Nginx/FPM/PHP 所有 php 文件都说“找不到文件”。

Mr.*_*oon 7 php nginx php-fpm

我刚刚在 centos 5.8 最终 64 位机器上安装了 nginx 1.1.13 和 php 5.4.0。Nginx 和 PHP/Fpm 正在运行,我可以通过 ssh 命令行运行 php 脚本,但在浏览器中我不断收到“找不到文件”。我所有的 PHP 文件都出现错误。

这就是我的 nginx.conf 处理 PHP 脚本的方式:

      location ~ \.php$
      {
              root                    /opt/nginx/html;
              fastcgi_pass            unix:/tmp/fpm.sock;
              fastcgi_index           index.php;
              fastcgi_param           SCRIPT_FILENAME /opt/nginx/html$fastcgi_script_name;
              include                 fastcgi_params;
      }
Run Code Online (Sandbox Code Playgroud)

这是从我的其他服务器直接复制/粘贴的,在此设置下它可以正常工作(但它们运行旧版本的 php/fpm)。

为什么我会收到这些错误?

小智 17

把“包括fastcgi_params;” 在所有“fastcgi_param *”行之前,“包括fastcgi_params;” 覆盖所有“fastcgi_param *”行(请参阅 nginx 调试日志):

location ~ \.php$ {
    root                    /opt/nginx/html;
    fastcgi_pass            unix:/tmp/fpm.sock;
    fastcgi_index           index.php;
    include                 fastcgi_params;
    fastcgi_param           SCRIPT_FILENAME /opt/nginx/html$fastcgi_script_name;
}
Run Code Online (Sandbox Code Playgroud)

  • 伙计,我已经浪费了 4 个小时,您的回答对我有所帮助。 (3认同)