500 vs 502: Internal Server Error vs Bad Gateway
A 500 comes from the application itself failing. A 502 comes from a proxy (Nginx, load balancer, CDN) that couldn’t get a valid response from the application.
500
HTTP 500 Internal Server Error
The server hit an unexpected condition — usually an unhandled exception or misconfiguration in the application.
Causes & fixes →
502
HTTP 502 Bad Gateway
A proxy or gateway (Nginx, load balancer, CDN) got an invalid response — or no response — from the upstream server behind it.
Causes & fixes →| 500 | 502 | |
|---|---|---|
| Who generates it | The application / origin server | A proxy or gateway in front of it |
| What it means | App crashed or threw an unhandled error | App unreachable, crashed mid-response, or sent garbage |
| Where to look | Application logs | Proxy error log first, then the upstream |
| Common fix | Fix the bug/config causing the exception | Start the upstream, fix socket/port, raise buffers |
Rule of thumb
Check the response’s Server header and HTML: if Nginx/Cloudflare/ALB branded the error, start with the proxy log.