Fixing 502 Bad Gateway: Troubleshooting Nginx, Istio, and Ingress Incompatibilities
DevOps

The dreaded 502 Bad Gateway error is one of the most frustrating issues to debug because it doesn't tell you what broke, it just tells you that one server received an invalid response from another server.
If you are running an API gateway, reverse proxy (like Nginx), or a service mesh (like Istio) in front of a Node.js or Go backend, a 502 usually comes down to mismatched timeout configurations.
The Fix: When troubleshooting a 502 error, follow this infrastructure triage checklist:
Check the Keep-Alive Timeout: A common culprit is when your reverse proxy keeps a connection alive longer than your backend service does. If Node.js abruptly closes an idle connection right as Nginx tries to reuse it, Nginx throws a 502. Ensure your backend's keep-alive timeout is slightly longer than your proxy's timeout.
Verify Upstream Ports: Ensure your ingress controller or container service mesh is routing traffic to the exact internal port your backend app is listening on (e.g., matching port 3000 inside the container environment).
Examine Container Health Probes: If your deployment platform or Kubernetes cluster detects that your application failed its readiness check, it will tear down the routing path, resulting in an immediate 502 gateway error for incoming traffic.