加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

Nginx phpFPM:PATH_INFO总是空的

发布时间:2020-12-13 21:37:25 所属栏目:Nginx 来源:网络整理
导读:我在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_

我在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行,以避免破坏该值.)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读