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

Php 从上游读取响应头时,在stderr主脚本中发送的FastCGI未知,php,nginx,centos,runtime-error,Php,Nginx,Centos,Runtime Error,我在nginx.conf中有 upstream php-fpm7.0 { server unix:/run/php-fpm/php7.sock; } location ~ \.php$ { include php-fpm; } 我在conf.d/default.conf upstream php-fpm7.0 { server unix:/run/php-fpm/php7.sock; } location ~ \.php$ { include php-fpm

我在
nginx.conf中有

upstream php-fpm7.0
{
    server unix:/run/php-fpm/php7.sock;
}
location ~ \.php$ {
    include php-fpm;
}
我在
conf.d/default.conf

upstream php-fpm7.0
{
    server unix:/run/php-fpm/php7.sock;
}
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在stderr中发送:“主脚本未知” 来自上游的响应头

如果不使用套接字,则会出现相同错误:

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;
我得到了
$\u服务器['SCRIPT']
/index.php
$\u服务器['FOLDER']
/home/www/m-a-x/www
$\u服务器['FOLDER\u 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;
}
  • 打开URL,将下载一个文件,该文件将包含变量 由nginx返回。例如/srv/www/index.php

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

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

  • 设置沿路径读取和执行www用户组文件的权限

    chmod g+x/srv

    chmod g+x/srv/www

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


  • 您是否在
    server
    块中设置了
    root
    指令?是的,我还在
    location~\.php$
    中添加了它,因此
    nginx
    可以看到文件,但
    php\u fpm
    不能。这两个服务是否在同一个用户下运行?主进程在根进程下运行,子进程在www.下运行,文件权限为777。是否与SELinux策略有关?我不是专家,但这可能是您需要检查的内容。您还可以将www用户添加到您的用户组:gpasswd-a www m-a-x