← Repair Hub

502 Bad Gateway Error

HTTP & Server Errors

What you’re seeing

The browser shows “502 Bad Gateway”, sometimes branded by Cloudflare or your host. It often comes and goes — fine on refresh, broken a minute later.

What it actually means

Modern sites rarely run on one machine. A request passes through a proxy or CDN, which hands it to a web server, which hands it to PHP. A 502 means one of those handoffs failed: the machine in front asked the machine behind for your page and got back something it could not understand, or nothing at all.

The useful consequence is that a 502 is usually about infrastructure rather than your content. Something upstream is overloaded, restarting, timing out, or misconfigured — which is why 502s so often flicker rather than sit still.

What usually causes it

Most likely first.

  1. 1

    The PHP process crashed or restarted

    PHP-FPM ran out of workers, hit a memory ceiling, or was restarted mid-request. The web server asked for a page and found nobody home.

  2. 2

    A traffic or resource spike

    A burst of visitors, a bot crawl, or a heavy background job used every available worker. Requests queue, then fail. Shared hosting hits this ceiling early.

  3. 3

    A CDN or proxy misconfiguration

    Cloudflare or a similar layer is pointed at the wrong origin, or the origin is refusing its requests. The branded 502 page is the tell.

  4. 4

    A slow query or script exceeding the gateway timeout

    The page eventually would have rendered, but the proxy gave up waiting and returned 502 instead.

  5. 5

    The host is having a bad day

    Sometimes it is genuinely not your site. Server maintenance, a failed deploy, or a network fault upstream produces exactly this error.

How to fix it

Work through these in order. Take a backup before you change anything.

  1. Step 1Confirm it is not just you

    Reload in a private window and test from a phone on cell data. Check your host's status page. If the error is intermittent across networks, suspect resources rather than code.

  2. Step 2Bypass the CDN

    If you run Cloudflare or similar, temporarily pause it and load the origin directly. If the site works, the fault is in the proxy layer, not your application.

  3. Step 3Check server resources

    Look at CPU, memory, and PHP worker usage in your hosting panel around the time of the error. Exhausted workers are the single most common signal behind a flickering 502.

  4. Step 4Read the server and PHP-FPM logs

    Look for worker timeouts, out-of-memory kills, or restart entries. These name the failing handoff more precisely than the browser ever will.

  5. Step 5Find the slow thing

    If the 502s cluster on one page or one admin action, that request is the suspect — usually a slow database query, an external API call with no timeout, or an unbounded import.

When to stop and call someone

Call someone if the 502s keep returning after a restart, if they cluster around your busiest hours, or if your host says the server is fine and you have no way to prove otherwise. Recurring 502s under load are a capacity and code problem, and they get worse as you grow.

Frequently asked

It means one server passed your request to another and got back an invalid response or none at all. The failure is in the handoff between machines — typically a proxy, web server, and PHP process — rather than in the page content itself.

It can be either. Exhausted PHP workers, a slow query, or a misconfigured CDN are yours; a crashed service, failed deploy, or upstream network fault is the host's. Checking the host status page and pausing your CDN separates the two quickly.

Because it is usually about capacity. When every PHP worker is busy, new requests fail; when one frees up, the next request succeeds. That produces an error that appears on some loads and not others, often worse during traffic peaks.

Often, temporarily. Restarting PHP-FPM or the web server clears stuck workers and the site returns. If the underlying cause is a slow query or too little capacity, the error comes back — a restart buys time to diagnose, not a fix.

Yes. If Cloudflare cannot reach your origin server, or the origin refuses its requests, it serves its own branded 502 page. Pausing Cloudflare and loading the site directly tells you within seconds whether the proxy layer is the problem.

Free · AI-powered · Emailed to you

See exactly what’s holding your website back.

Get a free audit of your site — speed, SEO, mobile, and security — with the fixes that matter most, delivered as a PDF to your inbox.

Get my free audit
CallGet a quote