lnmp去掉nginx上傳目錄的PHP執(zhí)行權(quán)限
LNMP有一個缺點就是目錄權(quán)限設(shè)置上不如Apache,有時候網(wǎng)站程序存在上傳漏洞或類似pathinfo的漏洞從而導(dǎo)致被上傳了php木馬,而給網(wǎng)站和服務(wù)器帶來比較大危險。建議將網(wǎng)站目錄的PHP權(quán)限去掉,當訪問上傳目錄下的php文件時就會返回403錯誤。下面VPS偵探詳細介紹如何把lnmp環(huán)境下去掉指定目錄的PHP執(zhí)行權(quán)限。
首先要編輯nginx的虛擬主機配置,在fastcgi的location語句的前面按下面的內(nèi)容添加:
1、單個目錄去掉PHP執(zhí)行權(quán)限
location ~ /attachments/.*\.(php|php5)?$ {
deny all;
}
deny all;
}
將attachments目錄的PHP執(zhí)行權(quán)限去掉。
2、多個目錄去掉PHP執(zhí)行權(quán)限
location ~ /(attachments|upload)/.*\.(php|php5)?$ {
deny all;
}
deny all;
}
將attachments、upload這二個目錄的PHP執(zhí)行權(quán)限去掉。
附上一個完整的虛擬主機的例子供參考:
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;
}
{
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測試配置文件,執(zhí)行:/usr/local/nginx/sbin/nginx -s reload 載入配置文件使其生效。
如有問題歡迎在本文下方留言或到VPS論壇交流反饋。
原創(chuàng)文章,謝絕轉(zhuǎn)載!
>>轉(zhuǎn)載請注明出處:VPS偵探 本文鏈接地址:http://m.0794baidu.com/security/lnmp-remove-nginx-php-execute.html










@???????????, 只要沒有需要直接訪問php的都可以這樣設(shè)置
一下。在wp-content下除了上傳附件用的uploads外,還有plugins、themes等目錄。所有這些目錄也都需要做這樣的設(shè)置么?
另外,是否關(guān)閉了pathinfo外,這個操作就可以免除了呢。謝謝
@wybie, 最后面附上的只是一個完整的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 fcgi.conf;
}
這部分添加到server的大括號里嗎?
@memorytalks, LNMP不會默認處理,需要你自己添加
LNMP 0.9
還需要這樣處理嗎?
安裝好 dicuzx設(shè)置 預(yù)覽縮略圖提示
系統(tǒng)設(shè)置錯誤,無法處理圖片
出一個干凈的lamp的吧
@弗蘭卡, 不是所有,一般只設(shè)置上傳目錄就行。
關(guān)閉了pathinfo也可以弄,也可以不弄,弄上更安全些。
你好軍哥,我想以WP為例問一下。在wp-content下除了上傳附件用的uploads外,還有plugins、themes等目錄。所有這些目錄也都需要做這樣的設(shè)置么?
另外,是否關(guān)閉了pathinfo外,這個操作就可以免除了呢。謝謝
這個真的不錯 根本上解決問題
@BNE,
哦,你這個沒問題了。但是為何非要有那個“?”
這樣還是會有問題。看一下我的文章吧:
http://www.wooyun.org/bugs/wooyun-2011-01376
馬上修改。
@小陳, lnmpa 不需要
這個不錯,用lnmpa需要設(shè)置么?