Home > Backend Development > PHP Tutorial > Problems using ThinkPHP's pathinfo mode under Nginx server

Problems using ThinkPHP's pathinfo mode under Nginx server

WBOY
Release: 2016-08-08 09:25:12
Original
1174 people have browsed it

After installing the LNMP one-click installation package, I found that the pathinfo mode of thinkphp cannot be used.
After some Baidu, I found that there are instructions for opening pathinfo in the nginx/conf/vhost/domain name file, so I started pathinfo.
But the project still couldn't run, so I ran the code locally and on the server at the same time:

<code><span><span><?php</span>
var_dump(<span>$_SERVER</span>);</span></code>
Copy after login

I found that there was a difference in PHP_SELF, so the problem may be here.
Next, search for PHP_SELF in the project and find this file:
ThinkPHP.php

<code><span>if</span>(<span>IS_CGI</span>) {
            <span>//</span><span>CGI</span>/<span>FASTCGI</span>模式下
            <span>$_temp</span>  = explode(<span>'.php'</span>,<span>$_SERVER</span>[<span>'PHP_SELF'</span>]);
            define(<span>'_PHP_FILE_'</span>,   rtrim(str_replace(<span>$_SERVER</span>[<span>'HTTP_HOST'</span>],<span>''</span>,<span>$_temp</span>[<span>0</span>].<span>'.php'</span>),<span>'/'</span>));
        }<span>else</span> {
            define(<span>'_PHP_FILE_'</span>,    rtrim(<span>$_SERVER</span>[<span>'SCRIPT_NAME'</span>],<span>'/'</span>));
        }</code>
Copy after login

That is, ThinkPHP relies on PHP_SELF in cgi mode. The problem is indeed here
Finally, I did some searching on Baidu, and it turned out that it was set in php.ini to block a vulnerability:

<code><span>cgi.fix_pathinfo</span>=<span>0</span></code>
Copy after login

It is precisely because of this line of setting that the value of PHP_SELF is deviated.

However, the pathinfo.conf in the LNMP integration package has solved this vulnerability using

<code>try_files <span>$fastcgi_script_name</span> =<span>404</span></code>
Copy after login

, so we can modify php.ini to

<code><span>cgi.fix_pathinfo</span>=<span>1</span></code>
Copy after login

Restart the server, OK, the problem is solved

The above introduces the problems of using ThinkPHP's pathinfo mode under Nginx server, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template