Home > php教程 > php手册 > lnmp取消nginx目录PHP执行权限

lnmp取消nginx目录PHP执行权限

WBOY
Release: 2016-06-13 09:35:36
Original
1005 people have browsed it

   首先要编辑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.45it.com;

  index index.html index.htm index.php;

  root /home/wwwroot/bbs.vpser.net;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;

  }

  添加完执行:/usr/local/nginx/sbin/nginx -t测试配置文件,执行:/usr/local/nginx/sbin/nginx -s reload 载入配置文件使其生效。

  注:注意顺序,一定要放在 “location ~ .*\.(php|php5)?$” 一行上面,不然不会生效。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template