thinkphp配置到二级目录,不配置到根目录,访问除首页的其他路径都是404报错

1.在nginx的配置里面,进行重定向

vi /etc/nginx/conf.d/default.conf

2.进入编辑

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

这样访问ip/thinkphp/public/index/index/index,会报404,但是会转去请求

/thinkphp/public/index.php/index/index/index再返回,就能显示正确的数据了
/thinkphp/public/可以根据你自己写的目录进行修改配置,想写到里面就写到哪里,并不受约束,在nginx的配置里面替换掉就可以了
就在这个thinkphp框架里面,写对数据库的操作,和请求的url

3.重启服务器

service nginx restart

原文地址:https://www.cnblogs.com/chenyi4/p/12332092.html