0

I was trying to configure chroot with php-fpm and mysql. I managed to work it out, however when I try to reach files other than index.php (like css, png etc.) it keeps giving 404.

However when I disable chroot, it works %100 correct.

My directory structure is like this;

/var/www #my chroot directory
/var/www/tmp #related pid and sock files
/var/www/log #related log directory
/var/www/public_html #wordpress directory

And my nginx configuration is like this;

server {
        listen   80; ## listen for ipv4; this line is default and implied

        root /public_html;
        index index.php;

        server_name _;

        location / {
                index index.php;
        }

        if (!-e $request_filename) {
                rewrite ^.*$ /index.php last;
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /public_html;
        }

        location ~ \.php$ {
                fastcgi_pass unix:/var/www/tmp/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param APPLICATION_ENV production;
                include fastcgi_params;
        }

        location ~ /\.ht {
                deny all;
        }
}

What do you think I am doing wrong ?

Thank you

Harun Baris Bulut
  • 455
  • 1
  • 8
  • 21

1 Answers1

1

I assume you are using PHP-FPM's chroot directive to apply the chroot environment. That is, nginx is not running in the chroot.

If that is the case, the problem is your root -configuration variable in the nginx config.

You should use:

root /var/www/public_html;

And then, in the FastCGI configuration part, you should add these lines after include fastcgi_params:

fastcgi_param SCRIPT_FILENAME /public_html$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT /public_html;

This way, nginx uses the real non-chroot directory structure, while PHP-FPM uses the chroot environment, and gets its environment information from nginx adjusted according to chroot.

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63