Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx post method does not work

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.

like image 542
kasko Avatar asked Sep 11 '26 08:09

kasko


1 Answers

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.

like image 125
migueldavid Avatar answered Sep 15 '26 12:09

migueldavid