【发布时间】: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