nginxintermediatenetworkingVerified
Nginx Connection Refused: Causes and Fixes
Last reviewed: 9/14/2026
3 solutions
Exact Error Message
connect() failed (111: Connection refused) while connecting to upstreamQuick Fix
Check if upstream service is running and listening on the correct port.
What This Error Means
Connection refused occurs when Nginx tries to connect to an upstream server but the server is not running, not listening on the expected port, or actively refusing connections.
Common Symptoms
- •502 Bad Gateway errors
- •Connection refused in Nginx logs
- •Upstream unreachable
- •Proxy requests fail
Common Causes
- •Upstream service not running
- •Wrong port in upstream configuration
- •Firewall blocking connection
- •Service binding to wrong interface
- •Upstream overloaded or rejecting connections
Diagnostic Steps
- 1Check Nginx error logs
- 2Verify upstream service is running
- 3Check which port upstream is listening on
- 4Test connectivity from Nginx server
- 5Check firewall rules
Solutions
Solution 1: Start upstream service
- 1Check if upstream service is running
- 2Start the upstream service
- 3Enable service to start on boot
- 4Verify service is listening
Commands to Run
Service name varies by application
sudo systemctl start SERVICE_NAMERequires sudo access
sudo systemctl status SERVICE_NAMEnetstat -tlnp | grep PORTSolution 2: Fix upstream configuration
- 1Check Nginx upstream configuration
- 2Verify port is correct
- 3Check host or IP address
- 4Reload Nginx configuration
Commands to Run
[
sudo nginx -t'
sudo systemctl reload nginxSolution 3: Fix firewall rules
- 1Check firewall status
- 2Allow required ports
- 3Verify firewall rules
- 4Test connection
Commands to Run
Opening ports affects security
sudo ufw allow PORT/tcpOnly allow from trusted networks
sudo firewall-cmd --add-port=PORT/tcp --permanentPrevention Tips
- ✓Use health checks for upstream services
- ✓Monitor upstream service health
- ✓Use load balancing for high availability
- ✓Configure proper timeouts
- ✓Monitor Nginx error logs
Version Notes: Applies to Nginx 1.18+
Official Documentation
Related Errors
Was this helpful?