DB / Nginx / N/A (Log Message)
CRITICAL
Nginx no live upstreams while connecting to upstream
This error occurs when Nginx, acting as a reverse proxy or load balancer, cannot forward a request because all servers defined in an `upstream` block are considered unavailable. It typically results in a 502 Bad Gateway response to the client.
Common Causes
- All backend servers (upstreams) are down, unreachable, or not listening on the configured port.
- Health checks (if configured) are failing, marking healthy servers as 'down'.
- Network issues (firewall rules, routing problems) are blocking communication between Nginx and the upstream servers.
- The upstream servers are crashing or rejecting connections due to resource exhaustion (e.g., out of memory, max connections).
How to Fix
1 Check Upstream Server Status
Manually verify the status and connectivity of each backend server defined in the upstream block.
BASH
$ # Check if the service is running on the backend server
ssh backend-server 'systemctl status your-app-service'
# Test network connectivity from the Nginx host to the backend
curl -v http://backend-server:app-port/
nc -zv backend-server app-port 2 Review Nginx Configuration & Logs
Examine the upstream configuration and the Nginx error log for specific connection failure messages.
BASH
$ # Check your upstream configuration
sudo nginx -T | grep -A 20 'upstream'
# Check the Nginx error log for details (common path)
sudo tail -f /var/log/nginx/error.log 3 Adjust Upstream Health Check Parameters
If using passive or active health checks, tune the `max_fails`, `fail_timeout`, and `slow_start` parameters to prevent servers from being marked 'down' incorrectly.
BASH
$ upstream backend {
server backend1.example.com max_fails=3 fail_timeout=30s;
server backend2.example.com max_fails=3 fail_timeout=30s;
# Consider adding a 'backup' server for failover
server backup.example.com backup;
} 4 Implement a Backup Server or Custom Error Page
Add a `backup` server directive to handle traffic when primary servers are down, or define a custom error page for a better user experience.
BASH
$ upstream app_backend {
server primary1.example.com;
server primary2.example.com;
server backup-server.example.com backup;
}
server {
...
error_page 502 /maintenance.html;
location = /maintenance.html {
root /usr/share/nginx/html;
}
}