How to Fix a 502 Bad Gateway Error: The Visitor's Checklist and the Owner's Playbook

CodexFuse Team · 2026-10-26T23:01:20.990Z · 13 min read

A 502 Bad Gateway error is the server's way of saying the message got lost between two computers. Learning how to fix a 502 Bad Gateway error starts with knowing whose job it is: if you are a visitor, a five-minute checklist is all you need, because the real fix almost always sits on the website's side. If you own the site, the fix is a short diagnosis — find which server in the chain stopped answering, then restart it, reconnect it, or roll back the change that broke it. This guide gives you both sides: the visitor checklist first, then the owner's playbook, so you never waste time fixing the wrong end. It completes our error-code trio alongside the 500 Internal Server Error guide and the 404 Not Found guide.

What Is a 502 Bad Gateway Error?

A 502 Bad Gateway error is an HTTP status code that means a server acting as a gateway or proxy received an invalid response from the server behind it. In plain English: your browser asked one server for a page, that server asked a second server for help, and the second server sent back something unusable — or nothing at all. The gateway gives up and shows you the 502 instead of the page.

Most pages you load pass through several hops: your browser reaches an edge service, which contacts a load balancer, a proxy, or an application server. Any server in that chain that acts as a gateway can produce a 502 when its next hop — its "upstream" — returns an empty response, resets the connection, or sends invalid data. The error page itself does not tell you which hop failed, which is why the diagnosis below matters: you trace the response from the gateway to the exact upstream that stopped answering.

The same error wears different labels depending on the server. You may see "502 Bad Gateway", "HTTP Error 502", "502 Proxy Error", "502 Bad Gateway NGINX", "502 Bad Gateway Apache", or "502 Bad Gateway Cloudflare". They all mean the same thing: a gateway got a bad answer from upstream.

502 vs 500 vs 503 vs 504: What Is the Difference?

These four errors all live in the 5xx server-error family, but each points at a different broken part. Knowing which one you have tells you whose logs to read.

Status codeWhat it meansWhose problem it is
500The application itself hit an unexpected condition.The app or site owner — the code failed.
502A gateway got an invalid response from the server behind it.The gateway-to-upstream link — a server stopped answering or answered badly.
503The service is temporarily unavailable — overload or maintenance.The owner — capacity or a maintenance window; may include a Retry-After time.
504The gateway waited too long for the upstream to respond.Timeliness — the upstream was too slow, not necessarily broken.

The practical difference: a 500 comes directly from the application that failed, while a 502 tells you an intermediary could not use another server's response. A 504 is about time, not about a bad response. And a 503 usually means the site is deliberately paused or overloaded, not broken.

What Causes a 502 Bad Gateway Error?

A 502 has many possible causes because it is a catch-all for "the gateway could not use what came back". The most common ones fall into two groups: something on the visitor's path, and something on the server's side.

CauseWhat happenedWho can fix it
Stopped upstream serviceThe application process crashed, restarted, or failed to start.Owner
Wrong address or portThe gateway connects to the wrong host, container, socket, or port.Owner
Server overloadToo many requests at once — a traffic spike, a sale, or a DDoS attack.Owner
Protocol mismatchOne side expects encrypted traffic while the other expects plain HTTP.Owner
DNS problemThe site's DNS points at the wrong server, or the change has not propagated yet.Owner
Firewall or security blockA firewall blocks the connection between the gateway and the upstream.Owner
Proxy or VPN failureYour proxy or VPN cannot reach the site's server, or its own server is too busy.Visitor
Outdated browser cacheYour browser holds a stale or corrupt copy of the page.Visitor
Network timeoutThe origin server took too long to answer, so the gateway gave up.Owner

Two details catch people out. First, heavy traffic does not automatically mean a 502: overload can crash workers or exhaust connections, which an intermediary then reports as a 502 — but a server can also answer overload honestly with a 503. Second, configuration changes often expose hidden dependencies: a new deployment that changes a socket path, hostname, port, or certificate can turn a working site into a 502 in one step, so owners should always compare the first failing request with the release timeline.

How to Fix a 502 Bad Gateway Error as a Visitor

As a visitor, you cannot repair a failed origin server or gateway. What you can do is prove whether the problem is temporary, limited to your network, or the site's problem — and then wait or report it. Work the steps in order and stop as soon as the page loads.

  1. Reload once. Wait about 30 seconds, then press Ctrl+F5 (Windows) or Cmd+R (Mac) to reload and bypass the cache. A brief service restart or routing event often clears itself in under a minute. One reload is enough — repeated refreshing will not fix a dead upstream.
  2. Check whether the site is down for everyone. Try a status-checking site such as Down for Everyone or Just Me, or the site's own status page or social account. If the whole site is down, the answer is waiting, not more troubleshooting on your device.
  3. Test another page on the same site. If the home page loads but one page fails, the problem is narrower than a full outage. Do not repeat a purchase, form submission, or any action that changes state — you do not want to pay or submit twice.
  4. Try a different browser or device. Open the page in a private or incognito window, which disables most extensions, or try another browser or your phone. If it loads there, the problem is local to your first browser.
  5. Disable extensions and your VPN, one at a time. An extension that changes proxy settings or a VPN that cannot reach the site's server can both produce a 502. Disable them only when your own rules allow a direct test, then try the page again.
  6. Clear your browser cache. A corrupt or outdated cached copy can make your browser load the wrong version of the page. Clear the cache (Ctrl+Shift+Del on Windows, Cmd+Shift+Del on Mac), restart the browser, and try again.
  7. Flush your DNS cache. Your computer may hold an outdated record of the site's address. On Windows, open Command Prompt and run ipconfig /flushdns. On a Mac, open Terminal and run sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder, then enter your password.
  8. Restart your device and your router. Restarting clears running programs and memory issues; restarting the modem and router clears temporary network glitches between your home and the site.

If none of that works, wait and try again later — the fault is almost certainly on the website's side and needs time to be fixed. Before you give up, report it: send the site the exact page address, the time and time zone you saw the error, the exact message on the screen, and any request identifier the error page shows. That report is far more useful to the owner than ten more reloads.

One correction worth knowing: clearing all your cookies, reinstalling your browser, or switching DNS servers should not be your default response. Those actions rarely repair the upstream path and can delete useful saved state. A single comparison — one page, one other device, one other network — tells you more than any of them.

How to Fix a 502 Bad Gateway Error as a Website Owner

As an owner, your job is to trace the 502 from the gateway that showed it to the exact upstream that stopped answering. Change one thing at a time, and collect the evidence before you change anything: save the status, headers, requested address, time, and any request identifier first.

  1. Check whether your site is actually running. Open your hosting control panel and confirm the site and its backend services are up. Restart the application process if it has stopped.
  2. Read the error logs on both sides. Match the gateway's log and the upstream's log using the same time and request identifier. The logs usually show the failure before the 502 was sent — a crashed worker, a refused connection, or an invalid response.
  3. Find the selected upstream. Record the backend address, port, protocol, route, and deployment version handling that request. Confirm the gateway is pointed at the right host, container, socket, or port — a wrong address after a deployment is one of the most common causes.
  4. Check for overload. Look for traffic spikes, DDoS attacks, or inefficient backend scripts. If workers, memory, or connection limits are exhausted, the upstream terminates requests and the gateway reports a 502.
  5. Test the firewall and security settings. Temporarily disable the firewall and see whether the site loads. If it does, whitelist your server's IP address or fix the rule that blocked the connection — do not leave the firewall off.
  6. Review recent changes. Disable recently installed or updated plugins and themes one by one, and check recent deployments and PHP version changes. Test any suspected change in a staging environment or through your host's supported recovery process, not on the live site.
  7. Check your DNS configuration. Confirm your DNS records point at the correct IP address. If you recently changed DNS settings, remember that changes can take up to 24 hours to propagate — a 502 right after a DNS change is often just propagation. See our guide on what DNS propagation is for the full picture.
  8. Disable your CDN and test. If everything else looks normal, the problem may sit with your content delivery network. Temporarily disable it and check whether the site loads. If it does, reconfigure the CDN settings — and check that your origin server's IP is correctly configured there. Our guide on what a CDN is explains how the edge and the origin fit together.
  9. Increase PHP limits only with evidence. If the logs show execution-time or memory exhaustion, raise the PHP max_execution_time and memory limits. Raising limits without confirming exhaustion only delays the real diagnosis.
  10. Contact your hosting provider. If the logs point at infrastructure you do not control, send your host the exact time, the affected URLs, and the log lines. A persistent 502 you cannot trace is the host's job, not a reason to keep guessing.

502 Errors on Nginx, Cloudflare, and WordPress: Where to Look First

The same 502 means different things on different stacks, because each layer occupies a different position in the chain. Identify who generated the response before you edit timeouts, plugins, or edge settings — a fix at the wrong layer hides the evidence without restoring service.

Nginx

Inspect the Nginx error log for the exact request time and upstream. Confirm that the configured protocol, address, port, or socket matches the running service, and test connectivity from the Nginx environment — not from an unrelated workstation. Do not raise every timeout before determining whether the service crashed, reset the connection, or returned invalid data.

Cloudflare

Identify the responder by comparing the error presentation with your edge and origin logs, and record the time, time zone, requested address, and any Cloudflare diagnostic identifier. A branded Cloudflare error page can reflect an origin-generated error, while a blank, unbranded response can originate inside Cloudflare itself — follow the documentation rather than guessing from the page design.

WordPress

WordPress does not generate every 502 shown in front of a WordPress site: a web server, host, CDN, or load balancer may be rejecting an invalid response from PHP or another application process. Check hosting, web-server, PHP, and application logs for the same request time, and review recent plugin, theme, PHP, and deployment changes after preserving the evidence.

How to Prevent 502 Bad Gateway Errors

Visitors cannot always prevent a 502, since it usually starts on the website's server — but you can reduce the chances of triggering one by keeping your browser up to date, clearing your cache and cookies regularly, and using a reliable internet connection. A simple reload clears most temporary glitches before they become a problem.

Owners can do far more. Choose a reliable hosting provider with good uptime, DDoS protection, and load balancing, and spread heavy traffic across multiple servers so no single one crashes. Keep servers and backend software updated, and always test updates and new plugins on a staging environment before applying them live. Improve backend performance with caching, compressed images, optimized database queries, and fewer resource-heavy plugins. Finally, set up automatic monitoring so a crashed service restarts immediately and log alerts flag unusual errors early — the fastest fix for a 502 is catching it before your visitors do.

Sources

  • AVG — "What is a 502 Bad Gateway error?" (avg.com/en/signal/502-bad-gateway, published December 18, 2025): definition, common causes, visitor steps, owner steps, and prevention — fetched in full this run.
  • Proxidize — "What Is a 502 Bad Gateway Error, and How Do You Fix It?" (proxidize.com/blog/error-code-502/): RFC 9110 definition, visitor sequence, owner diagnostic sequence, 502 vs 500/503/504 distinction, Nginx/Cloudflare/WordPress guidance — fetched in full this run.
  • Ranktracker — "502 Bad Gateway Error" (ranktracker.com/seo/glossary/502-bad-gateway/): visitor and owner step lists, common error-message variants — search result this run.
  • Go4Hosting — "How to Fix the 502 Bad Gateway Error?" (go4hosting.in/knowledgebase/hosting/how-to-fix-the-502-bad-gateway-error): step-by-step visitor fixes including DNS flush commands — search result this run.

Frequently Asked Questions

What does a 502 Bad Gateway error mean?

It means a server acting as a gateway or proxy received an invalid response from the server behind it. Your browser asked one server for a page, that server asked a second server for help, and the second server sent back something unusable or nothing at all — so the gateway shows a 502 instead of the page.

Is a 502 Bad Gateway error my fault?

Almost never. A 502 describes a failure between two servers, not a mistake in your request. The only visitor-side causes are a failing proxy or VPN, a stale cache, or a local DNS record — and the visitor checklist above tests all of them in a few minutes. If the error appears on every device and network, it is the website's problem.

How long does a 502 Bad Gateway error last?

There is no standard recovery period. A restarted process can recover in under a minute, while a wrong address or a bad deployment can fail indefinitely until someone fixes it. If a single reload after 30 seconds does not clear it, waiting is a legitimate answer — and reporting it to the site owner with the exact time helps more than reloading.

What is the difference between a 502 and a 504 error?

A 502 means the gateway got an invalid response from upstream; a 504 means the gateway waited too long for any response. A 502 is about a bad answer, a 504 is about no answer in time. A 500, by contrast, comes directly from the application that failed, and a 503 usually means the service is deliberately paused or overloaded.

Can clearing my cache fix a 502 Bad Gateway error?

Sometimes, if your browser holds a corrupt or outdated copy of the page — but it is not the default fix. Reload once first, check whether the site is down for everyone, and test another device. Clearing all cookies or reinstalling the browser rarely repairs the upstream path and can delete useful saved state, so keep cache-clearing as one step in the checklist, not the first resort.