php - 从上游读取响应头时,FastCGI 在 stderr 主脚本中发送未知

标签 php nginx centos runtime-error

我在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;
}

FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

如果不使用套接字,也会出现同样的错误:

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;

所有作品。 神秘。

最佳答案

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

location / {
    return 200 $document_root$fastcgi_script_name;
}
  1. 打开URL,将下载一个文件,文件将包含变量 由 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

关于php - 从上游读取响应头时,FastCGI 在 stderr 主脚本中发送未知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36035266/

相关文章:

php - CentOS 服务器安全

php - 如何更改 phpMyAdmin 中的权限

php - 让回车键点击搜索按钮

ssl - Nginx错误: "No shared cipher".但是还有

mysql - uWsgi 的响应丢失

node.js - ERR_CONNECTION_RESET : Error When i try to upload large files using node. js/multer ,部署在 elastic beanstalk -nginx 服务器

gcc - 运行 rhel6 构建的可执行文件时在 rhel7 机器上导入错误

amazon-s3 - 如何在 amazon linux 2 或 centos 中将 s3fs 从 v1.74 更新到最新版本?

php - 我可以将数组添加到 codeigniter 中的 update_batch 的 where 子句吗

php - 登录php脚本不允许登录