Fast turnaround. No long contracts.
Fix 502 Bad Gateway and 504 Gateway Timeout Errors
Your web server can’t talk to your app — or the app is too slow to respond. I’ll find the broken layer and fix it.
Both errors mean the web server couldn't get a good answer from the thing behind it (PHP, an app server, an upstream). A 502 means it got a broken reply; a 504 means it waited too long and gave up. Neither is a problem with the visitor's browser.

Sound Familiar?
What I'll Do
What each one is telling you
- 502 Bad Gateway — the web server (nginx/Apache) reached the backend but got an invalid or empty response. Usually PHP-FPM crashed, restarted, or a worker died mid-request.
- 504 Gateway Timeout — the backend was reached but didn't respond in time. Usually a slow query, an external API call hanging, or a long-running task blocking a worker.
- Intermittent 502/504 under traffic — the classic sign of too few PHP-FPM workers for the available memory: requests queue until the web server times out. Covered in depth in the stuck-PHP-FPM writeup.
How I track it down
- 1
Read the web-server error log
The nginx or Apache error log records the actual upstream failure — "connection refused", "worker exited", "upstream timed out". This names the cause; the browser's 502 page tells you nothing.
- 2
Check whether the backend is alive and sized right
Is PHP-FPM running? Is it configured with enough workers for the plan's RAM, or is it starving under load? An undersized worker pool is the most common cause of intermittent gateway errors.
- 3
Find what's slow (for 504s)
A 504 points at a specific slow operation — a query missing an index, an external API with no timeout, a heavy cron job. The slow-query log or an application trace finds it.
- 4
Fix the cause and add headroom
Right-size the worker pool, add the missing index or timeout, or move the heavy task off the request path. Then confirm the error log goes quiet under load.
Gateway error questions
It happens randomly, then recovers. Why?
That pattern is almost always worker starvation: under a burst, every PHP worker is busy, new requests queue, and the web server times them out until the burst passes. Right-sizing the pool fixes it.
Is a 502 my host's fault or mine?
Either. If the host's infrastructure is down it's theirs; if your app is crashing PHP or running slow queries it's yours. The error log tells which, and I'll give you the evidence to push back on the host if it's theirs.
Will a bigger plan fix it?
Only if the cause is genuinely capacity. If a single slow query or a hung API call is the problem, a bigger server just fails more expensively. Diagnose first.
Related articles
Deep-dive guides on the same topic.

What 502, 503, and 504 Errors Really Mean (And How to Fix Them)
Seeing 502 Bad Gateway, 503 Unavailable, or 504 Gateway Timeout? Here’s what each one actually means on your server — and the fix for each.

Redirect Chains and 404 Errors Are Killing Your SEO
Broken links, redirect chains, and soft 404s silently bleed your SEO. Here’s how to audit, find, and fix them before they hurt your rankings.
Ready to Get This Fixed?
Send me a message and tell me what's going on. I'll take a look and let you know how I can help.