1. 文章
  2. 文章详情

nginx访问php文件404

nginx 访问 html 文件正常,当访问php文件时会报错,查看nginx errorlog

FastCGI sent in stderr: "Primary script
unknown" while reading response header from upstream, client: 127.0.0.1, server:
 localhost, request: "GET /laravel/public/index.php HTTP/1.1", upstream: "fastcg
i://127.0.0.1:9000", host: "localhost"

在Nginx的 conf 中找到定义脚本文件的地方:

fastcgi_param  SCRIPT_FILENAME /var/www/html$fastcgi_script_name;

修改成如下方式($document_root):

fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

$document_root 代表当前请求在root指令中指定的值:

location / {
            root   html;
            index index.php index.html index.htm;
        }

上面配置中的$document_root就是针对/usr/local/nginx/html目录下的php文件进行解析。

参考:https://zhuanlan.zhihu.com/p/55793101

发表评论

登录后才能评论

评论列表(0条)