Lnmp ThinkPHP5 开启pathinfo支持

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/the_victory/article/details/79620257

我在wnmp环境下的代码正常运行,但是放在lnmp环境下发现ThinkPHP5的pathinfo失效,导致Route:rule也无法使用。即使按官网网上说的添加一些代码也只是首页有用,点击其他页面仍然可能导致404或者500错误。最终找到了以下解决方案。最后会贴出我的配置

1. 修改 /usr/local/php/etc/php.ini 文件

搜索cgi.fix_pathinfo=0,将其值改为1

这里写图片描述

2. 修改/usr/local/nginx/conf/nginx.conf (或者vhost下的)文件

添加

        include /usr/local/nginx/conf/enable-php-pathinfo.conf;
        location / {
            index  index.html index.htm index.php l.php;
            autoindex  off;

            if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=/$1  last;
            }
        }

3. nginx重新加载配置文件

nginx -s relaod

以下是我的配置文件。

 server {
        listen       80;
        server_name  www.vm2phplive.io;

        root    "/home/wwwroot/phplive/public";
        include /usr/local/nginx/conf/enable-php-pathinfo.conf;
        location / {
            index  index.html index.htm index.php l.php;
            autoindex  off;

            if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=/$1  last;
            }
        }


        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

猜你喜欢

转载自blog.csdn.net/the_victory/article/details/79620257