I'm currently facing an issue with Nginx not being able to connect to the Uvicorn server for a FastAPI application. Here are the details:
- Nginx Configuration:
- Nginx is configured to forward requests to
127.0.0.1:8000
. - Nginx logs show repeated
connect() failed (111: Connection refused)
errors, indicating that it cannot connect to the upstream server. - Configuration file for Nginx is set up with
proxy_pass
pointing tohttp://127.0.0.1:8000
.
- Nginx is configured to forward requests to
server {
server_name clover-academy.org www.clover-academy.org;
location / {
proxy_pass http://127.0.0.1:8000;
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;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/clover-academy.org/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/clover-academy.org/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
server {
if ($host = www.clover-academy.org) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = clover-academy.org) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name clover-academy.org www.clover-academy.org;
return 404; # managed by Certbot
}
-
Uvicorn Configuration:
- Uvicorn is set up to listen on
0.0.0.0:8000
using the command:uvicorn bot.app:app --host 0.0.0.0 --port 8000 --log-level debug
.
- Uvicorn is set up to listen on
-
Log Information:
- Nginx logs show errors like:
connect() failed (111: Connection refused) while connecting to upstream
. - Uvicorn logs are not showing any errors or connection issues.
- Nginx logs show errors like:
-
Actions Taken:
- Verified that Uvicorn is running on port 8000 and is listening on the correct address.
- Confirmed that Nginx is configured to listen on ports 80 and 443.
- Enabled verbose logging for both Nginx and Uvicorn for detailed error information. But the only error a received was the 101 connecition refused.
- Check if the certificates was still valid.
- Also checked iptables and everything was fine.
Nginx is receiving the request but the page keeps loading indefinitely, until The connection has timed out.
Thank you for your help!