nginx禁止指定目录运行php

nginx禁止指定目录运行php,只需要在server配置段中增加个location规则就可以了。
1、禁止某一个目录执行php
location ~* ^/download/.*\.(php|php5)$
{
deny all;
}

2、禁止多个目录执行php
location ~* ^/(download|down)/.*\.(php|php5)$
{
deny all;
}

注意:要写在php配置前,下面是一个示例
location ~* ^/(download|down)/.*\.(php|php5)$
{
deny all;
}
location ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
分享到:

网友留言(0 条)

发表评论