No Healthy Upstream Error: Meaning & Fixes
In this article
"No healthy upstream" is an error message from a reverse proxy or load balancer (like Nginx, HAProxy, or Traefik) indicating that the server it tries to forward requests to is either down, unreachable, or not responding. The fix is to make the backend service available again, correct its address or port, or adjust the proxy's health-check settings. This article explains what the error means, why it happens, and how to resolve it step by step.
What Does "No Healthy Upstream" Mean?
In a typical web setup, a reverse proxy sits in front of one or more backend servers (the "upstreams"). When you visit a website, your browser talks to the proxy, and the proxy forwards the request to a backend. The proxy periodically checks each backend's health—usually by sending a simple HTTP request or a TCP connection test. If a backend fails those checks, the proxy marks it as "unhealthy" and stops sending traffic to it. When all backends in a group are unhealthy, the proxy returns the "no healthy upstream" error to the client.
This error is not a problem with your browser or your internet connection. It means the server-side infrastructure is broken. Common scenarios include a crashed application server, a misconfigured firewall, a database connection failure that makes the app return 500 errors, or a typo in the proxy configuration pointing to the wrong port.
Common Causes of the Error
Several distinct issues can trigger this message. Identifying which one applies to your situation is the first step toward a fix.
- Backend service is down: The application process (e.g., Node.js, Python, Java) crashed or was stopped. Check with
systemctl status(on systemd systems) orps aux | grep your-app. - Wrong port or IP: The proxy config points to
localhost:3000but the app listens onlocalhost:8080. Verify the actual listening port withnetstat -tlnporss -tlnp. - Health check path returns non-2xx: The proxy checks
/healthbut your app returns a 404 or 500 for that path. The proxy considers the backend unhealthy even if the app works fine for other routes. - Firewall or security group blocking: A network firewall (like iptables, AWS Security Groups, or a cloud provider's firewall) is blocking the proxy's IP from reaching the backend port.
- Resource exhaustion: The backend is out of memory, disk space, or file descriptors, causing it to accept connections but never respond. Health checks time out.
- DNS resolution failure: If the proxy config uses a hostname (e.g.,
backend.internal) that no longer resolves, the proxy cannot connect at all.
How to Diagnose the Issue
Before changing anything, gather information. The error message alone doesn't tell you which backend failed or why. Here's a systematic approach:
- Check the proxy's error log. Nginx logs to
/var/log/nginx/error.logby default. HAProxy logs to syslog. Look for lines likeno live upstreamsorconnect() failed (111: Connection refused)—the latter tells you the exact IP and port it tried. - Test the backend directly from the proxy server. Run
curl -v http://127.0.0.1:3000/health(replace with your actual address). If you get a response, the backend is up; the problem is in the proxy config. If you get a timeout or connection refused, the backend is down or firewalled. - Check the backend's own logs. The application may be crashing on startup due to a missing environment variable or database connection. Look at
journalctl -u your-serviceor the app's log file. - Verify the health check path. Look at your proxy config. What path does it use for health checks? Test that exact path with curl. If it returns a non-2xx status, the backend is technically "unhealthy" by the proxy's definition.
- Check resource usage. Run
free -hfor memory,df -hfor disk, andulimit -nfor file descriptor limits. A full disk is a common cause of apps failing health checks.
How to Fix It (Step-by-Step)
Once you know the cause, the fix is usually straightforward. Here are the most common solutions:
- Start the backend service. If it's down, restart it:
sudo systemctl restart your-app. If it crashes immediately, check its logs for a startup error. - Correct the proxy configuration. Edit the upstream block in Nginx (or equivalent in HAProxy/Traefik) to point to the correct IP and port. Example Nginx config:
upstream backend { server 127.0.0.1:3000; }
Then reload:sudo nginx -s reload. - Fix the health check path. If your app doesn't have a
/healthendpoint, either add one that returns 200, or change the proxy's health check to a path that does return 200 (like/). - Adjust firewall rules. Allow traffic from the proxy to the backend port. For example, with iptables:
sudo iptables -A INPUT -p tcp --dport 3000 -j ACCEPT. On cloud platforms, update the security group's inbound rules. - Increase timeouts. If the backend is slow (e.g., a heavy API call takes 30 seconds), the health check might time out. Increase the
proxy_read_timeoutin Nginx or thetimeout checkin HAProxy. - Fix DNS. If you use a hostname, ensure it resolves correctly. Test with
dig backend.internal. If it fails, update your DNS records or use the IP directly in the proxy config.
Preventing the Error in the Future
Once you've fixed the immediate issue, consider these practices to avoid recurrence:
- Set up monitoring and alerting. Use tools like Prometheus, Grafana, or a simple cron job that pings the health endpoint and alerts you when it fails.
- Use multiple upstream servers. If you have more than one backend instance, the proxy will route around a single failure. Even two instances on the same machine (different ports) provide redundancy.
- Configure automatic restarts. Use a process manager like systemd with
Restart=alwaysin the service file, or a container orchestrator like Docker Compose withrestart: unless-stopped. - Write a proper health check endpoint. It should verify not just that the process is alive, but that it can connect to its database and other dependencies. This catches issues before they affect real users.
- Test your proxy config after changes. Always run
nginx -t(or equivalent) before reloading to catch syntax errors that could cause downtime.
Nginx vs. HAProxy vs. Traefik: Differences
While the error message is similar, each proxy has its own nuances:
- Nginx uses the
upstreamblock withserverdirectives. Health checks are passive by default (they mark a server down after a number of failed requests). Active health checks require the commercial version or a third-party module. The error appears as504 Gateway Timeoutor502 Bad Gatewayin the browser, andno live upstreamsin the log. - HAProxy has explicit
option httpchkfor active health checks. It showsno server is available to handle this request. HAProxy gives more detailed stats via its web interface (usually on port 8404). - Traefik uses dynamic configuration and labels. It checks health via the
healthcheckparameter in Docker labels or file config. The error in Traefik is often502 Bad Gatewaywith a log message likeunable to find a healthy server.
Regardless of the proxy, the underlying logic is the same: a backend must pass health checks to receive traffic.
Frequently Asked Questions
Why do I see "no healthy upstream" even though my app is running?
Your app might be running but not responding correctly to the health check. For example, if the health check path expects a 200 status but your app returns a 500 due to a database connection issue, the proxy marks it unhealthy. Also, check that the app is listening on the correct network interface—if it's bound to 127.0.0.1 but the proxy is on a different machine, it won't be reachable.
Does this error affect all users or just some?
It affects all users who are routed to the unhealthy upstream group. If you have multiple upstream groups (e.g., one for /api and one for /static), only requests to the unhealthy group will fail. Users hitting healthy groups will be unaffected.
Can a misconfigured firewall cause this error?
Yes. If the proxy server cannot reach the backend due to a firewall rule (on the proxy, the backend, or in between), the health check will fail with a timeout or connection refused. Always test connectivity from the proxy to the backend using curl or telnet before blaming the app.
Is "no healthy upstream" the same as a 502 Bad Gateway?
Usually, yes. The proxy returns a 502 Bad Gateway to the client when it has no healthy upstream to forward the request to. However, a 502 can also occur if the backend returns an invalid response or if the proxy itself is misconfigured. The "no healthy upstream" message is the specific reason the proxy logged.
How do I fix this if I'm using Docker?
Check that all containers are running (docker ps). Ensure the proxy container can reach the backend container by name (use a shared Docker network). Verify the backend's health check command in the Dockerfile or compose file—if it fails, Docker marks the container unhealthy, and the proxy will see it as down.
What should I do if the error persists after restarting everything?
Check the proxy's configuration for a hardcoded IP that has changed. Also look for DNS issues if you use hostnames. Finally, examine the backend's resource usage—a memory leak or full disk can cause it to crash repeatedly. If all else fails, enable debug logging in the proxy to see the exact connection attempt and failure reason.