一聚教程网:一个值得你收藏的教程网站

热门教程

nginx中怎么禁止目录PHP执行权限

时间:2022-06-30 18:44:25 编辑:袖梨 来源:一聚教程网

LNMP环境下目录权限设置上不如Apache,有时网站程序存在上传漏洞或类似pathinfo的漏洞从而导致被上传了php木马,而给网站和服务器带来比较大危险。
建议将网站目录的PHP权限去掉,当访问上传目录下的php文件时就会返回403错误。
如何把lnmp环境下去掉指定目录的PHP执行权限。 首先,编辑nginx的虚拟主机配置,在fastcgi的location语句的前面添加如下内容:

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

 代码如下 复制代码


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

将attachments目录的PHP执行权限去掉。

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

 

 代码如下 复制代码
location ~ /(attachments|upload)/.*.(php|php5)?$ {
deny all;
}

将attachments、upload这二个目录的PHP执行权限去掉。
附,完整的虚拟主机配置:

 代码如下 复制代码


server{
listen 80;
server_name www.111com.net;
index index.html index.htm index.php;
root /home/wwwroot/w123;
include discuz.conf;
location ~ /(attachments|upload)/.*.(php|php5)?$ {
deny all;
}
location ~ .*.(php|php5)?$
{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
access_log off;
}

热门栏目