Nginx + phpFPM: PATH_INFO is always empty

I configured nginx stable (1.4.4) + PHP (using FastCGI, php-fpm) on Debian. This works great:

location ~* ^/~(.+?)(/.*\.php)$ { fastcgi_split_path_info ^(.+?\.php)(/.*)$; alias /home/$1/public_html$2; fastcgi_pass unix:/var/run/php5-fpm.sock; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_index index.php; autoindex on; } 

I use the PATH_INFO variable, so I added the following line to fastcgi_params:

 fastcgi_param PATH_INFO $fastcgi_path_info; 

And in / etc / php 5 / fpm / php.ini:

 cgi.fix_pathinfo = 0 

I think this should work, but when I print all server variables, PATH_INFO is always empty:

  array ( 'USER' => 'www-data', 'HOME' => '/var/www', 'FCGI_ROLE' => 'RESPONDER', 'QUERY_STRING' => '', 'REQUEST_METHOD' => 'GET', 'CONTENT_TYPE' => '', 'CONTENT_LENGTH' => '', 'SCRIPT_FILENAME' => '/usr/share/nginx/html/srv_var.php', 'SCRIPT_NAME' => '/srv_var.php', 'PATH_INFO' => '', 'REQUEST_URI' => '/srv_var.php', 'DOCUMENT_URI' => '/srv_var.php', 'DOCUMENT_ROOT' => '/usr/share/nginx/html', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SERVER_SOFTWARE' => 'nginx/1.4.4', ..... ) 

I can not understand where the problem is. Any ideas?

+6
source share
5 answers

I came across a solution to this issue. $fastcgi_path_info var works with $fastcgi_split_path_info and must be set in the location block. Here is what worked in our environment:

 location ~ [^/]\.php(/|$) { root /var/www/jurism-php; if (!-f $document_root$fastcgi_script_name) { return 404; } # Mitigate https://httpoxy.org/ vulnerabilities fastcgi_param HTTP_PROXY ""; fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi_params; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; } 

The Nginx documentation provides an example of fastcgi_split_path_info .

(... which I now see corresponds to more than one post above). Perhaps the PATH_INFO line should be set after the include statement to avoid dropping the value.)

+2
source

Try the following:

 set $path_info $fastcgi_path_info; fastcgi_param PATH_INFO $path_info; 

http://wiki.nginx.org/PHPFcgiExample

http://trac.nginx.org/nginx/ticket/321

+1
source

Late answer, but it may be helpful to someone.

I used the REQUEST_URI variable instead of PATH_INFO. It looks like it contains the same value as PATH_INFO.

0
source

that's what i got. and it works like a charm.

  • nginx 1.10.1
  • php 5.6.24

https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/

0
source

My working configuration is as follows:

 location ~ [^/]\.php(/|$) { fastcgi_split_path_info ^(.+\.php)($|/.*); try_files $fastcgi_script_name =404; set $path_info $fastcgi_path_info; fastcgi_param PATH_INFO $path_info; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_ignore_client_abort off; } 
0
source

All Articles