3

I have a problem with nginx to download an excel file using the Http POST method. In fact I am getting a Status Code: 405 Not Allowed.

here is my configuration

upstream backend{
    server localhost:9090;
    server localhost:9091;
    server localhost:9092;
    server localhost:9093;
}

server {
    listen       8887;
    server_name  localhost;

    location / {
        proxy_pass  http://backend;
        proxy_next_upstream error timeout http_404; 
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
    }
}

how can I solve this problem.

Thank you in advance.

2
  • Why do you think this is an nginx problem? The configuration just passes the POST to the backend. It's most likely the backend that is issuing the 405 response, Jul 31, 2018 at 12:41
  • In fact it's very bizzare, it sends me sometimes 404 sometimes 405.
    – kasko
    Jul 31, 2018 at 13:04

1 Answer 1

5

Nginx responds with an HTTP 405 for POST requests that try to access a static asset.

From the Nginx release docs from a few years back:

*) Feature: now Nginx returns the 405 status code for POST method requesting a static file only if the file exists.

A way to go around it would be to add this line, which changes the response code and sends you to the requested URI:

error_page 405 =200 $uri;

You can find other solutions here:

http://invalidlogic.com/2011/04/12/serving-static-content-via-post-from-nginx/

I hope this helps.

1
  • Thank you for your answer but I changed the architecture of my app to have only one port.
    – kasko
    Aug 14, 2018 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.