我一直在这个问题上花了几个小时,尽pipe与此有关的post数量很多,但我无法解决。 我有一个Fedora 20盒子,Nginx + PHP-FPM,直到今天都工作得相当不错(我猜我重新加载了php-fpm.service)。 Nginx提供的静态文件没有问题,但任何PHP文件都会触发错误403。
权限是可以的,nginx和php-fpm在用户“nginx”下运行:
root 13763 0.0 0.6 490428 24924 ? Ss 15:47 0:00 php-fpm: master process (/etc/php-fpm.conf) nginx 13764 0.0 0.1 490428 7296 ? S 15:47 0:00 php-fpm: pool www nginx 13765 0.0 0.1 490428 7296 ? S 15:47 0:00 php-fpm: pool www nginx 13766 0.0 0.1 490428 7296 ? S 15:47 0:00 php-fpm: pool www nginx 13767 0.0 0.1 490428 7296 ? S 15:47 0:00 php-fpm: pool www nginx 13768 0.0 0.1 490428 6848 ? S 15:47 0:00 php-fpm: pool www
服务的文件已经被设置为nginx用户,我甚至结束了chmoding这些文件的尝试,但仍然“访问被拒绝”任何PHP文件。
下面是我的Nginxconfiguration的服务器:
server { listen 80; server_name localhost; root /var/www/html; location ~ \.php$ { fastcgi_intercept_errors on; try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
PHP-FPM池:
[www] ... listen = 127.0.0.1:9000 user = nginx group = nginx ...
对于版本:
php-5.5.11 (当然也是php-fpm-5.5.11 )
nginx的-1.4.7
我正在添加Nginx错误日志:
FastCGI sent in stderr: "Access to the script '/var/www/html' has been denied (see security.limit_extensions)" while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "xxx.xxx.xxx.xxx"
并确切security.limit_extensions
是正确的,设置为: security.limit_extensions = .php
。
关于path权限,可以遍历/ var / www / html 。 我错过了什么?
以下是一些可能的解决方案
在你的php-fpm http://www.conf中设置security.limit_extensions
为.php
或者.php5
或者其他适合你的环境的东西。 对于某些用户,完全删除所有值或将其设置为FALSE
是使其工作的唯一方法。
在你的nginx配置文件中设置fastcgi_pass
到你的套接字地址(例如unix:/var/run/php-fpm/php-fpm.sock;
)而不是你的服务器地址和端口。
检查你的SCRIPT_FILENAME
fastcgi参数,并根据你的文件的位置进行设置。
在你的nginx配置文件中包含fastcgi_split_path_info ^(.+\.php)(/.+)$;
在所有其他fastcgi参数定义的位置块。
在你的php.ini中设置cgi.fix_pathinfo
为1
请注意,上面的解决方案(设置cgi.fix_pathinfo
为1
)是一个可怕的想法。 请参阅https://nealpoole.com/blog/2011/04/setting-up-php-fastcgi-and-nginx-dont-trust-the-tutorials-check-your-configuration/以获得良好的概述。
这个问题很可能是依赖于PATH_INFO的应用程序。 为php启用访问日志记录,以获取有关如何调用应用程序的更多信息,以帮助您调试此问题。
再一次,只是可以肯定的 – 接受的解决方案是一个可怕的想法,并可能会让你的网站被黑客入侵。
不要忘记更改php.ini后重新启动php5-fpm服务!
服务php5-fpm重新启动或服务php5-fpm重新加载
fpm预启动php5,所以重新启动nginx以应用更改是不够的。
稍后的参考资料:在你的网站的conf中尝试添加:fastcgi_param PATH_INFO $ fastcgi_path_info; 另外看看SELinux正在做什么。 要关闭它:setenforce 0但是,然后确定什么脚本是问题,并把它放回setenforce 1
如果您的vhost文档根目录中没有index.php
,也会发生这种情况。
仔细检查你的nginx配置中的www_root
参数。 然后仔细检查你正在尝试打的php文件是否在那里。
在我的情况下,我错误键入虚拟主机的根路径,所以指向一个空目录,产生一个403。