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 →
500502
Who generates itThe application / origin serverA proxy or gateway in front of it
What it meansApp crashed or threw an unhandled errorApp unreachable, crashed mid-response, or sent garbage
Where to lookApplication logsProxy error log first, then the upstream
Common fixFix the bug/config causing the exceptionStart 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.