AI Overview
A 502 Bad Gateway error means a proxy or gateway, like nginx or Cloudflare, got an invalid response from the server behind it. It's rarely the visitor's fault. Fix it by checking the app server is running, reading the proxy error log and fixing the cause.
Key takeaways
- A 502 Bad Gateway means a proxy such as nginx or Cloudflare received an invalid response, or none, from the server behind it.
- The cause is usually one layer further in: a crashed or stopped app server, exhausted workers, a wrong socket or a blocked CDN.
- Site owners should confirm the scope, check the app is running and read the proxy error log, which names the exact failure.
- A Cloudflare-branded 502 comes from your origin server, while an unbranded blank 502 comes from Cloudflare itself.
- Google slows crawling on 5xx errors and eventually drops URLs that keep failing, so long or repeated 502s can cost rankings.
Summarize with AI
Opens the assistant in a new tab with a link to this post.
On this page
A 502 Bad Gateway error is one of the most frustrating errors on the web, for visitors and site owners alike. The page doesn't load, the message gives almost no detail, and it often comes and goes on its own. For a visitor, it's an annoyance. For the person who runs the site, it's a sign that something between the web and the application has broken, and every minute it lasts costs visits, sales and crawl time.
This guide explains what a 502 error actually means, the forms it takes on nginx, Apache, Cloudflare and WordPress, what usually causes it, and how to fix it step by step. It also covers how 502s affect SEO and how to find out about one before your visitors do.
What does 502 Bad Gateway mean?#
A 502 Bad Gateway is an HTTP status code. The HTTP standard (RFC 9110) defines it as a response from a server that, while acting as a gateway or proxy, received an invalid response from the server behind it.
Most modern websites aren't a single server. A request usually passes through several layers:
- A CDN or firewall, such as Cloudflare.
- A reverse proxy or load balancer, such as nginx, Apache, HAProxy or a cloud load balancer.
- The application itself, such as PHP-FPM running WordPress, a Node.js app or a Python app.
A 502 means one of the front layers was working fine, but when it passed the request back to the layer behind it, it got nothing usable: the connection was refused, closed early, or answered with something that wasn't valid HTTP. The front server then tells your browser, in effect, "I'm fine, but the server I depend on isn't."
That's the key to fixing it. A 502 is almost never caused by the visitor and almost never caused by the server that displays it. The real problem is one layer further in.
What a 502 error looks like#
The wording depends on which server generated it:
| Message | Usually generated by |
|---|---|
| 502 Bad Gateway, with "nginx" underneath | nginx as a reverse proxy |
| Proxy Error: The proxy server received an invalid response from an upstream server | Apache with mod_proxy |
| Error 502 Bad gateway, Cloudflare-branded page | Cloudflare, passing on a 502 from your origin |
| A blank 502 page without branding | Cloudflare itself |
| HTTP Error 502, 502 Service Temporarily Overloaded | Hosting platforms and load balancers |
| 502 Server Error: The server encountered a temporary error | Google Cloud load balancers |
The Cloudflare distinction is useful. According to Cloudflare's documentation, a Cloudflare-branded 502 or 504 page means your origin server returned the error, so the fix is on your server or with your host. An unbranded blank 502 comes from Cloudflare itself, and can be caused by things like broken gzip compression at the origin.
502 vs 500 vs 503 vs 504#
These four server errors are easy to mix up. Each points to a different place to look.
| Status | Meaning | Where the problem usually is |
|---|---|---|
| 500 Internal Server Error | The application hit an error it couldn't handle | Your code, a plugin, a config file. See our 500 Internal Server Error guide |
| 502 Bad Gateway | A proxy got an invalid response, or no response, from the server behind it | The upstream app server crashed, isn't running or refused the connection |
| 503 Service Unavailable | The server is temporarily unable to handle the request | Overload or planned maintenance |
| 504 Gateway Timeout | A proxy waited for the server behind it and gave up | The upstream app is running but too slow |
A quick rule: a 502 usually means the upstream is broken or missing, and a 504 usually means it's alive but slow.
Common causes of a 502 Bad Gateway#
| Cause | What's happening |
|---|---|
| The application server is down | PHP-FPM, Node, Gunicorn or a container stopped or crashed |
| The app ran out of workers or memory | Traffic spikes, slow database queries or a memory leak exhaust the worker pool |
| Wrong upstream address | nginx points to a socket, port or IP that no longer exists after an update |
| Response headers too large | nginx rejects an upstream response with oversized headers (large cookies are a common trigger) |
| A firewall blocks the proxy | Security rules at the origin block your CDN's or load balancer's IP addresses |
| DNS changed | The proxy or CDN still points at an old server IP after a migration |
| A deploy or restart is in progress | The app is briefly unavailable while it restarts |
| A plugin or theme crashes PHP | On WordPress, a fatal error kills the PHP worker mid-response |
Try it on your site · free
Check your own page's meta tags
Title, description, canonical and robots - including an accidental noindex - in a few seconds.
How to fix a 502 Bad Gateway as a visitor#
If you're only trying to view a site, your options are limited, because the fault is on the site's servers. Still, try these:
- Reload the page after 30 to 60 seconds. Many 502s happen during a restart and clear by themselves.
- Try another browser or a private window to rule out a stale cached error page.
- Clear your browser cache for that site.
- Check whether the site is down for everyone. Our guide on how to check if a website is down lists quick ways to test from outside your network.
- Turn off your VPN or proxy. Occasionally the "gateway" that failed is your own.
If it's down for everyone, the only thing left to do is let the site owner know, or come back later.
How to fix a 502 Bad Gateway on your website#
If it's your site, work from the outside in. The aim is to find which layer stopped answering.
1. Confirm the scope#
Is it every page or just some? Every visitor or one region? A 502 on every URL points to a dead app server. A 502 on a few heavy pages points to timeouts, memory or one broken route. A quick way to check many URLs at once is the free Bulk URL Status Checker, which returns the status code for up to 20 URLs.
2. Check the upstream application is running#
On a server you manage, check the service status:
sudo systemctl status php8.3-fpm
sudo systemctl status nginx
Replace the PHP version with yours, or check your Node, Python or container process instead. If the app isn't running, start it and read its logs to find out why it stopped:
sudo journalctl -u php8.3-fpm --since "1 hour ago"
On managed hosting, check your host's status page and dashboard, and open a ticket if the app layer is down.
3. Read the proxy's error log#
The proxy that returned the 502 records why. On nginx:
sudo tail -n 50 /var/log/nginx/error.log
The message tells you where to look next:
| nginx log message | What it means |
|---|---|
connect() to unix:/run/php/...sock failed (2: No such file or directory) | The PHP-FPM socket doesn't exist: PHP-FPM is stopped or the socket path in nginx is wrong |
connect() failed (111: Connection refused) | Nothing is listening on the upstream port |
upstream prematurely closed connection | The app crashed or was killed while answering |
upstream sent too big header | Response headers exceeded nginx's buffer |
no live upstreams | Every server in the upstream pool is marked as failed |
4. Fix the specific cause#
- PHP-FPM or app crashed: restart it, then find the trigger in its logs. Check memory with
free -mand look for the out-of-memory killer indmesg. - Worker pool exhausted: raise
pm.max_childrenin PHP-FPM only if the server has memory to spare, and fix the slow queries or endpoints that tie workers up. - Socket or port mismatch: make sure
fastcgi_passorproxy_passin nginx matches the socket or port the app actually listens on. PHP upgrades often change the socket name. - Headers too large: increase
fastcgi_buffer_sizeandfastcgi_buffers(orproxy_buffer_sizeandproxy_buffers), or reduce cookie size. - Firewall blocking your CDN: allow your CDN's published IP ranges at the origin firewall and in security plugins.
- DNS pointing to an old server: check that the A record in your DNS (and the origin address in your CDN) points to the current server IP.
Reload nginx after any config change with sudo nginx -t && sudo systemctl reload nginx. The -t test stops you from reloading a broken config.
5. Fixes specific to Cloudflare#
- Branded 502: the error came from your origin. Fix it there, using the steps above, or contact your host.
- Unbranded 502: try disabling compression at the origin to rule out broken gzip responses, as Cloudflare's documentation suggests, and check Cloudflare's status page.
- Pause Cloudflare briefly (or test with your origin IP directly) to see whether the origin works without the proxy in front.
6. Fixes specific to WordPress#
- Turn on debug logging by adding
define('WP_DEBUG', true);anddefine('WP_DEBUG_LOG', true);towp-config.php, then readwp-content/debug.log. - Disable all plugins by renaming the
wp-content/pluginsfolder over SFTP. If the 502 stops, rename it back and reactivate plugins one at a time. - Switch to a default theme to rule out the theme.
- Raise the PHP memory limit if the logs show memory exhaustion.
- If the error started right after an update, roll that update back. Our guide to safely updating WordPress plugins explains how to avoid this next time.
Does a 502 Bad Gateway hurt SEO?#
A short 502 won't hurt your rankings. A long or repeated one can.
Google's documentation on HTTP status codes says that 5xx server errors prompt Google's crawlers to temporarily slow down crawling. For Google Search, already indexed URLs are kept in the index at first, but are eventually dropped if they keep returning a server error. Any content Google receives with a 5xx status is ignored, and once the server starts responding with 2xx codes again, Google gradually increases the crawl rate.
In practice, that means:
- A few minutes of 502s during a restart is fine.
- Hours of 502s slow down how quickly Google picks up your new and changed pages.
- Days of 502s on important pages put them at risk of dropping out of search.
- Intermittent 502s on a handful of pages can go unnoticed for weeks while they quietly lose crawl activity.
If you need to take a site offline on purpose, a 503 is the right signal for a temporary outage, not a 502. Check Search Console's Crawl Stats report (Settings > Crawl stats) for server connectivity problems and 5xx responses over time.
How to catch 502 errors before your visitors do#
The worst way to find out about a 502 is from a customer email, or from a traffic drop a week later. Intermittent 502s are especially easy to miss, because by the time you check, the site loads fine.
MyKavo watches for them in two ways:
- Site health checks every 5 minutes. MyKavo requests each monitored website's homepage every 5 minutes. Any 5xx status, including a 502, counts as down. After two failed checks in a row, so a single blip never alerts you, MyKavo sends a down alert by email and to Slack, Discord or a webhook if you've connected one, followed by a recovery alert when the site is back.
- Page scans against your baseline. On every scan, if a monitored page that used to load now returns a 4xx or 5xx error, MyKavo raises it as a critical change with the old and new status side by side. Internal links that start returning server errors are grouped into a single broken links alert rather than dozens of separate emails.
Frequently asked questions
What does 502 Bad Gateway mean?
It means a server acting as a gateway or proxy, such as nginx or Cloudflare, received an invalid response or no response from the server behind it. The problem is usually the upstream application server.
Is a 502 Bad Gateway my fault or the website's?
Almost always the website's. Reloading, clearing your cache or turning off a VPN can help in rare cases, but most 502s need the site owner or host to fix the server.
How do I fix a 502 Bad Gateway on nginx?
Check that the upstream app, such as PHP-FPM, is running, read /var/log/nginx/error.log for the reason, confirm the socket or port in proxy_pass or fastcgi_pass is correct, and fix memory or buffer limits.
What is the difference between a 502 and a 504 error?
A 502 means the proxy got an invalid response or no response, usually because the upstream crashed or refused the connection. A 504 means the upstream is running but didn't answer in time.
Does a 502 error affect SEO?
Brief 502s don't. Google slows crawling when it sees 5xx errors, and URLs that keep returning server errors are eventually dropped from the index, so long or repeated 502s can cost rankings.
How can I monitor my website for 502 errors?
Use outside monitoring that checks your site every few minutes and alerts you on 5xx responses. MyKavo checks homepages every 5 minutes and flags monitored pages that start returning errors.
The bottom line#
A 502 Bad Gateway means a proxy in front of your site couldn't get a valid answer from the server behind it. Visitors can only reload and wait. Site owners should confirm the scope, check that the app server is running, read the proxy's error log, and fix the specific cause, whether that's a crashed PHP-FPM, a wrong socket, a firewall blocking the CDN or a plugin killing PHP. Short 502s are harmless for SEO, but long or repeated ones slow crawling and can drop pages from Google.
Check your most important URLs right now with the free Bulk URL Status Checker, then start free with MyKavo to get alerted within minutes when your site starts returning 502s, instead of hearing about it from your customers.
Get alerted when your site breaks. Free, no card.
Start free