goback add

lnmp取消nginx目录PHP执行权限

8584 点击·0 回帖
灯火互联
楼主

首先要编辑nginx的虚拟主机配置,在fastcgi的location语句的前面按下面的内容添加:

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

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

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

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

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

将attachments、upload这二个目录的PHP执行权限去掉。

附上一个完整的虚拟主机的例子供参考:

  1. server
  2. {
  3. listen 80;
  4. server_name www.hxhack.com;
  5. index index.html index.htm index.php;
  6. root /home/wwwroot/bbs.vpser.net;include discuz.conf;
  7. location ~ /(attachments|upload)/.*.(php|php5)?$ {
  8. deny all;
  9. }
  10. location ~ .*.(php|php5)?$
  11. {
  12. fastcgi_pass unix:/tmp/php-cgi.sock;
  13. fastcgi_index index.php;
  14. include fcgi.conf;
  15. }
  16. access_log off;
  17. }
添加完执行:/usr/local/nginx/sbin/nginx

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

 注:注意顺序,一定要放在 “location ~ .*.(php|php5)?$”

一行上面,不然不会生效。


喜欢0 评分0