6

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?

Community
  • 1
  • 1
donsplume
  • 61
  • 1
  • 1
  • 3
  • 1
    Are you sure that it is not tornado's response? – Alexey Ten Mar 06 '14 at 19:02
  • 1
    Very good point - I was so thrown by other questions' talk about HttpDavModule that it hadn't occurred to me that nginx was handling the request just fine without me doing anything. A bit of fiddling has shown that some code in my tornado setup was preventing the 'put' and 'delete' methods being called. All resolved now. Thank you. – donsplume Mar 06 '14 at 19:42
  • This question appears to be off-topic because it is aimed at [webmasters](http://webmasters.stackexchange.com/) – Rowland Shaw Mar 07 '14 at 08:42
  • I flagged this as unclear, since the question is framed to concern nginx but the issue was with tornado, and no information on tornado was given. – mikaraento Oct 04 '14 at 12:58
  • 2
    i have the same issue. WE have a laravel app which uses PUT as part of the php API. We are deploying to laravel forge, which uses ngnix. But nginx doesnt seem to support PUT (or DELETE), so you cant put a laravel app on nginx. Its a disaster. – John Little Oct 23 '17 at 16:44
  • @JohnLittle How come nginx doesn't support PUT or DELETE? These are standard HTTP methods, which should work out of the box for every web server or proxy. You must be doing something wrong. – VisioN Mar 30 '20 at 17:06

1 Answers1

0

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

jweboy
  • 17
  • 5
  • 1
    DAV has nothing to do with the original problem of the OP, hence your suggestion will not solve his problem. – VisioN Mar 30 '20 at 17:07