nginx + php 403 原因分析
环境:nginx + php
问题:
配置的网站,访问出现报错:Access Denied (403)
常见解决方法:
1、文件权限问题
可能是文件权限问题,没有读权限。
或者selinux没有关闭。
2、security.limit_extensions
查看nginx的错误日志error.log,发现有如下错误:
// :: [error] #: * FastCGI sent in stderr: "Access to the script '/home/www/game/10313156.html' has been denied (see security.limi
t_extensions)" while reading response header from......
从5.3.9开始,php官方加入了一个配置"security.limit_extensions",默认只允许执行扩展名为".php"的文件,造成了其他类型的文件不支持的问题。
官方说明 :
; Limits the extensions of the main script FPM will allow to parse. This can
; prevent configuration mistakes on the web server side. You should only limit
; FPM to .php extensions to prevent malicious users to use other extensions to
; exectute php code.
; Note: set an empty value to allow all extensions.
; Default Value: .php
;security.limit_extensions = .php .php3 .php4 .php5
修改php-fpm.conf:(加入需要的文件扩展名)
security.limit_extensions = .php .html .js .css .jpg .jpeg .gif .png .htm
3、cgi.fix_pathinfo
通过这种url访问,显示Acess denied 错误。

nginx错误日志:
// :: [error] #: * FastCGI sent in stderr: "Access to the script '/home/www/home.php/game/qr' has been denied (see security.limit_extensions)" while reading response header......
修改php.ini :(cgi.fix_pathinfo 默认为1 )
cgi.fix_pathinfo = 1
官方说明 :
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting
; this to will cause PHP CGI to fix its paths to conform to the spec. A setting
; of zero causes PHP to behave as before. Default is . You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://php.net/cgi.fix-pathinfo
其实cgi.fix_pathinfo = 1 会引发文件类型错误解析漏洞,建议是设置 cgi.fix_pathinfo = 0 。
关于漏洞危害的详情,可参考:
http://www.cnblogs.com/batsing/p/nginx_bug1_attack.html
http://www.phpvim.net/web/php/security-risks-caused-by-fix-pathinfo.html
( 关于漏洞的理解:
当cgi.fix_pathinfo=1时,访问路径:/foo.jpg/file.php ,如果file.php文件不存在,则php解析器会试图猜测你要执行哪个文件,沿着路径往回找。如果foo.jpg存在, 并且包含php代码,php解析器就会去执行foo.jpg 。
当cgi.fix_pathinfo=0时,PHP 解释器仅尝试给出的路径,如果文件没有找到就停止处理。
)
但将 cgi.fix_pathinfo = 0 ,可能会导致很多MVC框架(如ThinkPHP)无法正常运行。
4、
重启php-fpm
访问网页,按ctrl + F5频繁刷新的时候,会报 Access Denied错误。Access Denied是偶尔才会出现,不是一直403 。
nginx错误日志记录:
// :: [error] #: * FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: open_basedir restriction in effect. File(/home/www/touch/web/index.php) is not within the allowed path(s): (/home/wwwroot:/tmp/:/proc/) in Unknown on line 0
PHP message: PHP Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line
Unable to open primary script: /home/www/touch/web/index.php (Permission denied)" while reading response header from upstream, client: 117.136.1.22, server: test.hjq.com, request: "GET /index.php?c=Zs&a=getcontent HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "test.hjq.com"
、In your nginx config file set fastcgi_pass to your socket address (e.g. unix:/var/run/php-fpm/php-fpm.sock;) instead of your server address and port. 、Check your SCRIPT_FILENAME fastcgi param and set it according to the location of your files. 、In your nginx config file include fastcgi_split_path_info ^(.+\.php)(/.+)$; in the location block where all the other fastcgi params are defined.
原文链接:http://stackoverflow.com/questions/23390531/access-denied-403-for-php-files-with-nginx-php-fpm
http://www.laruence.com/2010/05/20/1495.html
nginx + php 403 原因分析的更多相关文章
- nginx 偶发 403原因
观察errorlog 日志 是否存在类似错误 [error] 12788#0: *322 connection is denied by policyframe[return code:8], 观察是 ...
- 网站假死 重启NGINX无效 必须重启PHP 原因分析
一.错误提示说明: Nginx 502 Bad Gateway:请求的PHP-CGI已经执行,但是由于某种原因(一般是读取资源的问题)没有执行完毕而导致PHP-CGI进程终止. Nginx 504 G ...
- Nginx 504 Gateway Time-out分析及解决方法
一.场景还原php程序在执行抓取远程图片库并保存至本地服务器的时候,出现了“504 Gateway Time-out”错误提示. 问题定位:由于图片巨多,所以下载时间很长(10分钟以上),引起网关超时 ...
- Centos75 解决Nginx出现403 forbidden(13: Permission denied)
Centos75 新安装的vm,nginx出现403 forbidden 一般为SELinux设置为开启状态(enabled)的原因 切为root ,执行: sed -i 's/SELINUX=enf ...
- SELECT TOP 1 比不加TOP 1 慢的原因分析以及SELECT TOP 1语句执行计划预估原理
本文出处:http://www.cnblogs.com/wy123/p/6082338.html 现实中遇到过到这么一种情况: 在某些特殊场景下:进行查询的时候,加了TOP 1比不加TOP 1要慢(而 ...
- [Linux] Nginx networking 403 Forbidden 静态文件不允许查看
nginx 的 403 Forbidden errors 表示你在请求一个资源文件但是nginx不允许你查看. 403 Forbidden 只是一个HTTP状态码,像404,200一样不是技术上的错误 ...
- mysql索引无效且sending data耗时巨大原因分析
一朋友最近新上线一个项目,本地测试环境跑得好好的,部署到线上却慢得像蜗牛一样.后来查询了一下发现一个sql执行了16秒,有些长的甚至80秒.本地运行都是毫秒级别的查询.下面记录一下困扰了两天的,其中一 ...
- 网站用域名能访问,用域名IP不能访问的原因分析
原因分析:一般虚拟主机是不能直接输入IP进行访问的 因为一个IP下有很多网站 ,只能用域名进行访问.如果想IP也能访问,必须网站有独立的IP地址,不是共享IP.如果是IIS的话,要把主机头对应的域名去 ...
- JavaScript中的ParseInt("08")和“09”返回0的原因分析及解决办法
今天在程序中出现一个bugger ,调试了好久,最后才发现,原来是这个问题. 做了一个实验: alert(parseInt("01")),当这个里面的值为01====>07时 ...
随机推荐
- Spring MVC-控制器(Controller)-可参数化视图控制器(Parameterizable View Controller )示例(转载实践)
以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_parameterizableviewcontroller.htm 说明:示例基于 ...
- iOS的四种传值方式
传值有四种方法 : 1. 属性传值 2. 单例传值 3. 代理传值 4. block传值 一.属性传值 (前-->后) 1. 后面的界面定义一个属性 存放前一个界面传过来的值 ...
- HTML5:防止页面在移动设备上缩放
在制作网页时,如果对移动设备有做兼容设计的话,通常是不希望页面在移动设备能够被缩放.这样可以防止原先设计好的样式被破坏.要做到这一点,只需要在网页的head部分加入如下语句即可: <!-- 屏蔽 ...
- [csdn markdown]使用摘记一源码高亮及图片上传和链接
本文主要内容是体验csdn markdown的代码块高亮显示和图片链接及上传. 图片上传 上边这是标题行.仅仅须要使用一个#就能够表示.几个表示是几级标题 图片上传 本地图片上传控件 本地图片上传方式 ...
- 【Android】ListView 优化
重用 ListView Item ListView创建时其会创建屏幕可容纳数量的 Item.ListView 滚动时,刚消失的 item 会被保存到回收池中.新出现的 item 从回收池中获取避免反复 ...
- 571B. Minimization(Codeforces Round #317)
B. Minimization time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- BZOJ 2440 中山市选2011 全然平方数 二分答案+容斥原理+莫比乌斯反演
题目大意:求第k个无平方因子数是多少(无视原题干.1也是全然平方数那岂不是一个数也送不出去了? 无平方因子数(square-free number),即质因数分解之后全部质因数的次数都为1的数 首先二 ...
- luogu2770 航空路线问题 网络流
题目大意: 给定一张航空图,图中顶点代表城市,边代表 2 城市间的直通航线.现要求找出一条满足下述限制条件的且途经城市最多的旅行路线.(1)从最西端城市出发,单向从西向东途经若干城市到达最东端城市,然 ...
- android在学习——activity关闭和dialog.dismiss冲突的解决(Activity has leaked window com.android.internal.policy.impl.PhoneWindow)
当我们在退出整个程序的时候偶尔会出现这种报错:Activity has leaked window com.android.internal.policy.impl.PhoneWindow 其意思大概 ...
- alsa 用户空间编程【转】
本文转载自:http://blog.csdn.net/sjin_1314/article/details/12872581 /**alsa play test *ALSA用户空间编译,ALSA驱动的声 ...