LNMP有一個(gè)缺點(diǎn)就是目錄權(quán)限設(shè)置上不如Apache,有時(shí)候網(wǎng)站程序存在上傳漏洞或類似pathinfo的漏洞從而導(dǎo)致被上傳了php木馬,而給網(wǎng)站和服務(wù)器帶來比較大危險(xiǎn)。建議將網(wǎng)站目錄的PHP權(quán)限去掉,當(dāng)訪問上傳目錄下的php文件時(shí)就會(huì)返回403錯(cuò)誤。下面VPS偵探詳細(xì)介紹如何把lnmp環(huán)境下去掉指定目錄的PHP執(zhí)行權(quán)限。
首先要編輯nginx的虛擬主機(jī)配置,在fastcgi的location語(yǔ)句的前面按下面的內(nèi)容添加:
1、單個(gè)目錄去掉PHP執(zhí)行權(quán)限
location ~ /attachments/.*\.(php|php5)?$ {
? ? ? ? deny all;
}
將attachments目錄的PHP執(zhí)行權(quán)限去掉。
2、多個(gè)目錄去掉PHP執(zhí)行權(quán)限
location ~ /(attachments|upload)/.*\.(php|php5)?$ {
? ? ? deny all;
}
將attachments、upload這二個(gè)目錄的PHP執(zhí)行權(quán)限去掉。
附上一個(gè)完整的虛擬主機(jī)的例子供參考:
server
{
listen 80;
server_name bbs.vpser.net;
index index.html index.htm index.php;
root /home/wwwroot/bbs.vpser.net;include discuz.conf;
location ~ /(attachments|upload)/.*\.(php|php5)?$ {
? ? ? ?deny all;
}
location ~ .*\.(php|php5)?$
{
? ? ? ?fastcgi_pass unix:/tmp/php-cgi.sock;
? ? ? ?fastcgi_index index.php;
? ? ? ?include fastcgi.conf;
? ? ? ?}access_log off;
}
添加完執(zhí)行:/usr/local/nginx/sbin/nginx -t測(cè)試配置文件,執(zhí)行:/usr/local/nginx/sbin/nginx -s reload 載入配置文件使其生效。