Nginx phpFPM:PATH_INFO总是空的

前端之家收集整理的这篇文章主要介绍了Nginx phpFPM:PATH_INFO总是空的前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我在Debian上配置了Nginx stable(1.4.4)PHP(使用FastCGI,PHP-fpm).这工作正常:

     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:

fastcgi_param   PATH_INFO       $fastcgi_path_info;

在/etc/PHP5/fpm/PHP.ini中:

cgi.fix_pathinfo = 0

我认为这应该有效,但是当我打印出所有服务器变量时,PATH_INFO始终为空:

    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',.....
)

我无法确定问题所在.有任何想法吗?

最佳答案
我偶然发现了一个解决方案. $fastcgi_path_info var与$fastcgi_split_path_info一起使用,需要在location块中设置.这是在我们的环境中起作用的:

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;
}

在fastcgi_split_path_info下的Nginx documentation中还有一个示例.

(…我现在看到匹配上面的多个帖子.可能需要在include语句之后设置PATH_INFO行,以避免破坏该值.)

猜你在找的Nginx相关文章