首页 > 解决方案 > 所有 laravel 项目或某些项目的 Nginx 错误 404

问题描述

目前我正在为 web 服务器开发 laravel 项目和 brew install nginx,但是当我打开它时,我的 laravel 项目出现错误 404。

所以我尾随看看发生了什么

tail -f /usr/local/var/log/nginx/error.log

    Output : the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/etc/nginx/nginx.conf:1<br>

    *1 directory index of "/Users/user/Projects/new-project/" is forbidden, client: 127.0.0.1

然后我尝试将用户更改为用户 www-data; 正如其他解决方案中所建议的,但仍然无法打开。


    user    www-data;
    worker_processes  1;
    events {
        worker_connections  1024;
    }

    server {
        listen       8080;
        server_name  test.localhost;

        location / {
            root   /Users/user/Projects/test;
            index  index.php;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            root           /Users/user/Projects/test;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

我正在使用 macbook unix 终端 catalina

标签: nginx

解决方案


根据 nginx 的 Laravel 文档,

您的根文件夹必须指向项目的公共目录/path/to/Project/public

遵循本指南https://laravel.com/docs/6.x/deployment

另请查看此线程。403 Forbidden on nginx/1.4.6 (Ubuntu) - Laravel


推荐阅读