wrong DOCUMENT_ROOT on chroot

Bug #465900 reported by NoSFeRaTU
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
PHP-FPM
New
Undecided
Unassigned

Bug Description

I think in chroot mode $_SERVER['DOCUMENT_ROOT'] variable must represent a path inside a chroot, not outside. Because in this case this path is invalid, but some scripts actively use that variable. I tried to change it in nginx with:
fastcgi_param DOCUMENT_ROOT wantedpath;
But with no success, variable keeps unchanged.

Revision history for this message
Jérôme Loyet (jloyet) wrote :

what is you nginx conf ?

Don't you have included the fastcgi.conf file after you set the DOCUMENT_ROOT with the fastcgi_param directive ? In this case, it will be overwriten by the fastcgi.conf included file.

Here is an exemple which works:

        location ~ \.php$ {
                include fastcgi_params;
                fastcgi_pass unix:/home/www/logs/fastcgi.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /docs$fastcgi_script_name;
                fastcgi_param DOCUMENT_ROOT /docs;
        }

and php-fpm is chrooted into /home/www

++ Jerome

Revision history for this message
brainf (vysmbox) wrote :

I also have this problem, yet decided with a variable $server_subdir:

server {
    listen 8011;
    server_name localhost;
    client_max_body_size 7m;
    set $server_subdir "server_services";
    root /home/user/www/www-nginx/$server_subdir;

    location / {
        index index.php index.html index.htm;
        try_files $uri $uri/ @controller;
    }

    location ~ \.php$ {
        try_files $uri @controller;

        fastcgi_pass 127.0.0.1:9005;
        fastcgi_index index.php;

        include /etc/nginx/fastcgi_params;
        fastcgi_ignore_client_abort on;

        fastcgi_param SCRIPT_FILENAME /$server_subdir$fastcgi_script_name;
    }

    location @controller {
        fastcgi_pass 127.0.0.1:9005;
        fastcgi_index index.php;

        include /etc/nginx/fastcgi_params;
        fastcgi_ignore_client_abort on;

        fastcgi_param SCRIPT_FILENAME /$server_subdir/index.php;
        fastcgi_param QUERY_STRING q=$uri&$args;
    }
}

Revision history for this message
Michael Shadle (mshadle) wrote :

First off you could compress that entire config into this. It could be an issue with your nginx config - you have callbacks multiple times for the same thing it seems like. For all I know it could wind up altering the actual proper location because it's being called twice...

This should work flawlessly (from the nginx angle) and may fix your issue (no promises, but it's a start)

server {
    listen 8011;
    server_name localhost;
    client_max_body_size 7m;
    root /home/user/www/www-nginx/server_services;
    index index.php index.html index.htm;
    try_files $uri $uri/ /index.php?q=$uri&$args;
    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_index index.php;
        fastcgi_ignore_client_abort on;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9005;
    }
}

Revision history for this message
brainf (vysmbox) wrote :

Thank you for the optimized configuration, but if you use $document_root PHP scripts are not executed (404 = No input file specified.). If you replace $document_root$fastcgi_script_name; to /server_services$fastcgi_script_name everything works fine. But now there is no reason to use the variable $ server_subdir:)

config (chrooted into <value name="chroot">/var/www-nginx</value>):

server {
    listen 8011;
    server_name localhost;
    client_max_body_size 7m;

    root /var/www-nginx/server_services;
    index index.html index.htm index.php;
    try_files $uri $uri/ /index.php?q=$uri&$args;
    autoindex on;

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_index index.php;
        fastcgi_ignore_client_abort on;
        #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_FILENAME /server_services$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9005;
    }
}

Revision history for this message
Michael Shadle (mshadle) wrote :

So do you think this is still a bug?

What I notice here is you have:

root /var/www-nginx/server_services;

however the scripts are really in a top level directory (on the filesystem)

/server_services

That would be one reason why it doesn't match. :)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.