美文网首页
配置Nginx支持Pathinfo,并隐藏入口文件

配置Nginx支持Pathinfo,并隐藏入口文件

作者: WananOH | 来源:发表于2018-03-12 13:11 被阅读0次

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

要是我们的网站支持Pathinfo模式的路由,可采用以下配置:
修改之前:

location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    include snippets/fastcgi-php.conf;
}

修改之后:

location ~ \.php(.*)$ { # 正则匹配.php后的pathinfo部分
    fastcgi_pass   127.0.0.1:9000;
    include snippets/fastcgi-php.conf;
    fastcgi_param PATH_INFO $1; # 把pathinfo部分赋给PATH_INFO变
}

如果还需要隐藏我们的入口文件(一般为index.php),那么在添加以下配置即可:

location / {
                if ( -f $request_filename) {
                        break;
                }
                if ( !-e $request_filename) {
                        rewrite ^(.*)$ /index.php/$1 last;
                        break;
                }
        }

相关文章

网友评论

      本文标题:配置Nginx支持Pathinfo,并隐藏入口文件

      本文链接:https://www.haomeiwen.com/subject/tfsnfftx.html