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时 ...
随机推荐
- [JZOJ4687]奇袭
[JZOJ4687]奇袭 题目 由于各种原因,桐人现在被困在Under World(以下简称UW)中,而UW马上要迎来最终的压力测试——魔界入侵. 唯一一个神一般存在的Administrator被消灭 ...
- libcloud代码研究(三)——bugs
Bug 1:对不可迭代类进行迭代(libcloud.storage.driver.cloudfile line. 141-142) 使用libcloud连接自搭建swift服务,自己在服务器 ...
- Hibernate注解开发教程
目录 第一章 类级别注解 1-1 本章简介 一.Hibernate注解简介 二.JPA与Hibernate的关系 三.Hibernate注解的分类 1-2 准备工作 1-3 @Entity注解 1-4 ...
- 记一个简单的webpack.config.js
module.exports = { entry: './basic/app.js', output: { path: './assets/', filename: '[name].bundle.js ...
- N天学习一个Linux命令之mkdir
前言 暂无 用途 用于新建目录 常用参数 1.设置目录权限-m, --mode=MODE 2.递归创建目录(父目录不存在时,也创建)-p, --parents 3.其它-v, --verbose pr ...
- ZOJ Monthly, November 2012
A.ZOJ 3666 Alice and Bob 组合博弈,SG函数应用 #include<vector> #include<cstdio> #include<cstri ...
- 海思3518e mpp2/sample/venc makefile简析
http://blog.csdn.net/u011003120/article/details/51324567
- FileZilla Client 免费又好用的ftp工具
设置文件同步关联(这个功能很好用) 很好用,很方便! 防止掉线 编辑->设置
- Android热更新实现原理
最近Android社区的氛围很不错嘛,连续放出一系列的android动态加载插件和热更新库,这篇文章就来介绍一下Android中实现热更新的原理. ClassLoader 我们知道Java在运行时加载 ...
- 地图使用-----MapKit介绍
一.MapKit介绍 1.苹果自带地图功能(高德地图),可以提供地图展示,查询,定位,导航等功能.使用MapKit框架实现地图功能,MapKit框架中所有数据类型的前缀都是MK 2.MapKit有一个 ...