nginx php FastCGI PATHINFO 配置

nginx 开启php的PATHINFO有两种方式比较好的一种方式是开启php.ini中的cgi.fix_pathinfo,只要通过FastCGI传递完整的路径给PHP就可以了

; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting
; of zero causes PHP to behave as before. Default is 1. You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://www.php.net/manual/en/ini.core.php#ini.cgi.fix-pathinfo
cgi.fix_pathinfo=1
#nginx配置
location ~ \.php($¦/) {
	include /etc/nginx/fastcgi_params;
	fastcgi_pass 127.0.0.1:9000;
	fastcgi_param SCRIPT_FILENAME	$document_root$fastcgi_script_name;
	fastcgi_param SERVER_NAME		$server_name;
	fastcgi_param PATH_INFO			$fastcgi_script_name;
}

还有一种方法是通过正则用nginx本身给分析出来,没有实际测试只做参考。

location ~ \.php
{
	fastcgi_index index.php;
	fastcgi_pass 127.0.0.1:9000;
	include      fastcgi_params;
	set $path_info "";
	set $real_script_name $fastcgi_script_name;
	if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
		set $real_script_name $1;
		set $path_info $2;
		}
	fastcgi_param SCRIPT_FILENAME /var/html/$real_script_name;
	fastcgi_param SCRIPT_NAME $real_script_name;
	fastcgi_param PATH_INFO $path_info;
}

 

发表评论

电子邮件地址不会被公开。

*