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 (X) 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? 13 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.
2. Check the Site Status
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. There are also other tools that can help.
3. Try a Different Browser
You could try a different browser to rule that out as an issue. If you’re using Google Chrome, for example, try using Microsoft Edge.
In case the error goes away, it might be a good idea to delete and reinstall the browser you initially used.
4. Try in Incognito Mode
You can also access the site in Incognito mode. If the 502 bad gateway error doesn’t happen, the problem might be caused by a browser extension.
But how to identify the culprit extension? Try disabling them gradually, one after the other, checking if the website will open normally.
When this happens, you will have deleted the extension that was blocking your access.
5. Test on Another Device
If it looks like a problem on your end, you can try accessing the website on a different device.
Do the test: use your cell phone’s mobile data to access the page you want to see. If you succeed, restart your computer and other networking equipment, following the classic tip of unplugging your wireless router, waiting a moment, and plugging it back in.
That way you will understand if the error is related to your networking devices or something else.
6. 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:
- How to Force Refresh a Single Page for All Browsers
- How to Clear Browser Cache for Google Chrome
- How to Clear Browser Cache for Mozilla Firefox
- How to Clear Browser Cache for Safari
- How to Clear Browser Cache for Internet Explorer
- How to Clear Browser Cache for Microsoft Edge
- How to Clear Browser Cache for Opera
7. 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.
8. 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.
9. 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.
10. 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.
11. 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.
12. 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.
13. 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:
- Try Reloading the Page
- Check the Site Status
- Try a Different Browser
- Try in Incognito Mode
- Test on Another Device
- Clear Your Browser Cache
- Check for DNS Issues
- Check With Your Host
- Temporarily Disable CDN or Firewall
- Check Your Plugins and Themes
- Check Logs
- Restart PHP
- Check for PHP Timeout Issues
Nice article, would have liked to see recommendations for people hosting their own sites such as adding buffering, but understand that this is catered more towards people with managed hosting, that being said this article offers some good points on things those people can try.
Thanks Steven! Agreed, I’ll see if we can add some more tips to this.
On my website, 502 Bad Gateway is only caused when I use Cloudflare also Cloudflare causes more problems. Can you help me to solve them without disabling Cloudflare?
Hey Aqib!
Sometimes a 502 bad gateway error can be a Cloudflare problem itself, especially on the free plan. However, a more common cause is that you perhaps misconfigured Cloudflare or there is a conflict on your site. It could very well be due to your hosting provider having issues. We always recommend asking your host to see if they can help diagnose the issue.
I contacted my host and they said my DNS was pointing to Cloudflare so I had to change my nameserver back to the original rather than cloudflare. However removing my site from cloudflare hasn’t fixed the problem. I’ll wait 24hours to see if it resolves.
hello, I am having serious troubles, my hosting randomly moved to a new server.
Since I have changed the A record to the new server IP address, nothing works properly, resources are not loading from the wp backend , websites are sometimes scrambled sometimes fine, most of the time when I click on pages of my site I get the 502 error in the second pic chapter 5 in this article, and if I refresh the page it works.
I have spent 8 days chatting with the hosting support and they are not able to fix this.
do you know what it can be?
I have tried everything, disabling Cloudflare, reinstalling plugins, I have sent HAR files all over support teams, nothing works!
Hey Marco!
Sorry to hear about your trouble. If none of the above troubleshooting steps worked for you, my best recommendation would be to probably move to a better host. Here at Kinsta we utilize New Relic and can help pinpoint for clients where the issue is.
Hey, a lot of times my website gets an error 502. Please tell me how I can resolve this issue.
Hey Raju! Have you gone through all the troubleshooting steps above? We always recommend chatting with your hosting provider, as they should be able to help.
Thank you for the guidance..
Hello,
Have you tried going through the troubleshooting steps above in the post? If you’re a Kinsta client, you can open up a ticket with our support team. Thanks!
Error 522
Error 522 is an error code from Cloudflare’s proxy service. Please refer to this page here for more information on Cloudflare status codes.
502 Bad Gateway at Cloudflare (Variation 2)
I am having that issues, in the last week, UptimeRobot sending me mails 38 TIMES my site down, 5 minutes for each down, always 502