MFB
MFB

Reputation: 19817

How do I allow a PUT file request on Nginx server?

I am using an application which needs to PUT a file on a HTTP server. I am using Nginx as the server but getting a 405 Not Allowed error back. Here is an example of a test with cURL:

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

And what I get back from 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>

What do I need to do to allow the PUT?

Any clues would be awesome!

Upvotes: 16

Views: 61571

Answers (4)

LittleEaster
LittleEaster

Reputation: 601

nginx is mainly a proxy and a lot of other things, it share something with web server, not all.

You may want to check: https://www.nginx.com/resources/wiki/modules/upload/, better is to have a rest interface and let nginx do the proxy, balancing, buffering, TSL ..

Upvotes: 0

egekhter
egekhter

Reputation: 2225

Adding this block solved the problem for me in a Laravel application.

location / {
     try_files $uri $uri/ /index.php?$query_string;
}

Upvotes: -1

fnkr
fnkr

Reputation: 10075

To add HTTP and WebDAV methods like PUT, DELETE, MKCOL, COPY and MOVE you need to compile nginx with HttpDavModule (./configure --with-http_dav_module). Check nginx -V first, maybe you already have the HttpDavModule (I installed nginx from the Debian repository and I already have the module).

Then change your nginx-config like that:

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

You can get more info on the nginx docs entry for the HttpDavModule.

Upvotes: 29

Ali Hashemi
Ali Hashemi

Reputation: 3408

Another reason for 405 Not Allowed is that you don't have permission to write files on the destination you're PUTing. If you have HttpDavModule and still getting this error, make sure you've given nginx write permissions where you're PUTing the files.

Upvotes: 2

Related Questions