I have a (Python, DRF-based) API, running as a Uvicorn service on port 8002 on a Debian server.
It runs with no apparent issue, since when I do curl http://127.0.0.1:8002/videos/
, I get the expected API response (I also have tested it when deployed on Heroku, with no issue).
I need to serve it publicly with Nginx, so I configured a new Nginx vhost as a reverse proxy as followed:
upstream my_api {
server 127.0.0.1:8002;
}
server {
server_name example.com;
location / {
# Pass to Uvicorn/Gunicorn web server service
proxy_pass http://my_api;
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-Proto $scheme;
}
}
error_log /home/www/mydomain.log info;
On the browser, I get a 400 Bad Request error, whether it is on http://example.com/videos/
or even on http://example.com/
or http://example.com/whatever
.
When I tail the /home/www/example.log
Nginx vhost log file, I don't get any pertinent information, or logs from other vhosts, like the following:
2021/07/09 12:05:49 [info] 24698#24698: *233765 client 55.36.148.206 closed keepalive connection
2021/07/09 12:06:12 [info] 24698#24698: *233772 client 217.244.66.202 closed keepalive connection
2021/07/09 12:06:13 [info] 24698#24698: *233775 client closed connection while waiting for request, client: 63.210.40.102, server: 0.0.0.0:80
(Note: the unique endpoint works for /videos/
route but not for /videos
route - this will be fixed later but anyway that shouldn't interfere with the question.)
Any idea how to debug/understand where this 400 error comes from?