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