HTTP 500 Internal Server Error vs 502 Bad Gateway
Both 500 and 502 indicate server-side failures, but they originate from different layers. A 500 means the origin server itself crashed or encountered an unhandled error, while a 502 means an intermediary (reverse proxy, load balancer) received an invalid response from the upstream server.
Descripción
The server encountered an unexpected condition that prevented it from fulfilling the request. A generic catch-all for server-side errors.
Cuándo lo verás
When an unhandled exception occurs, a database connection fails, or server code has a bug.
Cómo solucionarlo
Check server logs for the stack trace. Common causes: unhandled exceptions, database errors, misconfigurations.
Descripción
The server, acting as a gateway or proxy, received an invalid response from the upstream server.
Cuándo lo verás
When Nginx/Apache can't reach the application server (e.g., Gunicorn is down, upstream timeout).
Cómo solucionarlo
Check if the upstream server is running. Verify proxy configuration. Check for upstream timeouts.
Diferencias clave
500 originates from the application server — an unhandled exception, a bug, or a misconfiguration.
502 originates from a proxy or gateway — Nginx, a load balancer, or a CDN could not get a valid response from upstream.
500 usually requires checking application logs for stack traces.
502 usually requires checking whether the upstream server (e.g., Gunicorn) is running and reachable.
A 502 often means the upstream server crashed, returned garbage, or closed the connection unexpectedly.
Cuándo usar cuál
Return 500 when your application code encounters an unrecoverable error such as an unhandled exception or database failure. A 502 is typically generated by a reverse proxy (Nginx, HAProxy) when the upstream application server is unreachable or returns a malformed response. Developers should check the proxy error logs for 502 and the app logs for 500.