在nginx和php上拒绝访问
使用nginxweb服务器和php。nginx正在工作,我看到“欢迎使用nginx!”但当我试图访问php页面时,会遇到“访问被拒绝”的情况。我还安装了php fastcgi 这是我的nginx默认配置:在nginx和php上拒绝访问,php,nginx,Php,Nginx,使用nginxweb服务器和php。nginx正在工作,我看到“欢迎使用nginx!”但当我试图访问php页面时,会遇到“访问被拒绝”的情况。我还安装了php fastcgi 这是我的nginx默认配置: # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
我在/etc/php-fpm.d/www.conf和/etc/php5/fpm/php.ini中激活了security.limit\u extensions=.php.php3.php4.php5.html和listen=/var/run/php5 fpm.sock
我重新启动了nginx和php5 fpm
感谢您的帮助。我知道nginx和php无法访问文件时可能出现的一些情况:
很可能是php fpm
进程由对相应的.php文件没有读取权限的用户运行。
这会导致明显错误访问被拒绝。
nginx
进程对包含站点文件的root
目录没有读取和遍历权限。
这将产生403禁止的错误
php fpm
进程无法遍历到根目录的绝对路径。
这将导致找不到文件
错误
由于作者提到,这个问题只在访问php文件时出现,所以我认为第一种情况适用于这里
我相信情况是,nginx
作为一个用户运行,php-fpm
作为另一个用户运行,只有php-fpm
用户忘记了授予读取权限。请检查您的fastcgi\u参数文件,并根据本帖相应地更改它
我用上面的方法解决了我的问题。在你有第二个位置的地方这样做
location / {
try_files $uri $uri/ =404;
root /path/to/your/www;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
这两个参数是魔术酱:
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
如果您试图使用NGINX将HTML解析为PHP,并且遇到拒绝访问
错误,则需要更改PHP配置设置
在Ubuntu 16上,需要更新的文件位于/etc/php/7.0/fpm/pool.d/www.conf
中
转到显示的行;security.limit_extensions=.php.php3.php4.php5.php7
将其替换为security.limit\u extensions=.php.html
。请注意,前面的分号已被删除
然后重新启动PHPsudo systemctl重新启动php7.0-fpm
。这个问题应该得到解决
有关更多信息,请参阅此更详细的指南:我更改了/etc/php-fpm.d/www.conf文件中的用户和组,web文件夹的所有者更改为同一用户,但不起作用。我给出了相同的结果。我发送了nginx错误日志(2014/02/20 17:19:39[error]2989#0:*6发送到stderr的FastCGI:“访问脚本'/usr/share/nginx/html'被拒绝(请参阅security.limit_extensions)”,同时从上游读取响应头,客户端:10.10.125.16,服务器:localhost,请求:“GET/test.php HTTP/1.1”,上游:"fastcgi://unix:/var/run/php5-fpm.sock:,主机:“10.254.10.19”)如果您禁用security.limit\u扩展,会发生这种情况吗?您是否重新启动了php fpm?我仍然存在问题,这与我得到的这行代码有关:fastcgi\u pass 127.0.0.1:9000;
?在我的例子中,我使用的是CentOS 7、php 7.2和Nginx 1.14。我将服务器放在一个虚拟框中,可以通过IP地址192.168.x.x在浏览器中访问