Nginx + phpFPM:PATH_INFO始终为空 [英] Nginx + phpFPM: PATH_INFO always empty
问题描述
我在Debian上配置了nginx stable(1.4.4)+ PHP(使用FastCGI,php-fpm).效果很好:
I configured nginx stable (1.4.4) + PHP (using FastCGI, php-fpm) on Debian. That works fine:
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;
}
我使用PATH_INFO变量,因此我在fastcgi_params中添加了以下行:
I use the PATH_INFO variable, therefore I added the following line to fastcgi_params:
fastcgi_param PATH_INFO $fastcgi_path_info;
在/etc/php5/fpm/php.ini中:
And in /etc/php5/fpm/php.ini:
cgi.fix_pathinfo = 0
我认为应该可以,但是当我打印出所有服务器变量时,PATH_INFO始终为空:
I think that should work, but when I print out 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 figure where the problem is. Any ideas?
推荐答案
我偶然发现了一个解决方案. $ fastcgi_path_info
var与 $ fastcgi_split_path_info
一起使用,需要在位置块中进行设置.这是在我们的环境中起作用的东西:
I stumbled across a solution to this. The $fastcgi_path_info
var works together with $fastcgi_split_path_info
, and needs to be set within the location block. Here's 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;
}
在 Nginx文档中,在 fastcgi_split_path_info下也有一个示例
.
(...我现在看到的匹配上面的多个帖子.可能需要在include语句之后设置PATH_INFO行,以避免破坏值.)
(... which I now see matches more than one post above. Possibly the PATH_INFO line needs to be set after the include statement, to avoid clobbering the value.)
这篇关于Nginx + phpFPM:PATH_INFO始终为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!