Lnmp ThinkPHP5 开启pathinfo支持

我在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;
        }

    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值