502 vs 504
A 502 and a 504 both come from a server acting as a gateway or proxy, such as a load balancer or CDN sitting in front of your application. Both mean the proxy could not get a usable response from the backend behind it.
The difference is what went wrong upstream. A 502 means the backend answered with something invalid; a 504 means it did not answer in time at all.
At a glance
| Aspect | 502 | 504 |
|---|---|---|
| Meaning | Bad Gateway | Gateway Timeout |
| What the proxy saw | An invalid or broken response | No response before the timeout |
| Likely cause | Backend crashed, returned garbage, or refused the connection | Backend too slow, overloaded, or hung |
| First thing to check | Is the backend process up and responding correctly? | Is the backend slow, and are timeout limits too tight? |
| Both affect SEO if | Sustained errors stop pages being indexed | Sustained errors stop pages being indexed |
What a 502 points to
A 502 Bad Gateway means the proxy reached the backend but got back a response it could not use: the backend crashed mid-request, returned malformed output, or refused the connection. Start by checking that the application process is running and healthy.
Look at backend logs around the time of the error. A 502 usually reflects a real failure in the application rather than a network delay.
What a 504 points to
A 504 Gateway Timeout means the proxy waited for the backend and gave up before any response arrived. The backend may be overloaded, stuck on a slow query, or hung on an external call.
Check whether the backend is simply slow, and whether the proxy's timeout is too short for legitimate long requests. The fix is usually to speed up the backend or raise the timeout for the slow path.
Frequently asked questions
- Is a 502 or 504 my fault or the host's?
- Both originate from a gateway in front of your app, but the root cause is usually the backend it proxies to. A 502 points to a broken backend response; a 504 points to a backend that was too slow. The hosting layer surfaces the error, not necessarily the cause.
- Do 502 and 504 errors hurt SEO?
- A brief, occasional gateway error is tolerated. Sustained 502s or 504s stop pages from being indexed and signal an unreliable site, which slows your crawl rate, so they are worth fixing quickly.
- How do I tell which one I'm getting?
- Check the actual status code the server returns rather than guessing from a generic error page. A 502 means a bad backend reply; a 504 means the backend never replied in time.
Full reference
Related comparisons
See what your own site returns
Check the live status code of your URLs to confirm whether you are seeing a 502 or a 504.