php的cgi.fix_pathinfo解析

在解析url时,常常需要将cgi.fix_pathinfo = 1;
fix_pathinfo是用来干嘛的呢?

为CGI提供真正的PATH_INFO / PATH_TRANSLATED支持。 PHP的以前的行为是将PATH_TRANSLATED设置为SCRIPT_FILENAME,并且不要弄清PATH_INFO是什么。 有关PATH_INFO的更多信息,请参阅CGI规范。 将其设置为1将导致PHP CGI修复其路径以符合规范。 设置为零会导致PHP的行为像以前一样。 默认情况下打开。 您应该修复脚本以使用SCRIPT_FILENAME而不是PATH_TRANSLATED。

刚布了一套lnmp的环境,发现访问网站的时候总是显示

"Access to the script '/vagrant/php/new/public' has been denied (see security.limit_extensions)" while reading response header from upstream, client: 192.168.33.1, server: www.new.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.new.com"

然后将php-fpm的limit_extensions设置为不限制,又显示

"PHP message: PHP Warning:  Unknown: failed to open stream: Success in Unknown on line 0
Unable to open primary script: /vagrant/php/new/public (Success)" while reading response header from upstream, client: 192.168.33.1, server: www.new.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.new.com:8080"

后来才想起来,php.ini中有个设置cgi.fix_pathinfo不打开,nginx是解析不了路径的

location ~ \.php(.*)$ {
                fastcgi_pass    phpbackend;
                fastcgi_index   index.php;
                #先加载默认,后解析赋值
                include fastcgi_params;
                #正则解析路由
                fastcgi_split_path_info ^(.+\.php)(/?.+)$;
                fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param   PATH_INFO $fastcgi_script_name;
        }

猜你喜欢

转载自blog.csdn.net/b1303110335/article/details/77935245