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安全

相關文章
相關標籤/搜索