Cloudflare 502 Bad Gateway

Updated 11 October 2026

Short answer

When you see "502 Bad Gateway" with Cloudflare branding, the most common cause is that your own server returned a 502 and Cloudflare displayed it. So the broken part is usually behind your web server: the app has crashed, stopped, or isn't listening where your web server expects. Less often, the 502 really comes from Cloudflare, and then it's usually brief and affects many sites at once.

What's the problem

Visitors see "502 Bad Gateway" with "cloudflare" written under it, or a Cloudflare error page with the 502 code.

Why it happens

  • Your app behind the web server has crashed or isn't running (the most common case).
  • The web server can't reach the app, often a wrong port after a config change.
  • The app is restarting after a deploy.
  • Rarely, a Cloudflare-side problem, which usually shows on Cloudflare's status page.

How to fix it

  1. Check whether the 502 comes from your server or Cloudflare. If the page shows a plain "502 Bad Gateway" with "cloudflare" underneath but no Cloudflare diagram, it's typically your server's response.
  2. Check your app is running and restart it.
  3. Read your app and web server logs for the crash reason.
  4. Check Cloudflare's status page if many unrelated sites are failing at the same time.
  5. See the general 502 Bad Gateway guide for the server-side fixes.

What Preventionlabs checks

One click runs the full report on your domain. For this problem it shows whether your site loads, how fast, and where its redirects go; uptime checked every 5 minutes, with an email when the site goes down and when it is back. With Cloudflare connected, it also shows which pages returned server errors (5xx) to visitors, and when; your SSL mode and the other settings that commonly cause this; which requests the firewall blocked, by Cloudflare's own rule names; recent deploys and account changes, with their times; DNS changes in the last 7 days.

Run your free report

Your first report is free, no card needed. Then A$50 a month, up to 10 domains. Read-only: it never changes anything.

Sources

  1. Cloudflare: Error 502 or 504official docsCloudflare returns a Cloudflare-branded HTTP 502 or 504 error when your origin web server responds with a standard HTTP 502 bad gateway or 504 gateway timeout error:
  2. Cloudflare: Error 502 or 504official docsTo resolve 502/504 errors, it is essential to identify whether the issue originates from your origin web server or Cloudflare.

Preventionlabs is independent and not affiliated with Cloudflare. Product names are used only to describe the problem.

← All of Cloudflare errors