TapCub is live — analytics, insights and live chat, free on one platform
Glossary

502 Error (Bad Gateway): Meaning and How to Triage It by Layer

A 502 means a proxy or CDN got an invalid response from the server behind it. How it differs from 500 and 504, who sees it, a five-layer triage table and what repeated 502s do to crawling.

Lin Zhou Reviewed by Emma Collins Also called 502 Bad Gateway Last updated Nov 28, 2026 Glossary

Quick answer

A 502 Bad Gateway error is an HTTP status code returned by a server acting as a gateway or proxy, such as a CDN or nginx, when the upstream server behind it sends an invalid response or refuses the connection. The fault is usually at the origin, not at the server showing the error.

What is a 502 error?

A 502 Bad Gateway error is an HTTP status code that a server acting as a gateway or proxy returns when the server behind it, the upstream, sends back a response it cannot use. RFC 9110, the HTTP standard, defines it in section 15.6.3: the server, "while acting as a gateway or proxy, received an invalid response from an inbound server it accessed while attempting to fulfill the request."

Two consequences follow from that definition, and most troubleshooting lists skip them:

  • The server that shows you the 502 is usually not the one that failed. A CDN, load balancer or reverse proxy (often nginx) generated the page; the application server, PHP or Node process, or an API it called is where the fault is.
  • A 502 needs at least two hops. A site served directly by one process, with nothing in front of it, cannot return a genuine 502 for its own failures; it returns a 500 or drops the connection. If you see 502, there is a proxy layer, and the triage starts by working out which hop failed.

The code is written as "502 Bad Gateway", "HTTP Error 502", "Error 502" or "502 error code"; they are the same response. Brands sometimes add their own wording to the error page, but the status code in the response is what counts.

How is 502 different from 500, 503 and 504?

All four are 5xx server errors, but each points to a different place. The definitions below are from RFC 9110 section 15.6.

CodeNameWhat it meansWhere to look first
500Internal Server ErrorThe server hit an unexpected condition and could not complete the requestApplication error log on the server that answered
502Bad GatewayA gateway or proxy got an invalid response from the upstream serverProxy error log, then whether the upstream process is running and reachable
503Service UnavailableThe server is temporarily unable to handle the request (overload or maintenance); it may send Retry-AfterCapacity, maintenance mode, rate limits
504Gateway TimeoutA gateway or proxy got no timely response from the upstream serverSlow queries or calls in the upstream; proxy timeout settings

The 502/504 split is the useful one: 502 means the upstream answered badly or refused the connection, 504 means it did not answer in time. MDN adds that if the gateway receives no response at all it should send 504, and if the origin sends a valid HTTP error it should pass that through rather than replace it with 502. For the application-level error, see HTTP 500 error.

Who sees a 502: visitors, crawlers or your analytics?

The same failure looks different depending on who is watching:

  • Visitors see the proxy's error page. Because the HTML of your site never arrives, none of your scripts run: no analytics, no chat, no tag manager. In page-script analytics, a 502 outage shows up as a drop in sessions, not as an error count.
  • Search engine crawlers receive the status code itself. Google's documentation says that 5xx responses, including 502, make its crawlers temporarily slow down, in proportion to how many URLs return errors, and that URLs persistently returning a server error are eventually removed from the index.
  • API clients and single-page apps get a 502 on a background request while the page itself loaded. Here your front-end code does run, and whether anything is recorded depends on how it handles the failed call.
  • Your servers' access logs are the only place every 502 is recorded with its URL, time and client, which is why log-based monitoring catches what page-script analytics cannot.

How do you triage a 502 layer by layer?

Work from the outside in, stopping at the first layer that shows the error. Each row lists the check and the evidence to look for.

LayerCheckEvidence that the fault is here
1. Client networkDoes the page load from another network or device, and with VPN or proxy turned off?Error only on one network; MDN notes client VPN, proxy, firewall or DNS settings as a cause
2. CDN or edgeDoes the error page carry the CDN's branding, and does the origin respond when requested directly?Origin is healthy when bypassing the CDN; CDN logs show failed connections to origin
3. Reverse proxy / load balancerProxy error log at the time of the 502Lines such as connect() failed (111: Connection refused) while connecting to upstream, upstream prematurely closed connection, no live upstreams
4. Application serverIs the app process or worker pool running, and did it crash or restart?Process manager shows restarts; memory limit kills; deploy at the same minute
5. Upstream dependencyDid an API, database or internal service the app calls fail or return garbage?App logs show errors from the dependency; the 502 is only on routes that use it

Two patterns narrow it down quickly. All URLs at once points to layers 2–4: the proxy cannot reach any healthy app server. Only some routes points to layer 5 or to responses those routes produce, such as headers too large for the proxy's buffer (nginx logs upstream sent too big header; its default proxy_buffer_size is one memory page, 4 KB or 8 KB).

What usually causes 502 errors at the origin?

  • App process down or restarting. A crash, an out-of-memory kill or a deploy that restarts workers leaves the proxy with nothing to connect to: connection refused, 502.
  • Worker pool exhausted. Under load, every worker is busy and new connections are refused or reset. Spikes from bots crawling expensive pages are a common trigger; see bot traffic.
  • Wrong upstream address. A changed port, container name or socket path after a deploy.
  • Malformed or oversized response headers. Large cookies or many Set-Cookie headers exceeding the proxy buffer.
  • Firewall or security rules blocking the proxy's connection to the origin, including CDN IP ranges that were not allowed.
  • Timeouts that end in 502 rather than 504. Some proxies report a reset or closed connection as 502. In nginx, proxy_connect_timeout and proxy_read_timeout both default to 60 seconds, and proxy_next_upstream by default retries another server only on error and timeout, so a single slow or crashing upstream can surface as either code.

How do repeated 502s affect crawling and SEO?

A short 502 outage rarely matters for search. Google's crawlers slow down, and once the server returns 2xx responses again, they gradually increase the crawl rate. The risk is persistence: URLs that keep returning server errors are eventually dropped from the index, and a slowed crawler discovers new pages later.

Sample data: in one week a site's server logs show 12,000 search-engine fetches. 420 of them returned 502, a 3.5% error share. Splitting by hour, 360 of the 420 (86%) fell between 02:00 and 03:00, the window when a nightly backup restarted the app containers. The fix is operational (stagger the restarts or drain traffic first), and the evidence that it worked is the 5xx count for that hour falling to zero the following week. To confirm which status codes crawlers are actually receiving for which URLs, see check URL status codes.

What can visitors do about a 502?

Very little, because the fault is on the server side. Three things are worth trying, in this order: reload after 30–60 seconds (many 502s are brief restarts); try another network or turn off a VPN or proxy, which tests layer 1; and clear the cached copy of the page. If the error persists for everyone, only the site operator can fix it. Site owners should show a plain error page with a status link rather than the proxy's default, and should avoid caching 502 responses at the CDN.

Finding 502s in TapCub

The TapCub page script cannot see a 502 on a full page load, because the error page is served before any of your HTML. What TapCub shows depends on where the records come from:

  1. Send crawler records from the server. The server endpoints accept Nginx or Apache log lines (POST /api/v1/server/logs/import) or access records with a status field (POST /api/v1/server/events), using an API key from Configuration › Settings › API keys. They keep requests classified as bots and drop human ones. The log import on All-platform analytics › Data › Data import builds visitor data instead and skips 4xx and 5xx lines, so it will not show 502s. In short: TapCub can show the 502s crawlers received, not the ones human visitors hit.
  2. Check crawl health for search engines. Monitoring › Crawl health shows total fetches, success rate (status below 400), 404s and 5xx per search engine, with the most-fetched pages per crawler. The sample week above would show 420 5xx out of 12,000 fetches there. Walkthrough: check crawl health.
  3. See which bots received errors. Web analytics › Bots lists the most common status code each bot received, and search engines get a small health table with 5xx counts.
  4. Watch visitors for the drop, and front-end errors for API 502s. A full-page 502 appears in visitor reports only as missing sessions; mark the incident with Configuration › Annotations so the dip is explained later. If your front-end code throws an exception when a background API call returns 502, those exceptions appear in Monitoring › Errors with page, time and session.

TapCub does not ping your site from outside or check uptime, so it will not alert you the moment a 502 starts; use an uptime monitor for that and TapCub to see who was affected.

Sources

Was this explanation clear?

We use your answers to fix and expand this page.

Lin Zhou

Product Experience Specialist

Writes about product experience, practical workflows, and growth, turning complex processes into clear steps for everyday decisions.

FAQ

Questions people ask

Short answers to the follow-up questions that come up most.

Still have a question?

Chat with the team behind TapCub — we usually reply within a few hours on business days.

What does a 502 Bad Gateway error mean?

It means a server sitting in front of the site, such as a CDN, load balancer or reverse proxy, tried to get the page from the server behind it and received an invalid response or a refused connection. The problem is on the website's side, usually the application server or a service it depends on.

Is a 502 error my fault or the website's?

Almost always the website's. Try reloading after a minute, switching networks or turning off a VPN or proxy; if the page loads elsewhere, the issue was your network path. If the error persists everywhere, only the site operator can fix it.

What is the difference between 502 and 504?

Both come from a gateway or proxy. A 502 means the upstream server answered with an invalid response or refused the connection; a 504 means it did not answer in time. A 502 points to a crashed or misconfigured upstream, a 504 to slow queries or calls.

Do 502 errors hurt SEO?

Short outages rarely do: Google's crawlers slow down and then gradually return to normal once pages respond with 2xx again. URLs that keep returning server errors are eventually removed from the index, so fix recurring 502s and watch the 5xx count crawlers receive.

See this number on your own site

Add one script tag for web and apps, and the first reports fill in within minutes.

See your data clearly. Find your growth.

Every click, backed by data. Install one line of code and see your first numbers in a minute.

No credit card · Free plans for analytics and chat · Cookieless analytics