Skip to content

Home · Blog · 502 Bad Gateway: what it means and what to do

Send a request

New format

502 Bad Gateway: what it means and what to do

502 Bad Gateway means a proxy or gateway (often nginx or a CDN) did not get a valid response from the upstream — PHP, Apache, or your app.

It is not an “SEO penalty.” A site that stays down still loses traffic and crawl while the error hangs. Below: common causes and what to check.

Share
Telegram

Typical causes

PHP-FPM or the app is down or not answering, an upstream timeout expired, the server is overloaded, the proxy config is broken, the CDN is glitching, or SSL between proxy and backend is failing.

The same page may return 502 only under load — for example a heavy database query that ties up every worker. Note the exact time and URL; a screenshot of the error page alone is not enough.

Often shows up after:

  • a deploy or config change
  • a traffic spike
  • stuck CMS plugins
  • hitting hosting limits

Test yourself

Mini quiz: 502

Two checks.

1 502 Bad Gateway is usually about…
2 Masking 502 with a redirect…

How to fix it

Check hosting status and your uptime monitor. Read nginx or Apache logs and PHP logs. Restart the PHP pool or container only by your usual procedure. Disable a recently installed CMS plugin if the timing lines up with the error.

Do not start by randomly changing DNS, PHP version, or a dozen settings. Localize the layer first: CDN, web server, app, database, or an external API. That way the fix does not hide the cause — or create a new one.

Order of checks:

  • confirm 502 from outside (`curl -I`)
  • gateway and application logs
  • CPU, RAM, and disk load
  • upstream timeouts
  • roll back the last change

Web server Server logs

Practice

502 checklist

While the site is down.

0 / 7 done

Prevention

You need uptime monitoring, sane limits, staging before release, cache and queues for heavy jobs, and some resource headroom.

Do not watch only the homepage. Include checkout, login, forms, APIs, and a few key category pages — they often stress the app differently than a static home.

For the SEO team:

  • alert when key URLs return 5xx
  • do not confuse 502 with a search filter
  • after recovery, check indexing of important pages

Diagnosis via logs and metrics

In the proxy log, find the request by time, URI, and request id, then match it to the app log. Messages about connect() failed, premature response, timeout, or exhausted workers tell you where to dig next.

Metrics help tell a one-off blip from a systemic issue. Watch CPU and memory, disk space, process count, database response time, and the request queue before, during, and after the incident.

Before you ping a developer or host, prepare:

  • exact URL and time with timezone
  • status code and how often it repeats
  • log snippets without passwords or tokens
  • list of recent releases and config changes

What to check after recovery

After the fix, hit the URLs again from outside, in a private window, and via monitoring. Make sure the error did not vanish on one node or in local cache only — and that key user flows still work.

If bots and visitors saw 502 for a long stretch, check webmaster reports and crawl trends. Do not auto-request a recrawl of thousands of URLs until the server response is stable.

Close the incident when:

  • several checks return the expected codes
  • load and log errors look normal again
  • cause and actions are written down
  • a clear alert is set for a repeat

FAQ

Is 502 an SEO problem?

Indirectly: bots and visitors cannot see the page. Long downtime hurts. The code itself is about infrastructure, not a ranking filter.

How is it different from 500 and 504?

500 is an application error. 504 means the gateway timed out waiting. 502 means the backend response was missing or broken.

Can a visitor see it when I don’t?

Yes — local cache, another CDN POP, or a short blip. Check in a private window and with an external uptime check.

Will changing DNS fix it right away?

Rarely as first aid. Start with logs, backend status, and PHP or worker limits.

Should you redirect around a 502?

No. Fix the server or app. Do not paper over 502 with a redirect.

Should you clear cache on a 502?

Only if you have reason to think a bad response was cached. Clearing cache does not replace checking the backend, logs, and limits.

When should you contact hosting support?

Immediately if you lack server access or logs show infrastructure faults. Send the error time, URL, status code, and what you already checked.

Site returns 502 and support only says “clear the cache”?

We’ll localize gateway vs backend, read logs, and restore stable responses — no redirect masks.

Discuss the task