nginx和php-fpm“主脚本未知”

闻起来就像一个重复的,我知道,但我现在已经尝试了5次这个安装程序,但我仍然无法得到这个工作。 大多数的configuration与chroot和多服务器等复杂,但我现在已经减less到最简单的configuration可能。 我想了解如何使用nginx以最简单的forms设置fpm …请耐心等待。

当前设置:

  • CentOS 7 64位
  • nginx 1.8.0来自Nginx的回购
  • 从Remi php56的PHP 5.6

除了/etc/nginx/conf.d/default.conf

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

添加和修改/etc/php-fpm.d/www.conf

 listen = /var/run/php-fpm/php-fpm.sock listen.owner = nginx listen.group = nginx listen.mode = 0660 

新增文件/usr/share/nginx/html/info.php

 <?php phpinfo();?> 

开始这两个服务

 systemctl start nginx.service systemctl start php-fpm.service 

最后tail -f /var/log/nginx/error.log

当读取来自上游的响应标题时,客户端:xx.xxx.xxx.xxx,服务器:本地主机,主机名称为“ 主脚本未知 ”时发送到stderr中的FastCGI:请求:“GET /info.php HTTP / 1.1”,上游:“fastcgi:// unix:/var/run/php-fpm/php-fpm.sock:”,主机:“xxx.xx.xxx.xx”

所以看起来FPM找不到脚本,这点我已经理解了,但是根据configuration,Script文件名是文档根目录和脚本名称。 脚本名称是info.php,根据默认configuration,根path是:

  location / { root /usr/share/nginx/html; index index.html index.htm; } 

因此,如果我手动连接,我得到

 /usr/share/nginx/html/info.php 

和这个文件存在

 #ls -lah /usr/share/nginx/html/ total 20K drwxr-xr-x 2 root root 4.0K Nov 9 12:35 . drwxr-xr-x 3 root root 4.0K Apr 21 2015 .. -rw-r--r-- 1 root root 537 Apr 21 2015 50x.html -rw-r--r-- 1 root root 612 Apr 21 2015 index.html -rw-r--r-- 1 root nginx 20 Nov 9 10:45 info.php 

有谁能给我一个解释,为什么这是行不通的?

$document_root需要从相同位置或父容器中的root指令中获取它的值。 您似乎在同级容器中定义了root 。 将root移动到server容器。