php网站显示File not found,nginx报错:FastCGI "Primary script unknown"

mac上使用homebrew重新安装了php72版本和nginx,但是配置好nginx.conf和hosts后打开页面发现显示File not found,进入到nginx的error.log中发现报错如下:

246#0: *108 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "someline.io"

看了很多网上其他的答案,但都没能解决问题,所以请大神不吝赐教!万分感谢~
其中nginx和php-fpm都是默认地址:
which nginx查看到nginx地址为:/usr/local/bin/nginx
nginx.conf所在地址为:/usr/local/etc/nginx
which php-fpm查看到php-fpm地址为:/usr/local/sbin/php-fpm
下面是我的nginx配置:

server {
        listen       8080;
        server_name  someline.io;
        root /www/Code/php/someline/public;

        location ~ ^/assets/([a-zA-Z0-9\-_.]+)/ {
            location ~* \.(ttf|ttc|otf|eot|woff|woff2)$ {
                add_header Access-Control-Allow-Origin "*";
            }

            location ~ ^/assets/([a-zA-Z0-9\-_.]+)/(css|js)/.*\.min\.(css|js)$ {
                gzip_static on;
            }
        }

        location / {
             index index.php;
             try_files $uri $uri/ /index.php?$args;
        }

        location ~ ^/index.php$ {
            root /usr/local/etc/nginx/;
            include fastcgi_params;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            proxy_ignore_client_abort on;
        }

        error_page   502 /502-desktop.html;

    }

下面是我hosts配置:

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
127.0.0.1       someline.io

/var/www的权限已经设置成chmod -R 777了,对应的nginx.conf所在的nginx文件夹也设置成了chmod -R 777了,但是依然有这个问题。
请大神不吝赐教!谢谢了!

阅读 5.9k
1 个回答

好混乱。。。

先把

    location ~ ^/index.php$ {
        root /usr/local/etc/nginx/;
        

中的 root这样去掉。 配置中root指的是网站根目录,你写这个是啥

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题