5025xx Server ErrorCritical

HTTP 502 Bad Gateway

Defined in RFC 7231

What Does HTTP 502 Mean?

The server, acting as a gateway or proxy, received an invalid response from the upstream server.

Common Causes

  1. 1Upstream server crashed or is unresponsive
  2. 2Reverse proxy cannot reach the application server
  3. 3DNS resolution failure for upstream
  4. 4Upstream server returning malformed responses
  5. 5PHP-FPM or application process crashed

Impact

  • Website completely unavailable
  • All pages return errors
  • Service outage

Developer Fix

For web developers and application engineers

  1. 1Check upstream server health and logs
  2. 2Verify application process is running (e.g., PM2, Gunicorn)
  3. 3Test direct connection to upstream bypassing proxy
  4. 4Review recent deployments that may have broken the app

Server Admin Fix

For system administrators and DevOps engineers

  1. 1Restart the upstream application server
  2. 2Check nginx/Apache proxy pass configuration
  3. 3Verify upstream server is listening on the correct port
  4. 4Review load balancer health check results
  5. 5Check DNS resolution for upstream hostnames

Frequently Asked Questions

What's the difference between 502 and 504?
502 means the proxy received an invalid response from the upstream server (server responded but the response was bad). 504 means the proxy didn't receive any response at all (upstream timed out).
How do I fix a 502 Bad Gateway?
For users: wait and retry. For admins: check if the upstream application is running, verify proxy configuration, check upstream server logs, and ensure the app is listening on the expected port.

Related HTTP Status Codes

About the Author

Web Infrastructure Team

Verified against official RFC specifications and real-world server configurations. HTTP status code behavior confirmed across Apache, Nginx, and Cloudflare.