---
title: Error 502 or 504
description: Troubleshoot HTTP 502 error responses.
image: https://developers.cloudflare.com/core-services-preview.png
---

> Documentation Index  
> Fetch the complete documentation index at: https://developers.cloudflare.com/support/llms.txt  
> Use this file to discover all available pages before exploring further. 

[Skip to content](#%5Ftop) 

# Error 502 or 504

## Error 502 bad gateway or error 504 gateway timeout

An HTTP `502` or `504` error indicates that Cloudflare is unable to establish contact with your origin web server.

### Common causes

There are two possible causes:

* [502/504 errors from your origin web server](#502504-from-your-origin-web-server) (most common).
* [502/504 errors from Cloudflare](#502504-from-cloudflare).

You may also see `504` status codes in logs or analytics caused by [cache MISS responses from Early Hints](https://developers.cloudflare.com/cache/advanced-configuration/early-hints/#emit-early-hints), or by Cloudflare Workers Cache API [cache.match operations resulting in cache MISS ↗](https://developers.cloudflare.com/workers/runtime-apis/cache/#errors-1).

### Resolution

To resolve `502/504` errors, it is essential to identify whether the issue originates from your origin web server or Cloudflare. In the following sections, you can find more details for troubleshooting and resolving errors from both sources.

#### 502/504 from your origin web server

Cloudflare 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:

![Example of a Cloudflare-branded error 502.](https://developers.cloudflare.com/_astro/image1.bhOtPL9__Z11fWXs.webp) 

Contact your hosting provider to troubleshoot these common causes at your origin web server:

* Ensure the origin server responds to requests for the hostname and domain within the visitor's URL that generated the `502` or `504` error.
* Investigate excessive server loads, crashes, or network failures.
* Identify applications or services that timed out or were blocked.

#### 502/504 from Cloudflare

A `502` or a `504` error originating from Cloudflare appears as follows, a blank page without the Cloudflare branding:

![Example of an unbranded error 502.](https://developers.cloudflare.com/_astro/image5.DQ6zBJUs_21yXXb.webp) 

If the error does not mention `cloudflare`, contact your hosting provider for assistance. Refer to [502/504 errors from your origin](#502504-from-your-origin-web-server) for more information.

This error can occur due to a compression issue at the origin, such as when the origin server serves gzip-encoded compressed content but fails to update the `content-length` header, or if the origin is serving broken gzip compressed content. To diagnose this, you can try disabling compression at your origin to confirm if it resolves the error.

Additionally, in some cases, a particular data center may experience a sudden increase in traffic. To ensure minimal impact for customers, our automated processes will redirect traffic to another data center. These adjustments typically happen seamlessly and take just a few seconds. However, during this process, some clients may experience temporary latency or HTTP `502` errors. You can find more information about our automated traffic management tools in this [blogpost ↗](https://blog.cloudflare.com/meet-traffic-manager).

If you need further assistance from our Support team, provide the following details to [Cloudflare Support](https://developers.cloudflare.com/support/contacting-cloudflare-support/) to avoid delays in processing your inquiry:

* The timestamp along with the timezone in which the issue occurred.
* The URL that resulted in the HTTP `502` or `504` response (for example, `https://www.example.com/images/icons/image1.png`).
* The output from browsing to `<YOUR_DOMAIN>/cdn-cgi/trace`.

### Known Cloudflare issues leading to HTTP Error 502 or 504

* Using [Gateway](https://developers.cloudflare.com/cloudflare-one/traffic-policies/) can lead to an HTTP Error `502` if the origin only partially supports HTTP/2\. Refer to [Troubleshooting](https://developers.cloudflare.com/cloudflare-one/traffic-policies/troubleshooting/#error-502-bad-gateway) for more details and resolution.
* You might see a `502 Bad Gateway` error when connecting to an HTTP or HTTPS application through [Cloudflare Tunnel](https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/), with `Unable to reach the origin service. The service may be down or it may not be responding to traffic from cloudflared`. It means the tunnel itself is connected to the Cloudflare network, but `cloudflared` cannot reach the origin service defined in your ingress rule. Refer to the [tunnel common errors page](https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/troubleshoot-tunnels/common-errors/#i-see-a-502-bad-gateway-error-when-connecting-to-an-http-or-https-application-through-tunnel) for more details and resolution.
* You may see an influx of HTTP Error `504` with the `RequestSource` of `earlyHintsCache` in Cloudflare Logs when Early Hints is enabled, which is expected and benign. Refer to [the Early Hints article](https://developers.cloudflare.com/cache/advanced-configuration/early-hints/#emit-early-hints) for more details and resolution.

```json
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/support/troubleshooting/http-status-codes/cloudflare-5xx-errors/error-502-504/#page","headline":"Error 502 or 504 · Cloudflare Support docs","description":"Troubleshoot HTTP 502 error responses.","url":"https://developers.cloudflare.com/support/troubleshooting/http-status-codes/cloudflare-5xx-errors/error-502-504/","inLanguage":"en","image":"https://developers.cloudflare.com/core-services-preview.png","dateModified":"2026-04-23","publisher":{"@type":"Organization","name":"Cloudflare","url":"https://www.cloudflare.com/"},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"/directory/","name":"Directory"}},{"@type":"ListItem","position":2,"item":{"@id":"/support/","name":"Support"}},{"@type":"ListItem","position":3,"item":{"@id":"/support/troubleshooting/","name":"Troubleshooting"}},{"@type":"ListItem","position":4,"item":{"@id":"/support/troubleshooting/http-status-codes/","name":"HTTP Status Codes"}},{"@type":"ListItem","position":5,"item":{"@id":"/support/troubleshooting/http-status-codes/cloudflare-5xx-errors/","name":"Cloudflare 5xx errors"}},{"@type":"ListItem","position":6,"item":{"@id":"/support/troubleshooting/http-status-codes/cloudflare-5xx-errors/error-502-504/","name":"Error 502 or 504"}}]}
```
