51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

nginx禁止指定目录运行php

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; } |


赞(0)
未经允许不得转载:工具盒子 » nginx禁止指定目录运行php