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

为了安全起见,咱们通常会对上传目录禁止运行php脚本
修改nginx.conf配置文件
禁止单目录:php

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

禁止多目录:nginx

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

须要注意两点:
一、以上的配置文件代码须要放到 location ~ .php{...}上面,若是放到下面是无效的
二、attachments须要写相对路径,不能写绝对路径
三、不要忘记重启nginx呀,service nginx restart安全

相关文章
相关标签/搜索