nginx supports pathinfo mode

WBOY
Release: 2016-07-28 08:26:45
Original
710 people have browsed it

Nginx服务器默认不支持pathinfo, 在需要pathinfo支持的程序中(如thinkphp),则无法支持”/index.php/Home/Index/index”这种网址.

网上流传的解决办法很多,这里提供一种比较简洁的写法(只需要改动2行代码)

<code><span># 典型配置</span><span>location</span><span>~ \.php$</span> {
    <span>root</span>           html;
    <span>fastcgi_pass</span><span>127.0.0.1:9000</span>;
    <span>fastcgi_index</span>  index.php;
    <span>fastcgi_param</span>  SCRIPT_FILENAME  <span>$DOCUMENT_ROOT</span><span>$fastcgi_script_name</span>;
    <span>include</span>        fastcgi_params;
}

<span># 修改第1,6行,支持pathinfo</span><span>location</span><span>~ \.php(.*)$</span> { <span># 正则匹配.php后的pathinfo部分</span><span>root</span> html;
    <span>fastcgi_pass</span><span>127.0.0.1:9000</span>;
    <span>fastcgi_index</span>  index.php;
    <span>fastcgi_param</span>  SCRIPT_FILENAME  <span>$DOCUMENT_ROOT</span><span>$fastcgi_script_name</span>;
    <span>fastcgi_param</span> PATH_INFO <span>$1</span>; <span># 把pathinfo部分赋给PATH_INFO变量</span><span>include</span>        fastcgi_params;
}</code>
Copy after login

以上就介绍了 nginx支持pathinfo模式,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!