Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx returns 405 (Method Not Allowed) for PUT or DELETE

Tags:

nginx

I am using nginx to serve static pages but to pass requests to an API on to a Tornado application, which I would like to handle GET, POST, PUT and DELETE requests.

GET and POST requests are fine, but PUT and DELETE requests are rejected with "405: Method Not Allowed"

This question asks much the same: How do I allow a PUT file request on Nginx server? but the answer doesn't solve my issue, which makes me think it's related to my use of proxy_pass in my setup.

Here's my nginx server config:

upstream TornadoAPI {
        server 127.0.0.1:8000;
}

server {
        listen 80;
        listen [::]:80 default_server ipv6only=on;

        root /usr/share/nginx/html;
        index index.html index.htm;

        # Make site accessible from http://localhost/
        server_name localhost;

        location /<<static url>>/ {
                root /var/www;
                index index.html;
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.html;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

        location /<<API url>>/ {
                dav_methods PUT DELETE;
                dav_access all:r;
                proxy_pass http://TornadoAPI/api/;
        }
}

I have attempted to use the HttpDavModule directives (though I don't think my application qualifies as HttpDav - I have no intention on letting users write files) without luck. I have confirmed the module's presence by inspecting nginx -V.

Here's an example output from the nginx access.log:

<<IP address>> - - [06/Mar/2014:16:29:57 +0000] "PUT /<<API url>>/<<resource>> HTTP/1.1" 405 87 "<<ngix server root url>>" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36"

Can someone suggest what else I can do to accept the PUT and DELETE methods?

like image 418
donsplume Avatar asked Mar 06 '14 17:03

donsplume


People also ask

What is 405 Not Allowed nginx?

The HyperText Transfer Protocol (HTTP) 405 Method Not Allowed response status code indicates that the server knows the request method, but the target resource doesn't support this method.

How do I fix 405 Method not allowed in Postman?

If you are certain you need a POST request, chances are, you're just using the wrong endpoint on the server. Again, this can only be solved if you have proper documentation to show what methods are supported for each endpoint.


1 Answers

You can add this sentence in your configuration file

dav_methods PUT DELETE MKCOL COPY MOVE;

Specific detailed reference nginx document http://nginx.org/en/docs/http/ngx_http_dav_module.html

like image 118
jweboy Avatar answered Oct 26 '22 01:10

jweboy