[nginx 配置]Nginx 限制指定目录执行php文件

更新时间:2017-11-14    来源:nginx    手机版     字体:

【www.bbyears.com--nginx】

方法

 代码如下

location~^/images/.*.(php|php5)$
{
denyall;
}

location~^/static/.*.(php|php5)$
{
denyall;
}

location~*^/data/(attachment|avatar)/.*.(php|php5)$
{
denyall;
}

注:这些目录的限制必须写在

 代码如下

location~.*.(php|php5)$
{
fastcgi_pass  127.0.0.1:9000;
fastcgi_index  index.php;
include fcgi.conf;
}

的前面,否则限制不生效!

path_info漏洞修正:

在通用fcgi.conf顶部加入

 代码如下

if ($request_filename ~* (.*).php) {
set $php_url $1;
}
if (!-e $php_url.php) {
return 404;
}


1、去除单个目录去掉PHP执行权限

 代码如下

location ~ /attachments/.*.(php|php5)?$ {
deny all;
}

2、多个目录去掉PHP执行权限

 代码如下

location ~ /(attachments|upload)/.*.(php|php5)?$ {
deny all;
}

如果你想在apache中限制执行php可参考

以设置APACHE的虚拟主机配置项,是使其不能执行PHP程序
如果用.htaccess来实现某个目录需要认证,则在apache的httpd.conf里设置:

 代码如下  
Options Indexes FollowSymLinks 
AllowOverride AuthConfig 
order deny,allow 
 

然后在需要认证的目录(如:dir)下建立.htaccess文件

本文来源:http://www.bbyears.com/caozuoxitong/37034.html