You click a link. Instead of a webpage, you get a white screen and a terse message: 502 Bad Gateway. No explanation, no useful context. Just a number, a label, and the vague feeling that something between you and the server went sideways.
A 502 bad gateway error means one server tried to talk to another and got garbage back. The gateway or proxy sitting in the middle received an invalid response from the upstream server, and it threw up its hands. Could be a five-second glitch. Could be a sign that something’s genuinely broken on the backend.
Either way, you’re not stuck. Most 502 errors resolve with quick client-side fixes like refreshing, clearing cache, or flushing DNS. When those don’t cut it, server-side troubleshooting will. This guide covers both, from the obvious stuff to the things you’d only know after staring at logs at 2 AM.
What Does 502 Bad Gateway Mean
The 502 status code is an HTTP response that says the server acting as a gateway or proxy received an invalid response from the upstream server it needed to fulfill the request. That’s the formal definition. In practice, it means two servers failed to have a conversation.
Here’s how the chain works. Your browser sends a request. It hits a reverse proxy or load balancer (the gateway). That gateway forwards the request to an origin server, an application server, or some other backend. If that backend sends back something the gateway can’t parse, or doesn’t respond at all, the gateway returns an HTTP 502 error to your browser.
The bad gateway meaning is straightforward: the middleman got a bad answer. The tricky part is figuring out which link in the chain broke.
What Causes a 502 Bad Gateway Error
A 502 bad gateway error sits at the intersection of a dozen potential failures. The root cause can be anything that disrupts communication between the gateway and the upstream server. Here’s what usually goes wrong:
Server overload. The upstream server is drowning in requests. It can’t respond before the gateway’s timeout threshold, so the gateway gives up and hands you a 502. This is the most common cause during traffic spikes, product launches, or a front-page Reddit link.
Network connectivity issues. Packet loss, routing failures, or flaky connections between data centers. The gateway sends a request, the packets vanish into the void, and you get a 502 error code.
Server downtime. The backend is offline. Maintenance, a crash, a bad deploy that took the process down. The gateway reaches out and nobody’s home.
Firewall restrictions. Overzealous firewall rules blocking traffic between servers. The gateway’s request gets dropped before it reaches the backend.
DNS problems. The gateway can’t resolve the upstream hostname. Bad DNS records, expired entries, or an unresponsive DNS server all cause this.
Proxy or gateway misconfiguration. Wrong upstream address, incorrect port, busted config syntax. A single typo in your Nginx conf can produce a steady stream of 502 bad gateway nginx errors.
Application errors. The backend app crashes mid-request, returns malformed headers, or sends an incomplete response. The gateway can’t make sense of it.
CDN issues. Your CDN edge servers can’t reach your origin. Cloudflare, Fastly, or whatever sits in front of your stack loses the connection and returns a 502.
Database connection problems. The app server connects fine, tries to query the database, and the database connection pool is exhausted or the DB is down. The app hangs, times out, and the gateway returns 502.
PHP or script timeouts. A PHP process exceeds max_execution_time. The process dies, the web server gets no response, and the gateway flags it as a bad gateway error.
The frustrating thing: all of these produce the same error from the user’s perspective. That’s why fixing a 502 means testing systematically, starting from the simplest explanation and working inward.
How to Fix the 502 Bad Gateway Error
Start with the cheap, fast fixes. If those don’t work, move to server-side troubleshooting. Each step below takes a few minutes at most.
Refresh the Page
The majority of 502 bad gateway errors are transient. A server hiccupped, a connection timed out, and three seconds later everything’s fine again. Hit refresh before you do anything else.
On Windows: F5 or Ctrl + F5 for a hard refresh. On Mac: Cmd + R. Ctrl + F5 bypasses the cache entirely, which is what you want here. If the page loads, you’re done. Move on with your life.
Check if the Website Is Down
Before you start troubleshooting your own setup, figure out whether the problem is on the server’s end. Use a website down checker like Down for Everyone or Just Me (downforeveryoneorjustme.com) or IsItDownRightNow. Punch in the URL and see if the site is down for the world or just for you.
If it’s down for everyone, the issue is server-side and there’s nothing you can do except wait. If it’s just you, the problem is local: your network, your DNS, your browser, or your ISP.
Clear Your Browser Cache
Your browser stores copies of pages, scripts, and assets to speed things up. When those cached files go stale or get corrupted, they can cause persistent 502 errors even after the server has recovered. Clearing the browser cache forces your browser to fetch everything fresh.
In Chrome: Settings > Privacy and Security > Delete Browsing Data. Select cached images and files, pick a time range, and clear. In Firefox, it’s under Settings > Privacy & Security > Cookies and Site Data > Clear Data.
One caveat: clearing cache can log you out of sites and remove saved preferences. Export your bookmarks first if you’re worried about losing anything.
Try Incognito or Private Mode
Open the site in an incognito window. Incognito mode disables extensions and ignores your existing cache and cookies. If the page loads fine there, you’ve narrowed the problem: it’s either a browser extension or corrupted local data.
Start disabling extensions one at a time. Ad blockers are the usual suspect. They intercept requests and sometimes mangle the connection enough to trigger a 502 bad gateway error in Chrome or any other browser.
If disabling extensions doesn’t help, try a different browser entirely. Page works in Firefox but not Chrome? Reinstall Chrome. It’s faster than debugging whatever state it got itself into.
Flush Your DNS Cache
DNS translates domain names into IP addresses. Your OS caches these lookups. If a cached entry points to a dead IP or an IP that’s changed, your requests go nowhere and you’ll see a 502 error.
To flush your DNS cache:
Windows: Open Command Prompt as admin and run ipconfig /flushdns
Mac: Open Terminal and run sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
Linux: Run sudo systemd-resolve --flush-caches or restart your DNS service.
While you’re at it, consider switching to a public DNS like Google (8.8.8.8 / 8.8.4.4) or Cloudflare (1.1.1.1). ISP DNS servers go flaky more often than they should.
Test on a Different Device
If you’ve tried everything above and the 502 persists, test on a different device connected to a different network. Pull up the site on your phone using mobile data, not Wi-Fi. Try a laptop at a coffee shop.
This isolates the variable. If the error follows you across devices and networks, the problem is almost certainly server-side. If it’s only on your machine or your network, restart your router, check your local firewall settings, and look for anything intercepting your traffic.
Review Server Error Logs
This is where you shift from user-side fixes to server-side investigation. The server error log tells you exactly what went wrong, or at least gives you a timestamp and a stack trace to work with.
Check your web server’s error log. For Nginx, that’s typically /var/log/nginx/error.log. For Apache, look at /var/log/apache2/error.log or /var/log/httpd/error_log. If you’re running WordPress, you can enable debug logging by adding these lines to wp-config.php:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );Errors will land in wp-content/debug.log. Look for fatal errors, connection timeouts, or out-of-memory warnings right around the time the 502 started. That’s your lead.
Disable Plugins and Themes
Faulty WordPress plugins are one of the most common causes of 502 bad gateway errors on WordPress sites. A poorly coded plugin can consume all available PHP workers, crash mid-execution, or block outgoing server communication.
If you can access your WordPress dashboard, go to Plugins > Installed Plugins, select all, and choose Deactivate from the Bulk Actions dropdown. Then reactivate them one by one, refreshing the site after each. When the 502 comes back, you’ve found the culprit.
Can’t access the dashboard? SSH or FTP into the server, navigate to wp-content/, and rename the plugins folder to something like plugins-disabled. This deactivates everything at once. Check if the site loads. If it does, rename the folder back and start isolating.
Themes work the same way. Switch to a default WordPress theme like Twenty Twenty-Five. If the error vanishes, your custom theme has a problem.
Check Your CDN Configuration
If you’re running a CDN like Cloudflare, it sits between your visitors and your origin server. When the CDN can’t reach your origin, it returns a 502 bad gateway error. But Cloudflare 502 errors come in two flavors, and the difference matters.
If the error page has Cloudflare branding with a plain white background, the problem is on Cloudflare’s end. Check cloudflarestatus.com and wait it out, or contact their support.
If the error page has Cloudflare branding with a gray/orange header, the problem is your origin server. Your hosting is down, your server is overloaded, or your origin IP has changed. In that case, troubleshoot your server directly.
You can temporarily bypass Cloudflare by pausing it in the dashboard or updating your hosts file to point directly at your origin IP. This helps confirm whether the CDN is the issue or just the messenger.
Increase PHP Timeout Limits
PHP processes have a built-in kill switch: max_execution_time. If a script runs longer than this limit (typically 30 to 300 seconds), PHP terminates it. The web server gets no response, the gateway gets nothing, and you see a 502.
To check and adjust these values, edit your php.ini file:
max_execution_time = 300
max_input_time = 300You can also set these in your .htaccess file for Apache or in your PHP-FPM pool configuration. After changing values, restart PHP-FPM or your web server for the changes to take effect.
If scripts are consistently timing out, don’t just keep raising the limit. That’s treating the symptom. Find out why the script is slow: bad database queries, unoptimized loops, external API calls that hang. Fix the root cause.
502 Bad Gateway Error Variations
The 502 error wears different masks depending on your browser, server software, and CDN. Don’t let the wording fool you. These all mean the same thing:
Generic variations: 502 Error, Error 502, HTTP 502, HTTP Error 502 Bad Gateway, 502 Server Error.
Technical variations: 502 Proxy Error, 502 Bad Gateway Nginx, 502 Web Server Received an Invalid Response.
Overload messages: 502 Service Temporarily Overloaded.
Blank screen: Some servers return a completely white page with no error message at all. Check the HTTP status code in your browser’s developer tools (F12 > Network tab) to confirm it’s a 502.
Chrome, GitLab, and Twitter/X each display their own styled error pages. The error code 502 is always the same underneath.
Is a 502 Bad Gateway Error Permanent
Almost never. The vast majority of 502 bad gateway errors are temporary. A server restarted, a connection blipped, a deploy went out and bounced the workers. Give it a minute, refresh, and the problem’s gone.
Persistent 502 errors, ones that last hours or keep recurring, point to a real infrastructure problem: an overloaded server that needs scaling, a misconfigured proxy, a dying backend process, or a hosting provider that’s overselling resources.
Does 502 Bad Gateway Affect SEO
Short answer: yes, if it lasts long enough. Google’s crawler treats a 502 like any server error. A brief one during a crawl? The bot retries later and moves on. But if Googlebot keeps hitting 502s over days, your pages can drop from the index. Rankings suffer. Organic traffic tanks.
Monitor your site with Google Search Console. The Coverage report shows server errors that Googlebot encountered. If you see a spike in 5xx errors, fix the underlying cause fast. Every hour of downtime is hours of crawl budget wasted and trust eroded.
502 Bad Gateway Errors FAQ
What Is a 502 Bad Gateway Error
A 502 bad gateway error is an HTTP status code indicating that a server acting as a gateway or proxy received an invalid response from the upstream server. It’s a server-side issue, meaning the problem is between the servers, not on your device.
What Does Bad Gateway Mean
Bad gateway means the intermediary server (the gateway) couldn’t get a valid response from the server behind it. The word “gateway” refers to any server that relays requests to another server. When that relay fails, you get the bad gateway error.
How Do I Fix a Bad Gateway Error
Start with client-side fixes: refresh the page, clear your browser cache, flush DNS, and try incognito mode. If those don’t work, check server error logs, disable plugins, review your CDN settings, and increase PHP timeout limits. Work from simple to complex.
Why Do I Keep Getting 502 Bad Gateway
Recurring 502 errors suggest a persistent server problem. Common culprits include an overloaded server that needs more resources, a misconfigured reverse proxy, a faulty plugin that keeps crashing, or a hosting environment that can’t handle your traffic levels.
What Is Error 502 in Chrome
Chrome displays its own styled 502 error page when it receives a 502 status code from the server. The error code 502 in Chrome is identical to a 502 in any other browser. Chrome just adds a suggestion to check your connection and try again, which is decent advice for the first attempt.