首页 > 后端开发 > php教程 > Nginx系列(七.nginx支持pathinfo)

Nginx系列(七.nginx支持pathinfo)

WBOY
发布: 2016-08-08 09:24:42
原创
1077 人浏览过

一、通过rewrite方式代替php中的PATH_INFO (仅支持Thinkphp)

<code>location / {
    <span>if</span> (!<span>-e</span><span>$request_filename</span>){
        rewrite ^/(.*)$ /index.php?s=/<span>$1</span> last;
    }
}</code>
登录后复制

二、nginx配置文件中设置PATH_INFO值

<code>location ~ \.php {
    root /web/www/thinkphp;
    fastcgi_index index.php;
    fastcgi_pass <span>127.0</span>.<span>0.1</span>:<span>9000</span>;
    include      fastcgi_params;

    <span>set</span><span>$path_info</span><span>""</span>;
    <span>set</span><span>$real_script_name</span><span>$fastcgi_script_name</span>;
    <span>if</span> (<span>$fastcgi_script_name</span> ~ <span>"^(.+?\.php)(/.+)$"</span>) {
        <span>set</span><span>$real_script_name</span><span>$1</span>;
        <span>set</span><span>$path_info</span><span>$2</span>;
    }

    fastcgi_param SCRIPT_FILENAME <span>$document_root</span><span>$real_script_name</span>;
    fastcgi_param SCRIPT_NAME <span>$real_script_name</span>;
    fastcgi_param PATH_INFO <span>$path_info</span>;
}</code>
登录后复制

建议关闭 cgi.fix_pathinfo 选项

三、nginx自带pathinfo支持 (新版本)

<code><span>location</span><span>~ [^/]\.php(/|$)</span> {
        <span>root</span> /web/www/thinkphp;
        <span>fastcgi_index</span> index.php;
        <span>fastcgi_pass</span><span>127.0.0.1:9000</span>;
        <span>include</span>      fastcgi_params;

        <span>fastcgi_split_path_info</span><span> ^(.+?\.php)(/.*)$</span>;
        <span>fastcgi_param</span> SCRIPT_FILENAME <span>$document_root</span><span>$fastcgi_script_name</span>;
        <span>fastcgi_param</span> SCRIPT_NAME <span>$fastcgi_script_name</span>;
        <span>fastcgi_param</span> PATH_INFO <span>$fastcgi_path_info</span>;
        <span>fastcgi_param</span> PATH_TRANSLATED <span>$document_root</span><span>$fastcgi_path_info</span>;
}</code>
登录后复制

需要开启 cgi.fix_pathinfo 选项

四. 隐藏index.php文件

<code>location / {
    <span>if</span> (!<span>-e</span><span>$request_filename</span>){
        rewrite ^/(.*)$ /index.php/<span>$1</span> last;
    }
}</code>
登录后复制

五.nginx 官方指导

http://wiki.nginx.org/PHPFcgiExample

以上就介绍了Nginx系列(七.nginx支持pathinfo),包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板