15

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!

MFB
  • 19,017
  • 27
  • 72
  • 118

4 Answers4

27

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.

fnkr
  • 9,428
  • 6
  • 54
  • 61
  • 1
    What if I don't need to create files, just to use additional HTTP metthods? – Alexander Pravdin Dec 21 '15 at 03:52
  • 2
    If you don't want to have your request handled by dav_methods and want to use PUT or DELETE methods, you should make sure these requests are not matched by the index module, but by try_files ie: try_files $uri /index.php$is_args$args; in case of a typical setup with PHP – dadasign Nov 25 '17 at 20:08
  • 4
    PUT is an HTTP method, not a webdav one. – LtWorf Apr 16 '18 at 08:47
  • @LtWorf Doesn't matter, if you want nginx to handle the request you need to use the HttpDavModule -- or forward the request to another backend, e.g. via proxy_pass. Otherwise nginx will return 405 Not Allowed. – fnkr May 03 '18 at 07:15
  • @fnkr and how does one forward such requests to a backend? I'm only aware of backends accepting what `nginx` already accepts, i.e. `GET`, `POST`... – Gwyneth Llewelyn Aug 28 '21 at 17:18
1

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.

Ali Hashemi
  • 3,158
  • 3
  • 34
  • 48
0

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

location / {
     try_files $uri $uri/ /index.php?$query_string;
}
egekhter
  • 2,067
  • 2
  • 23
  • 32
0

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 ..

LittleEaster
  • 527
  • 7
  • 10