2013-06-04 78 views
6

我正在使用的應用程序需要PUT HTTP服務器上的文件。我使用Nginx作爲服務器,但得到405 Not Allowed錯誤。這裏是捲曲測試的例子:如何在Nginx服務器上允許PUT文件請求?

curl -X PUT \ 
-H 'Content-Type: application/x-mpegurl' \ 
-d /Volumes/Extra/playlist.m3u8 http://xyz.com 

而我回來的Nginx的:

<html> 
<head><title>405 Not Allowed</title></head> 
<body bgcolor="white"> 
<center><h1>405 Not Allowed</h1></center> 
<hr><center>nginx/1.1.19</center> 
</body> 
</html> 

什麼我需要做的,讓PUT

任何線索都會很棒!

回答

16

要添加PUT,DELETE,MKCOL,COPY和MOVE等HTTP和WebDAV方法,您需要編譯HttpDavModule./configure --with-http_dav_module)的nginx。首先檢查nginx -V,也許你已經有HttpDavModuleI installed nginx from the Debian repository and I already have the module)。

然後改變你的nginx,配置這樣的:

location/{ 
    root  /var/www; 
    dav_methods PUT; 
} 

你可以在nginx docs entry for the HttpDavModule更多信息。

+1

如果我不需要創建文件,只需使用其他HTTP方法會怎樣? –

+1

不起作用,'405不允許' – Green

+0

如果您不想讓您的請求由dav_methods處理並且想要使用PUT或DELETE方法,則應確保這些請求不與索引模塊匹配,而是通過try_files ie:try_files $ uri /index.php$is_args$args;在使用PHP進行典型設置的情況下 – dadasign

1

405 Not Allowed的另一個原因是您沒有權限在目標PUT上寫入文件。如果您有HttpDavModule,但仍然出現此錯誤,請確保已爲文件提供了nginx寫入權限。

相關問題