Home >Backend Development >PHP Tutorial >Problems using ThinkPHP's pathinfo mode under Nginx server
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>
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>
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>
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>
, so we can modify php.ini to
<code><span>cgi.fix_pathinfo</span>=<span>1</span></code>
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.