1. Refresh the page: The first and simplest thing to try when you encounter a 502 Bad Gateway error is to simply refresh the page. This can often resolve the issue.
2. Check your internet connection: If your internet connection is slow or unreliable, it can cause a 502 Bad Gateway error. Try restarting your router or modem, or check with your ISP to see if there are any issues with your connection.
3. Clear your browser’s cache: Clearing your browser’s cache can help resolve a 502 Bad Gateway error. To do this, open your browser’s settings and look for the “Clear Cache” or “Clear Browsing Data” option.
4. Check for server maintenance: If the website you’re trying to access is undergoing maintenance, it can cause a 502 Bad Gateway error. Check the website’s status page or contact the website’s support team to see if the issue is being addressed.
5. Check your DNS settings: If your DNS settings are incorrect, it can cause a 502 Bad Gateway error. Try changing your DNS settings to Google’s public DNS or OpenDNS.
6. Disable browser extensions: Browser extensions can sometimes interfere with webpages and cause a 502 Bad Gateway error. Try disabling any extensions you have installed and see if that resolves the issue.
7. Contact your hosting provider: If you’re hosting your own website, contact your hosting provider to see if they can help resolve the issue.
8. Check for server errors: If the website you’re trying to access is hosted on a server, check the server’s error logs to see if there are any errors that could be causing the 502 Bad Gateway error.
9. Try a different browser: If none of the above solutions work, try accessing the website in a different browser. This can help identify if the issue is browser-specific.
When it comes to websites, there are a lot of different errors that can be downright frustrating and confusing. A few that come to mind are the white screen of death or the frightening error establishing a database connection.
But an even more popular one is the 502 bad gateway error. Why? Because this regularly happens around the entire web, not only to WordPress sites, but even popular services such as Gmail, Twitter, and Cloudflare.
Read more below about what causes this error and some solutions on how to quickly resolve it.
What is a 502 Bad Gateway Error?
The 502 Bad Gateway error specifically means that the server received an invalid response from an inbound server.
The Internet Engineering Task Force (IETF) defines the 502 Bad Gateway error as:
The 502 (Bad Gateway) status code indicates that 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.
Every time you visit a website your browser sends a request to a web server. The web server receives and processes the request, and then sends back the requested resources along with an HTTP header and HTTP status code. Typically an HTTP status code isn’t seen unless something goes wrong. It’s basically the servers way of notifying you that something has gone wrong, along with the code on how to diagnose it.
Error Code | 502 Bad Gateway Error |
Error Type | Server-side error |
Error Variations | “502 Bad Gateway” “Error 502” “HTTP Error 502 – Bad Gateway” “502 Service Temporarily Overloaded” “502 Proxy Error” A blank white screen “502 Server Error: The server encountered a temporary error and could not complete your request” “HTTP 502” Temporary Error (502) 502. That’s an error 502 bad gateway Cloudflare Bad Gateway: The proxy server received an invalid response from an upstream server |
Error Causes | Server overload Browser issues DNS issues Web host issues Firewall blocks Plugins and themes errors |
There are many different types of 500 status error codes (500, 501, 502, 503, 504, 508, 520, etc.) which all have slightly different meanings.
These indicate that the request was accepted, but the server prevented the fulfillment of the request.
Check Out Our Video Guide to Fixing Different Types of 500 Errors
What Causes the 502 Bad Gateway Error?
The most likely causes of the 502 Bad Gateway are:
- Server overload: the server ran out of resources and crashed, triggering an HTTP error 502. The possible reasons for this could be an unexpected spike in traffic or low memory.
- Browser problems: your browser version is outdated or maybe there are corrupted files in your browser cache.
- Firewall blocks: your firewall might be detecting false threats and blocking internet providers or IP addresses.
502 Bad Gateway Error Variations
Due to the various browsers, web servers, and operating systems, a 502 bad gateway error can present itself in a number of different ways. But they all have the same meaning. Below are just a couple of the many different variations you might see on the web:
- “502 Bad Gateway”
- “Error 502”
- “HTTP Error 502 – Bad Gateway”
- “502 Service Temporarily Overloaded”
- “502 Proxy Error”
- A blank white screen
- “502 Server Error: The server encountered a temporary error and could not complete your request”
- “HTTP 502”
- Temporary Error (502)
- 502. That’s an error
- 502 bad gateway Cloudflare
- Bad Gateway: The proxy server received an invalid response from an upstream server
Another variation you might see is a “502 server error.”
And here is yet another variation. “502 – Web server received an invalid response while acting as a gateway or proxy server. There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server.”
Other services such as Twitter might even show a completely different message for a 502 Bad Gateway error, such as “Twitter is over capacity.” This definitely looks a little more user-friendly.
And here is a snapshot of how Google displays it. “502. That’s an error. The server encountered a temporary error and could not complete your request. Please try again in 30 seconds. That’s all we know.”
502 Errors Impact on SEO
Unlike 503 errors, which are used for WordPress maintenance mode and tell Google to check back at a later time, a 502 error can have a negative impact on SEO if not fixed right away. If your site is only down for say 10 minutes and it’s being crawled consistently a lot of times the crawler will simply get the page delivered from cache. Or Google might not even have a chance to re-crawl it before it’s back up. In this scenario, you’re completely fine.
However, if the site is down for an extended period of time, say 6+ hours, then Google might see the 502 error as a site level issue that needs to be addressed. This could impact your rankings. If you’re worried about repeat 502 errors you should figure out why they are happening to begin with. Some of the solutions below can help.
How to Fix the 502 Bad Gateway Error? 9 Methods
A 502 bad gateway error is typically a problem with the network/server, however, it can also be a client-side issue. So we’ll dive into a little of both. Check out these common ways to fix the 502 bad gateway error to get back up and running.
1. Try Reloading the Page
One of the easiest and first things you should try when encountering a 502 bad gateway error is to simply wait a minute or so and reload the page (F5 or Ctrl + F5). It could be that the host or server is simply overloaded and the site will come right back. While you’re waiting, you could also quickly try a different browser to rule that out as an issue.
Another thing you can do is to paste the website into downforeveryoneorjustme.com. This website will tell you if the site is down or if it’s a problem on your side.
2. Clear Your Browser Cache
Whenever you encounter issues like these it can be good to clear your browser cache. Below are instructions on how to do it in the various browsers:
3. Check for DNS Issues
A 502 gateway error could also be because of a DNS issue, such as the domain is not resolving to the correct IP, or the DNS server is not responding. If you have just migrated your site to a new host, is it important to wait for things to fully propagate, which can take up to 24 hours in some cases. This depends upon the TTL value of your DNS records.
You can also try flushing your local DNS cache. This is similar to clearing your browser cache.
In Windows simply open up Command Prompt and enter the following:
ipconfig /flushdns
You should see a “Successfully flushed the DNS resolver Cache” if it worked.
For macOS users, you can enter the following in the terminal:
dscacheutil -flushcache
Note: There is no success message on Macs.
And lastly, you could temporarily change your DNS servers. By default, DNS servers are automatically assigned by your ISP. But you could try temporarily changing these to a public DNS server, such as Googles. In fact, some prefer to use Google’s public DNS long-term. If you have a premium DNS propagation usually is a lot faster.
4. Check With Your Host
The primary reason we typically see a 502 bad gateway error is due to an issue with the web host. Sometimes a query, script, or request will take too long and so it is canceled or killed by the server. A lot of hosts, especially shared hosts implement what they call a “kill script.” Basically what this does is it will terminate a request after a certain period of time so that it doesn’t take a site down or impact other users. If you do a Twitter search for “bad gateway” you can see thousands of tweets happening every day alerting their hosting company of the problem.
One reason you might want to consider moving to a host like Kinsta is that our platform runs in an isolated software container that contains all of the software resources required to run the site (Linux, NGINX, PHP, MySQL). This means that the software that runs each site is 100% private and is not shared, even between your own sites. This greatly reduces the chance of seeing a 502 bad gateway error. We aren’t running aggressive kill scripts like some shared hosts are. And even if one of your sites does happen to go down, it won’t impact your other sites.
Another reason you could see a 502 gateway error with your host is also due to the fact that the server is simply not reachable, either because it is down or there is no connectivity. In this case, it is recommended to check your host’s status page or open a support ticket.
5. Temporarily Disable CDN or Firewall
It could also be an issue with your content delivery network (CDN) or firewall. If you are using a 3rd-party CDN provider an easy way to troubleshoot this is to simply disable your CDN temporarily. For example, we are big fans of the free CDN enabler plugin. If you are using that, you can simply deactivate the plugin and then test your site.
Wp-admin not working? Simply log in to your site via SFTP and rename the plugin’s folder to cdn-enabler_old. This will temporarily disable the CDN connection. The same goes for WP Rocket or any other plugin you might have hooked up to your CDN.
This can also occur sometimes with providers that provide DDoS protection and mitigation or fully proxy services like Cloudflare, as they have extra firewalls in-between. We have noticed that this happens once in a while on the Cloudflare free plan. Unfortunately, since Cloudflare is a fully proxy service, there is no quick way to simply disable it.
However, before you go blaming Cloudflare, it is important to know that there are two different types of 502 bad gateway errors variations with Cloudflare as seen below:
502 Bad Gateway at Cloudflare (Variation 1)
If you see the following screen, this is actually a problem on Cloudflare’s end, in which case you should reach out to them for support. You can also check Cloudflare’s status page to see if they’re currently experiencing an outage.
502 Bad Gateway at Cloudflare (Variation 2)
If you see the following screen, this is a problem with your host.
GoDaddy Firewall
Here is another example with of an HTTP 502 error and GoDaddy’s firewall. The issue is actually with the origin server (the hosting provider) due to a timeout, not the firewall itself.
6. Check Your Plugins and Themes
A lot of times the reason for scripts and queries being canceled by the server is due to bad code on your site, possibly from a 3rd party plugin or theme. We have also seen a lot of misconfigured caching plugins generate 502 errors. A few ways you can troubleshoot this is by deactivating all your plugins. Remember, you won’t lose any data if you simply deactivate a plugin.
If you can still access your admin, a quick way to do this is to browse to “Plugins” and select “Deactivate” from the bulk actions menu. This will disable all of your plugins. If this fixes the issue you’ll need to find the culprit. Start activating them one by one, reloading the site after each activation. When you see the 502 gateway error return, you’ve found the misbehaving plugin. You can then reach out to the plugin developer for help or post a support ticket in the WordPress repository.
If you can’t access your admin you can FTP into your server and rename your plugins folder to something like plugins_old. Then check your site again. If it works, then you will need to test each plugin one by one. Rename your plugin folder back to “plugins” and then rename each plugin folder inside of if it, one by one, until you find it.
Always makes sure your plugins, themes, and WordPress core are up to date. And check to ensure you are running a supported version of PHP. You can always reach out to your host for assistance. We use Kinsta APM and other troubleshooting methods here at Kinsta to help clients narrow down what plugin, query, or script might be causing the error. You can also use your own custom New Relic key if you have your own license.
If it turns out to be an efficient query or bad code in a plugin, you might need to bring in a WordPress developer to fix the issue.
7. Check Logs
You should also take advantage of your error logs. If you are a Kinsta client, you can easily see errors in the log viewer in the MyKinsta dashboard. This can help you quickly narrow down the issue, especially if it’s resulting from a plugin on your site.
If your host doesn’t have a logging tool, you can also add the following code to your wp-config.php file to enable logging:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
If you need more help on how to enable WordPress debugging mode here is a full step by step tutorial.
The logs are typically located in the /wp-content directory. Others, like here at Kinsta might have a dedicated folder called “logs”.
You can also check the log files in Apache and NGINX, which are commonly located here:
- Apache: /var/log/apache2/error.log
- NGINX: /var/log/nginx/error.log
If you are a Kinsta client you can also take advantage of our analytics tool to get a breakdown of the total number of 502 errors and see how often and when they are occurring. This can help you troubleshoot if this is an ongoing issue, or perhaps something that has resolved itself.
8. Restart PHP
Finally, you can also try restarting PHP. If you’re a Kinsta client, you can easily restart PHP from the tools menu within the MyKinsta dashboard. If your host doesn’t provide this, you can always open up a support ticket and ask them restart PHP.
9. Check for PHP Timeout Issues
PHP timeouts occur if a single PHP process runs for longer than the max_execution_time
or max_input_time
set in the PHP configuration on your server. This is a common occurrence if you’re doing big WordPress imports. When this happens a 502 server error is usually displayed. If you run into a PHP timeout these values may need to be elevated.
You can check with your current host about what values are set on your server and if they can be increased. On the Kinsta platform, these values are set to 300 seconds (5 minutes) by default. The maximum PHP timeout values available on our platform are based on your current hosting plan.
Summary
As you can see there are quite a few things you can do to troubleshoot and fix a 502 gateway error on your site. Typically this is not on the client-side, but rather an issue with your host. Third-party plugins and themes with bad code or unoptimized queries are also things to watch out for.
Was there anything we missed? Perhaps you have another tip on troubleshooting 502 gateway errors. If so, let us know below in the comments.
FAQ
What Is a 502 Bad Gateway Error?
The 502 Bad Gateway error indicates that one server on the internet received an invalid response from another server. It’s a generic error alerting you that there’s something wrong with a website’s server communication.
What Causes the 502 Error?
The 502 bad gateway error is typically caused by issues related to the network/server, however, it can also be caused by client-side issues.
How Do You Fix the 502 Bad Gateway Error?
There are a number of things you can try when attempting to fix the 502 Bad Gateway Error:
Get all your applications, databases and WordPress sites online and under one roof. Our feature-packed, high-performance cloud platform includes:
- Easy setup and management in the MyKinsta dashboard
- 24/7 expert support
- The best Google Cloud Platform hardware and network, powered by Kubernetes for maximum scalability
- An enterprise-level Cloudflare integration for speed and security
- Global audience reach with up to 35 data centers and 275 PoPs worldwide
Get started with a free trial of our Application Hosting or Database Hosting. Explore our plans or talk to sales to find your best fit.