gpt4 book ai didi

Nginx + PHP FPM : PATH_INFO always empty

转载 作者:可可西里 更新时间:2023-11-01 12:54:17 25 4
gpt4 key购买 nike

我在 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 block 中设置。以下是在我们的环境中有效的方法:

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 documentation 中也有一个示例在 fastcgi_split_path_info 下。

(...我现在看到它匹配上面的不止一篇文章。可能需要在 include 语句之后设置 PATH_INFO 行,以避免破坏值。)

关于Nginx + PHP FPM : PATH_INFO always empty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20848899/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com