首页 > 服务器    日期:2019-08-22 / 来自互联网 / 浏览

为了网站的安全运行建议将网站上传目录的PHP权限去掉,当访问上传目录下的php文件时就会返回403错误。下面详细介绍如何把Nginx环境下去掉指定目录的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.domain.com; index index.html index.htm index.php; root /home/wwwroot/www.domain.com; include www.domain.com.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; }

觉得上面的内容有用吗?快来点个赞吧!

点赞() 我要打赏

温馨提示 : 本站内容来自会员投稿以及互联网,所有源码及教程均为作者总结编辑,请大家在使用过程中提前做好备份,以免发生无法预知的错误,源码类教程请勿直接用于生产环境!

 可能感兴趣的文章