thinkPHP框架在nginx环境中提示404错误的几种情况与解决方法

发布时间 2023-09-28 09:33:08作者: 王顺波

一、未设置伪静态

解决方法:在项目public目录下新建文件,命名为nginx.htaccess,文件内容如下:

location / {
    index  index.html index.htm index.php;
    autoindex  off;
    if (!-e $request_filename) {
        rewrite  ^(.*)$  /index.php?s=/$1  last;
        break;
    } 
}

二、项目的debug模式已打开,但是某方法出错报错时,不出现具体的错误提示,还是只是出现404报错。

解决方法:nginx配置文件中的error_page 404 /404.html;注释,即可显示错误信息,根据错误信息解决,如下图

三、未使用控制器后缀却在新建控制器文件时名称后缀加了Controller。如Index.php写做IndexController.php。

解决方法:项目配置文件config/route.php中开启使用控制器后缀。如下图