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










@???????????, 只要沒有需要直接訪問php的都可以這樣設置
一下。在wp-content下除了上傳附件用的uploads外,還有plugins、themes等目錄。所有這些目錄也都需要做這樣的設置么?
另外,是否關閉了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設置 預覽縮略圖提示
系統設置錯誤,無法處理圖片
出一個干凈的lamp的吧
@弗蘭卡, 不是所有,一般只設置上傳目錄就行。
關閉了pathinfo也可以弄,也可以不弄,弄上更安全些。
你好軍哥,我想以WP為例問一下。在wp-content下除了上傳附件用的uploads外,還有plugins、themes等目錄。所有這些目錄也都需要做這樣的設置么?
另外,是否關閉了pathinfo外,這個操作就可以免除了呢。謝謝
這個真的不錯 根本上解決問題
@BNE,
哦,你這個沒問題了。但是為何非要有那個“?”
這樣還是會有問題。看一下我的文章吧:
http://www.wooyun.org/bugs/wooyun-2011-01376
馬上修改。
@小陳, lnmpa 不需要
這個不錯,用lnmpa需要設置么?