fastcgi server variables vs. apache

Denis F. Latypoff denis at gostats.ru
Tue Apr 7 06:49:28 MSD 2009


Hello androo,

Tuesday, April 7, 2009, 6:55:15 AM, you wrote:

> First of all, thank you for Nginx. It is a breath of fresh air
> after Apache. And though it has taken some getting used to, I've
> discovered that I like the config file syntax better in Nginx.

> Second, there are three server variables whose values are not the
> same under Nginx as under Apache: PATH_INFO, PATH_TRANSLATED, and
> SCRIPT_NAME. Obviously this makes trouble when trying to use
> applications designed for Apache. In addition, because the
> "fastcgi_param" directive cannot be used inside an "if" statement,
> it is impossible to write a general rule to set their values the
> same as under Apache. This is an issue when using URIs of the form "/directory/script.php/blah".

> PATH_INFO: Under Apache, it doesn't exist unless using URIs of the
> above form; then it equals "/blah". Under Nginx, it never exists.

> PATH_TRANSLATED: Under Apache, it doesn't exist unless using URIs
> of the same form; then it equals "/document/root/blah" (note: not
> "/document/root/directory/blah"). Under Nginx, it exists when using
> such URIs, but it equals "/document/root".

> SCRIPT_NAME: Under Apache, when using URIs of the same form, it
> equals "/directory/script.php". Under Nginx, it equals "/directory/index.php/blah".

> So far I haven't been able to find a general rule to fix this. What
> I would like to do is put something like this at the end of fastcgi_params:

> if ($document_uri ~ "^/(.+)\.php/(.*)") {
>     fastcgi_param PATH_INFO /$2;
>     fastcgi_param PATH_TRANSLATED $document_root/$2;
>     fastcgi_param SCRIPT_NAME /$1.php;
> }

> If someone called a URI that matched the pattern, these values
> would kick in; otherwise, the defaults would be used. But this can't
> be done because "fastcgi_param" isn't allowed inside "if". Next I
> tried the following at the end of fastcgi_params:

> if ($document_uri ~ "^/(.+)\.php/(.*)") {
>     set $apache_path_info /$2;
>     set $apache_path_translated $document_root/$2;
>     set $apache_script_name /$1.php;
> }
> fastcgi_param  PATH_INFO          $apache_path_info;
> fastcgi_param  PATH_TRANSLATED    $apache_path_translated;
> fastcgi_param  SCRIPT_NAME        $apache_script_name;

> But this sets PATH_INFO, PATH_TRANSLATED, and (most
> problematically) SCRIPT_NAME to empty values even for URIs that don't match the pattern.

> Has anyone found a way around this? I.e. a way of writing a general
> rule (i.e., one that is not hard-coded for specific URIs) that will
> normalize the three variables to their Apache values?

Since version 0.7.31 use may use fastcgi_split_path_info:

    location ~ ^(.+\.php)(.*)$ {

        fastcgi_split_path_info         ^(.+\.php)(.*)$;
        fastcgi_param  SCRIPT_FILENAME  /path/to/php$fastcgi_script_name;
        fastcgi_param  PATH_INFO        $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
        ...
    }


> Posted at Nginx Forum:
> http://forum.nginx.org/read.php?2,866,866#msg-866



-- 
Best regards,
 Denis                            mailto:denis at gostats.ru






More information about the nginx mailing list