Docker NGinx 405 POST Not Allowed

08/18/20191 Min Read — In Docker, React.js, DevOps

Today it took me over one hour to debug an error with Docker and Nginx.

Every time I tried to submit a form with a POST method, NGinx gave me a 405 error: "405 Not Allowed".

I originally thought that Nginx overrode React Router settings and tried to troubleshoot my production NGinx config.

StackOverflow had some ideas: POST request not allowed - 405 Not Allowed - nginx, even with headers included.

Perhaps it was a problem with serving static content via POST from Nginx?

I knew that my request tried to hit a route to my Flask backend - nothing to do with static content. But it was worth a try.

So I experimented with proxying my routes.

I also tried looking at my Docker logs, but they only showed that I get the 405 error. Not helpful.

In the end, I just forgot to add a simple route to my default config.

server {
listen 80;
location /auth {
proxy_pass http://users:5000;
proxy_redirect default;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}