without reverse proxying my flask server with nginx GET and POST are working fine.
but in reverse proxy its not working.
my nginx.conf file is
# nginx.conf
# HTTP server block for handling HTTP requests
`server {
listen 80;
location / {
proxy_pass http://flask:5000;
proxy_http_version 1.1;
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 Content-Type "application/json";
}
}`
Error I faced is
$ curl -X POST -H "Content-Type: application/json" -d ‘{"message": "Hello from cURL!"}’ http://x.x.x.x/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 184 100 153 100 31 2091 423 –:–:– –:–:– –:–:– 2555
<!doctype html>
<html lang=en>
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>`
2
Answers
i have made changes to code file and configuration file, now nginx is reverse proxying correctly. app.py
nginx.conf:
ignore second server bock in nginx.conf if you dont want ssl to be added
docker-compose file
Method not allowed error is thrown because you try to use a request method (GET, POST, etc.) that is not allowed. This can be because of the application code or server configuration but my best guess is your reverse proxy isn’t set up properly and you send the request to the default nginx page, which returns method not allowed since the default server does not have POST api endpoints.
I am not very well-versed in reverse proxy configuration but if you can provide more details (eg. nginx log outputs) someone can provide a complete answer.