Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

No Healthy Upstream Error: Meaning & Fixes

· 7 min read · Home Tech

In this article
  1. What Does "No Healthy Upstream" Mean?
  2. Common Causes of the Error
  3. How to Diagnose the Issue
  4. How to Fix It (Step-by-Step)
  5. Preventing the Error in the Future
  6. Nginx vs. HAProxy vs. Traefik: Differences
  7. Frequently Asked Questions

"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) or ps aux | grep your-app.
  • Wrong port or IP: The proxy config points to localhost:3000 but the app listens on localhost:8080. Verify the actual listening port with netstat -tlnp or ss -tlnp.
  • Health check path returns non-2xx: The proxy checks /health but 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:

  1. Check the proxy's error log. Nginx logs to /var/log/nginx/error.log by default. HAProxy logs to syslog. Look for lines like no live upstreams or connect() failed (111: Connection refused)—the latter tells you the exact IP and port it tried.
  2. 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.
  3. 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-service or the app's log file.
  4. 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.
  5. Check resource usage. Run free -h for memory, df -h for disk, and ulimit -n for 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:

  1. 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.
  2. 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.
  3. Fix the health check path. If your app doesn't have a /health endpoint, either add one that returns 200, or change the proxy's health check to a path that does return 200 (like /).
  4. 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.
  5. 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_timeout in Nginx or the timeout check in HAProxy.
  6. 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=always in the service file, or a container orchestrator like Docker Compose with restart: 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 upstream block with server directives. 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 as 504 Gateway Timeout or 502 Bad Gateway in the browser, and no live upstreams in the log.
  • HAProxy has explicit option httpchk for active health checks. It shows no 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 healthcheck parameter in Docker labels or file config. The error in Traefik is often 502 Bad Gateway with a log message like unable 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.