# 502 Bad Gateway

> A 502 Bad Gateway means a proxy or CDN got an invalid response from the server behind it. See who causes it, how visitors get past it, and how owners fix it.

Canonical: https://scaplet.com/errors/http/502

Guide Error · HTTP status codes

A 502 Bad Gateway means a proxy or CDN got an invalid response from the server behind it. See who causes it, how visitors get past it, and how owners fix it.

5 min

read

6

sources

Oct 22, 2026

updated

Scaplet Editorial Team

author

502 5xx · Server error

The short answer

A 502 Bad Gateway means a server acting as a gateway or proxy, such as nginx, a load balancer or a CDN, received an invalid response from the server behind it. The cause is usually on the site side, not yours. Visitors can retry; owners should check that the origin is running and answering the proxy correctly.

1. [What a 502 means and who causes it](#what-a-502-means-and-who-causes-it)
2. [How to get past a 502 as a visitor](#how-to-get-past-a-502-as-a-visitor)
3. [How to find the cause as a site owner](#how-to-find-the-cause-as-a-site-owner)
4. [What it does to SEO](#what-it-does-to-seo)

30-second check

## Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?

Summarize this page with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F502%20(%22502%20Bad%20Gateway%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F502%20(%22502%20Bad%20Gateway%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F502%20(%22502%20Bad%20Gateway%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F502%20(%22502%20Bad%20Gateway%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

_01_Who usually causes a 502

## What a 502 means and who causes it

RFC 9110 defines 502 as a status that "indicates that the server, while acting as a gateway or proxy, received an invalid response from an [inbound](/glossary/inbound-marketing) server it accessed while attempting to fulfill the request." Two servers are involved. The one you talked to (the proxy, load balancer or CDN) is fine enough to answer. The one behind it (the origin, or "upstream") failed to give it a usable reply.

Layer

### Origin server

Typical cause

The app or web server crashed, restarted, or is not listening where the proxy expects

Who can fix it

Site owner or host

Layer

### Proxy or load balancer

Typical cause

Wrong upstream address, port or socket; response headers larger than the proxy buffer

Who can fix it

Site owner or host

Layer

### CDN

Typical cause

Cannot connect to the origin, TLS mismatch with the origin, malformed compressed response

Who can fix it

Site owner, sometimes the CDN vendor

Layer

### Visitor network

Typical cause

VPN, DNS, firewall or proxy settings; the site works for other people

Who can fix it

Visitor

MDN adds the distinction that matters when you debug. If the origin sends a valid HTTP error response, the gateway should pass that on instead of a 502. If the gateway gets no HTTP response at all within its time limit, it sends a [504 Gateway Timeout](/errors/http/504). So a 502 points at a reply that was broken, empty or refused, not a slow one.

_02_How it works

## How to get past a 502 as a visitor

A 502 does not mean you were blocked. It describes a failure between two servers. A server that understood the request and refuses it sends [403 Forbidden](/errors/http/403) instead, which RFC 9110 defines as "understood the request but refuses to fulfill it".

1. 01

### Reload once or twice

If the origin was restarting or overloaded, a reload can work. Wait a minute, then try again.
2. 02

### Test another network or device

MDN says fixing a 502 probably requires investigation by server owners or administrators, with client networking errors as the exception, particularly if the service works for other visitors and if clients use VPNs or other custom networking setups. Turn off the VPN or try mobile data.
3. 03

### Check your own settings

If only your connection fails, check network settings, firewall setup, proxy settings and DNS configuration, as MDN suggests.
4. 04

### Contact the site

If every device and network fails, the owner or host has to fix it. Tell them the time of the error and the exact URL.

_03_Common causes of a 502, where to look and the fix

## How to find the cause as a site owner

Work from the origin outward. First test the origin directly, skipping the proxy and CDN. If it answers correctly, the fault is in the proxy configuration or the path between them. If it does not answer, the proxy is only reporting a real origin failure.

Cause

### Origin process is down

Where to look

Process manager status, app logs, host memory

Fix

Restart it and fix the crash; add a health check so the load balancer stops sending traffic to a dead node

Cause

### Wrong upstream address, port or socket

Where to look

Proxy config (for nginx, the `proxy_pass` or `fastcgi_pass` line)

Fix

Point it at the address the app really listens on

Cause

### Origin response header larger than the buffer

Where to look

Proxy buffer settings

Fix

In nginx, raise `proxy_buffer_size`: the docs say a first response part over the buffer size "is considered invalid"

Cause

### TLS to origin fails (CloudFront)

Where to look

Origin certificate names, expiry and chain

Fix

CloudFront returns 502 for an expired, invalid or self-signed origin certificate, a wrong-order chain, or a name that matches neither the Origin Domain nor the `Host` header

Cause

### Origin refuses CloudFront on its ports

Where to look

Firewall and security rules for ports 80 and 443 by default

Fix

Allow the published CloudFront ranges and confirm the web server is running

Cause

### Origin DNS fails (CloudFront)

Where to look

The `NonS3OriginDnsError` code

Fix

Fix the DNS records for the origin domain, then retest with `dig` from a public network

Cause

### Compression mismatch (Cloudflare)

Where to look

Origin response headers

Fix

Cloudflare lists an origin that serves gzip-encoded content but does not update the `content-length` header as one cause of 502 and 504

Test the origin directly

```
# From the proxy host, hit the app on its own port curl -sS -o /dev/null -w "%{http_code} %{time_total}s\n" http://127.0.0.1:8000/ # Through the public hostname, with response headers curl -sSI https://example.com/ | head -n 20
```

**Read the error page itself**Cloudflare says a 502 or 504 that comes from Cloudflare itself is a blank page without Cloudflare branding. A Cloudflare-branded 502 or 504 means your origin sent that status, so start at the origin. For a support ticket, Cloudflare asks for the time and timezone, the URL, and the output of `/cdn-cgi/trace` on your domain.

If your proxy is nginx, the stack-specific checks (socket permissions, buffer sizes, PHP-FPM) are on [502 Bad Gateway in nginx](/errors/http/502/nginx). If the proxy got no HTTP response at all, you will see [504 Gateway Timeout](/errors/http/504) instead.

Causes and fixes differ by server and platform. See the 502 guides for [Apache](/errors/http/502/apache), [Cloudflare](/errors/http/502/cloudflare), [nginx](/errors/http/502/nginx).

_04_Explained

## What it does to SEO

Google treats 5xx responses as server errors: they make its crawlers temporarily slow down, content returned with them is ignored, and already indexed URLs are preserved but eventually dropped if the errors persist. Google says that once the server responds with a 2xx [status code](/glossary/http-status-codes) again, it gradually increases the crawl rate. See [5xx server errors](/seo-issues/server-errors-5xx) for how to trace and verify recovery, and Google's documentation on how HTTP status codes affect its crawlers.

Questions

## Asked a lot.

4 questions people ask next, answered from the sources on this page.

_01_ Is a 502 error my fault?

Rarely. A 502 is a gateway or proxy reporting that the server behind it gave an invalid response, so the fix is on the site owner or host side. The exception is your own network: MDN says VPNs, firewall, proxy and DNS settings can cause it when the site works for other people.

_02_ What is the difference between 502 and 504?

A 502 means the gateway received an invalid response from the upstream server. A 504 means the gateway did not receive a response from it in time. In MDN's wording, with a 504 the proxy "did not receive any HTTP response from the origin within a certain time".

_03_ How do I fix a 502 Bad Gateway on my own site?

Request the origin directly. If it fails, restart or repair the app. If it works, check the proxy or CDN: the upstream address, buffer sizes, TLS settings to the origin, firewall rules and DNS. Then retest through the public hostname.

_04_ Does a 502 mean I am blocked?

No. A 502 describes a failure between two servers. A server that understood the request and refuses it responds with 403 Forbidden.

Sources · 6

## Every fact, linked and dated.

Official docs first. The date is when we last opened each page.

- rfc-editor.org
- mozilla.org
- google.com
- cloudflare.com
- amazon.com
- nginx.org

1. 01 [RFC 9110: HTTP Semantics](https://www.rfc-editor.org/rfc/rfc9110.html) rfc-editor.org · checked 2026-10-25
2. 02 [MDN: 502 Bad Gateway](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/502) developer.mozilla.org · checked 2026-10-25
3. 03 [How HTTP status codes affect Google's crawlers](https://developers.google.com/crawling/docs/troubleshooting/http-status-codes) developers.google.com · checked 2026-10-25
4. 04 [Cloudflare: 502 and 504 errors](https://developers.cloudflare.com/support/troubleshooting/http-status-codes/cloudflare-5xx-errors/error-502-504/) developers.cloudflare.com · checked 2026-10-25
5. 05 [Amazon CloudFront: HTTP 502 status code (Bad Gateway)](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/http-502-bad-gateway.html) docs.aws.amazon.com · checked 2026-10-25
6. 06 [nginx: ngx_http_proxy_module](https://nginx.org/en/docs/http/ngx_http_proxy_module.html) nginx.org · checked 2026-10-25

## Keep learning

[All errors](/errors)

[Learn 502 Bad Gateway in nginx HTTP status codes](/errors/http/502/nginx) [Related 5xx server errors Status codes and links](/seo-issues/server-errors-5xx) [Read next HTTP 500 Internal Server Error HTTP status codes](/errors/http/500) [Do Run a free site audit Free, about two minutes](/site-audit)

Other 502 errors
[Azure Front Door 502](/errors/cdn/azure-front-door-502) [Google Cloud 502 Bad Gateway](/errors/cdn/google-cloud-502) [Render 502 Bad Gateway](/errors/cdn/render-502) [502 Bad Gateway in Apache](/errors/http/502/apache) [502 Bad Gateway in nginx](/errors/http/502/nginx)

Nearby in errors
[HTTP 500 Internal Server Error](/errors/http/500) [HTTP 501 Not Implemented](/errors/http/501) [502 Bad Gateway on Azure](/errors/http/502/azure)

More in HTTP status codes
[416 Range Not Satisfiable](/errors/http/416) [417 Expectation Failed](/errors/http/417) [418 I'm a Teapot](/errors/http/418) [421 Misdirected Request](/errors/http/421) [422 Unprocessable Content (Unprocessable Entity)](/errors/http/422) [423 Locked](/errors/http/423) [424 Failed Dependency](/errors/http/424) [425 Too Early](/errors/http/425) [426 Upgrade Required](/errors/http/426) [428 Precondition Required](/errors/http/428) [429 Too Many Requests](/errors/http/429) [451 Unavailable For Legal Reasons](/errors/http/451) [502 Bad Gateway](/errors/http/502) [503 Service Unavailable](/errors/http/503) [504 Gateway Timeout](/errors/http/504) [505 HTTP Version Not Supported](/errors/http/505) [506 Variant Also Negotiates](/errors/http/506) [507 Insufficient Storage](/errors/http/507) [508 Loop Detected](/errors/http/508) [510 Not Extended](/errors/http/510) [511 Network Authentication Required](/errors/http/511) [5xx errors](/errors/http/5xx-errors) [HTTP 200 OK](/errors/http/200) [HTTP 201 Created](/errors/http/201)

Terms on this page
[Inbound marketing](/glossary/inbound-marketing) [HTTP status codes](/glossary/http-status-codes)

Free · 2 minutes

## Tools point. Agencies advise. _This one ships._

Run the free audit, then approve the fixes. Every change can be undone.

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **0→7** ChatGPT citations in six weeks Paylane
