HelpWithWebFix My Gateway Errors

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.

Detail of an error screen and developer workspace
Photo by David Pupăză on Unsplash

Sound Familiar?

Visitors seeing 502 Bad Gateway errors
Intermittent 504 Gateway Timeout errors
Site works sometimes, fails other times
Errors spike during traffic spikes
App crashed and you’re not sure where

What I'll Do

Identify which layer is returning the error
Restart and stabilize crashed app services
Fix timeout configurations
Diagnose and fix slow database queries behind timeouts
Set up health checks to auto-recover
Graceful deploy workflow to prevent future 502s

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. 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. 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. 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. 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.

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.

CallTextMessage