2013-03-17 22 views
1

在我的網站上,用戶可以上傳他們的文件並獲得該文件的簡短網址。 在此之前,我使用Apache Web服務器,但現在我想切換到Nginx。RemoveHandler for nginx

在Apache中,我用這個片段刪除PHP處理一些目錄文件上傳到:

<Directory /var/www/unkown-user-data/uploads> 
RemoveHandler .php .phtml .php3 .php5 
RemoveType .php .phtml .php3 .php5 
php_flag engine off 
AddHandler default-handler .php 
</Directory> 

但現在,應該怎麼是我做這個nginx的Web服務器?

回答

1

Nginx沒有removehandler指令。您將位置塊添加到服務器的不同類型的請求。

我假設uploads文件夾可能有.php .phtml .php3 .php5文件,當它從該文件夾請求時,您不想執行它們。這裏是我的建議:

location ^~ /uploads/ { 
    root /var/www/unkown-user-data; 
    expires max; 
} 

注:「^〜」是很重要的(這意味着有比正則表達式更高的優先級「〜」塊)。否則,正則表達式位置塊如

location ~ \.php$ { 
    ... 
} 

將首先匹配並且php腳本將被錯誤地執行。這裏是比賽順序nginx的維基:

1. Directives with the "=" prefix that match the query exactly (literal string). If found, searching stops. 
2. All remaining directives with conventional strings. If this match used the "^~" prefix, searching stops. 
3. Regular expressions, in the order they are defined in the configuration file. 
4. If #3 yielded a match, that result is used. Otherwise, the match from #2 is used. 
+0

謝謝:-)我用第一種方法和工作。 –