Welcome! Log In Create A New Profile

Advanced

fastcgi server variables vs. apache

April 06, 2009 07:55PM
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?
Subject Author Posted

fastcgi server variables vs. apache

androo April 06, 2009 07:55PM

Re: fastcgi server variables vs. apache

Denis F. Latypoff April 06, 2009 10:49PM

Re: fastcgi server variables vs. apache

androo April 07, 2009 11:02PM

Re: fastcgi server variables vs. apache

My SchizoBuddy December 10, 2009 09:36AM

Re: fastcgi server variables vs. apache

Igor Sysoev December 10, 2009 09:44AM

Re: fastcgi server variables vs. apache

spirit December 16, 2009 08:40AM

Re: fastcgi server variables vs. apache

Igor Sysoev December 16, 2009 09:00AM

Re: fastcgi server variables vs. apache

locojohn July 07, 2011 09:22AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 244
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready