linux中nginx下禁止某目录执行php程序

对上传目录禁止运行php脚本
修改nginx.conf配置文件
禁止单目录:

location ~* ^/attachments/.*.(php|php5)$ {deny all;}

禁止多目录:

location ~* ^/(attachments|uploads)/.*.(php|php5)$ {deny all;}

需要注意以下3点:
1、以上的配置文件代码需要放到 location ~ .php{…}上面,如果放到下面是无效的
2、attachments需要写相对路径,不能写绝对路径
3、不要忘记重启nginx呀,service nginx restart 或 service nginx reload

发表评论

电子邮件地址不会被公开。 必填项已用*标注