HTTP 502 · proxy and origin
502 Bad Gateway: where to look for the broken connection.
A 502 usually arises between an intermediate layer and the service that should generate the response. You need to establish which two elements can’t communicate.
Next step
Give the domain, the time, how often it happens and whether Cloudflare, a load balancer or a reverse proxy sits in front of the server.
01
What this symptom really means
The gateway or proxy received a response it couldn’t use, or failed to connect properly to the upstream. The code alone doesn’t say whether the origin is down, resetting the connection or returning a corrupted response.
02
A safe first step
Record the headers, the time and the URL. Check whether the error skips certain static files and whether it occurs directly on the origin, provided the test doesn’t bypass security or expose the server.
03
The most common layers of the cause
Possible causes include a stopped PHP-FPM, a wrong socket, a container restart, a connection reset, the wrong port, a firewall, a TLS problem to the origin, overload or an application failure before headers are sent.
04
What data to keep before making changes
You need proxy and upstream logs from the same time, the connection configuration, process status, the latest deployment and resource graphs. Keep request IDs if the infrastructure adds them.
05
What a responsible diagnosis looks like
The error at the edge is correlated with the origin log and the process state. The connection between layers, the correctness of the port or socket and the behaviour of a specific request under controlled load are tested.
06
What not to do blind
Don’t raise timeouts blind, and don’t restart all services before collecting logs. A restart can hide the cause, and a longer timeout only postpones the error.
07
When you need technical help
Help is needed with recurring 502s, multiple proxy layers, no access to the origin, errors after a deployment or a simultaneous rise in response time and resource use.
Does the 502 appear all the time, or only for a certain operation?
We’ll compare the proxy, application runtime and origin logs and establish whether the problem lies in the connection, the process or the load.
Only 3 required fields · reply within 1 business day · no obligation
