nginx禁止指定目录运行php,只需要在server配置段中增加个location规则就可以了。
1、禁止某一个目录执行php
location ~* ^/download/.*\.(php|php5)$ { deny all; }
|---------|------------------------------------------------------------| | 1 2 3 4 | location ~* ^/download/.*\.(php|php5)$ { deny all; } |
2、禁止多个目录执行php
location ~* ^/(download|down)/.*\.(php|php5)$ { deny all; }
|---------|--------------------------------------------------------------------| | 1 2 3 4 | 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; }
|-------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 11 | 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; } |