I'm running Debian 6.0.3
(squeeze
), nginx-0.7.67
, fcgiwrap-1.0-1+squeeze1
. Here is the test script:
#!/usr/bin/perl
use 5.010;
use warnings;
use strict;
use Data::Dumper;
print "Content-Type: text/html\n\n";
say Dumper {map {$_ => $ENV{$_}} 'SCRIPT_NAME', 'DOCUMENT_ROOT', 'WHATEVER'};
say "$<, $>, $(, $)";
And here's the nginx
configuration:
server {
server_name domain.com;
root /home/yuri/6;
access_log /var/log/nginx/domain.com-access.log;
error_log /var/log/nginx/domain.com-error.log;
location /cgi-bin/ {
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param DOCUMENT_ROOT /home/yuri/7/;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param WHATEVER 1;
fastcgi_param WHATEVER 2;
}
location /1.php {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param PHP_ADMIN_VALUE cgi.fix_pathinfo=1;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param SCRIPT_FILENAME whatever;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Here's what I get in browser if going to url http://domain.com/cgi-bin/1.pl:
$VAR1 = { 'SCRIPT_NAME' => '/cgi-bin/1.pl', 'DOCUMENT_ROOT' => '/home/yuri/7/', 'WHATEVER' => '2' };
So it seems, that fcgiwrap
uses the first DOCUMENT_ROOT
for looking up for the script, but the script gets the last values of params. If you change the order of DOCUMENT_ROOT
directives, web server returns 403
. The question is... how come?
php
though works as expected: the second SCRIPT_FILENAME
overrides the first one.
The fastcgi library just passes whatever parameters it was given into the
environ
pointer.getenv()
as used byfcgiwrap
uses whatever environment variable came first (optimization?). It is likely that PHP FPM treats this environment just like the array data type, any latter key overwrites the first.You should not rely on the order and make sure that there is only one key. I have not looked at the FastCGI specification, whether the correct behavior is documented or not.
As for why you get the 403, I guess that there is no
/home/yuri/7/1.pl
file. (remember, the first parameter gets matched by fcgiwrap). Since it is not executable, fcgiwrap returns a 403.Testing
The below patch prints the environment as given by
FCGI_Accept()
:nginx configuration used for the test:
Commands to start the servers (assuming
nginx.conf
in the current directory):Now, run
curl http://localhost:5555/
and the stderr will print:Aside, this is a development version. The current stable (1.1.0) does not contain the
-p
parameter above. For the results it does not really matter, you could as well have dropped it and received an error that noSCRIPT_NAME
is given or something.