為了安全起見, 我們一般會對上傳目錄禁止執行 php 指令碼
修改 nginx.conf 配置檔案
禁止單目錄:
location ~* ^/attachments/.*.(php|php5)$ {
deny all;
}

禁止多目錄:
location ~* ^/(attachments|upload)/.*.(php|php5)$ {
deny all;
}

需要注意兩點:
1 、以上的配置檔案程式碼需要放到 location ~ .php{…} 上面,如果放到下面是無效的
2 、 attachments 需要寫相對路徑,不能寫絕對路徑
3 、不要忘記重啓 nginx 呀,service nginx restart