【问题标题】:FastCGI sent in stderr primary script unknown while reading response header from upstream从上游读取响应标头时,在 stderr 主脚本中发送的 FastCGI 未知
【发布时间】:2016-07-02 07:24:24
【问题描述】:

我有nginx.conf

upstream php-fpm7.0
{
    server unix:/run/php-fpm/php7.sock;
}

我有conf.d/default.conf

location ~ \.php$ {
    include php-fpm;
}

我有php-fpm

fastcgi_pass    php-fpm7.0;
include fastcgi_params;
fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;
set             $path_info              $fastcgi_path_info;
fastcgi_param   PATH_INFO               $path_info;
# Additional variables
fastcgi_index   index.php;

但我收到错误 404。 当我评论时

#location ~ \.php$ {
#    include php-fpm;
#}

文件可用

即使出错

location ~ \.php$ {
    fastcgi_pass unix:/run/php-fpm/php7.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

在 stderr 中发送的 FastCGI:读取时“主脚本未知” 来自上游的响应头

如果不使用socket,同样的错误:

fastcgi_pass 127.0.0.1:9000;

Centos 7

更新 1。

使用后:

fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param SCRIPT $fastcgi_script_name;
fastcgi_param FOLDER $document_root;
fastcgi_param FOLDER_SCRIPT $document_root$fastcgi_script_name;

我得到了$_SERVER['SCRIPT'] /index.php$_SERVER['FOLDER']/home/www/m-a-x/www$_SERVER['FOLDER_SCRIPT']/home/www/m-a-x/www/index.php

当我回来时

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

一切正常。 谜。

【问题讨论】:

  • 您是否在server 块内设置了root 指令?
  • 是的,我也添加到location ~ \.php$
  • 所以nginx 可以看到文件但php_fpm 不能。两个服务是否在同一用户下运行?
  • 在 root 下运行的主进程,子进程 - 在 www 下。文件权限为 777。
  • 会不会和 SELinux 政策有关?我不是专家,但您可能需要检查一下。

标签: php nginx centos runtime-error


【解决方案1】:

您总是可以通过将它们添加到return语句来检查nginx变量,例如:

location / {
    return 200 $document_root$fastcgi_script_name;
}
  1. 打开网址,将下载一个文件,文件将包含变量 由 nginx 返回。例如 /srv/www/index.php

  2. 检查 nginx/php-fpm 用户组是否有权访问该文件:

    sudo -u www stat /srv/www/index.php

  3. 设置权限以读取和执行整个路径中 www 用户组的文件。

    chmod g+x /srv

    chmod g+x /srv/www

    chmod g+x /srv/www/index.php

【讨论】:

  • 您也可以将 www 用户添加到您的用户组:gpasswd -a www m-a-x
猜你喜欢
  • 2021-04-08
  • 1970-01-01
  • 2020-08-20
  • 2016-05-16
  • 2019-08-05
  • 2015-07-07
  • 2012-08-18
  • 2014-12-30
  • 2017-04-09
相关资源
最近更新 更多