How To Fix a 502 Bad Gateway Error (2024)

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 deathor the frighteningerror 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 andHTTP 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 Code502 Bad Gateway Error
Error TypeServer-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 CausesServer 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:

  1. 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.
  2. Browser problems: your browser version is outdated or maybe there are corrupted files in your browser cache.
  3. Firewall blocks: your firewall might be detecting false threats and blocking internet providers or IP addresses.

502 Bad Gateway Error Variations

How To Fix a 502 Bad Gateway Error (1)

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.”

How To Fix a 502 Bad Gateway Error (2)

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.”

How To Fix a 502 Bad Gateway Error (3)

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.

How To Fix a 502 Bad Gateway Error (4)

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.”

How To Fix a 502 Bad Gateway Error (5)

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 andreload 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 intodownforeveryoneorjustme.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.

How To Fix a 502 Bad Gateway Error (6)

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 forOpera

7. Check for DNS Issues

A 502 gateway error could also be becauseof 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
How To Fix a 502 Bad Gateway Error (7)

You should see a “Successfully flushed the DNSresolverCache” if it worked.

For macOS users, you canenter the following in the terminal:

dscacheutil -flushcache

Note: There is no success message onMacs.

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 apublic DNS server, such as Googles. In fact, someprefer 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 aquery, script, or request will take too longand so it iscanceledor killed by the server. A lot of hosts, especially shared hosts implement what they call a “kill script.” Basicallywhat 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 seethousands of tweets happening every day alerting their hosting company of the problem.

How To Fix a 502 Bad Gateway Error (8)

One reason youmight want to consider moving to a host like Kinsta is that our platform runs in anisolated software containerthat contains all of the software resources required to run the site (Linux, NGINX, PHP, MySQL). This means that the software that runseach 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 pageor open a support ticket.

9. Temporarily Disable CDN or Firewall

It could also be an issue with yourcontent 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 tocdn-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.

How To Fix a 502 Bad Gateway Error (9)

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.

How To Fix a 502 Bad Gateway Error (10)

502 Bad Gateway at Cloudflare (Variation 2)

If you see the following screen, this is a problem with your host.

How To Fix a 502 Bad Gateway Error (11)

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.

How To Fix a 502 Bad Gateway Error (12)

10. Check Your Plugins and Themes

A lot of times the reason for scripts and queries being canceled by the server is due tobad 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.

How To Fix a 502 Bad Gateway Error (13)

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.

How To Fix a 502 Bad Gateway Error (14)

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 APMand 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.

How To Fix a 502 Bad Gateway Error (15)

If it turns out to be an efficient query or bad code in a plugin, you might need to bring in aWordPress developerto fix the issue.

11. Check Logs

Youshould also take advantage of yourerror 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.

How To Fix a 502 Bad Gateway Error (16)

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”.

How To Fix a 502 Bad Gateway Error (17)

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 ouranalytics toolto 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.

How To Fix a 502 Bad Gateway Error (18)

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.

How To Fix a 502 Bad Gateway Error (19)

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:

  1. Try Reloading the Page
  2. Check the Site Status
  3. Try a Different Browser
  4. Try in Incognito Mode
  5. Test on Another Device
  6. Clear Your Browser Cache
  7. Check for DNS Issues
  8. Check With Your Host
  9. Temporarily Disable CDN or Firewall
  10. Check Your Plugins and Themes
  11. Check Logs
  12. Restart PHP
  13. Check for PHP Timeout Issues

How To Fix a 502 Bad Gateway Error (20)

Brian Jackson

Brian has a huge passion for WordPress, has been using it for over a decade, and even develops a couple of premium plugins. Brian enjoys blogging, movies, and hiking. Connect with Brian on Twitter.

How To Fix a 502 Bad Gateway Error (2024)

FAQs

How To Fix a 502 Bad Gateway Error? ›

A 502 bad gateway message indicates that one server got an invalid response from another. In essence, you've connected with some kind of interim device (like an edge server) that should fetch all of the bits you need to load the page. Something about that process went wrong, and the message indicates the problem.

How do I fix 502 Bad Gateway? ›

9 ways to fix the 502 bad gateway error
  1. Reload the webpage. ...
  2. Double-check the URL. ...
  3. Verify web server status. ...
  4. Test the webpage in a different environment. ...
  5. Flush your DNS cache. ...
  6. Disable your browser extensions. ...
  7. Inspect your proxy server, VPN, and firewall. ...
  8. Try again later.
Sep 13, 2023

Is a 502 Bad Gateway my fault? ›

A 502 bad gateway message indicates that one server got an invalid response from another. In essence, you've connected with some kind of interim device (like an edge server) that should fetch all of the bits you need to load the page. Something about that process went wrong, and the message indicates the problem.

Why does 502 Bad Gateway keep popping up? ›

It can occur due to temporary issues, such as errors in server-side code or DNS problems. You can usually solve the issue by refreshing the page or waiting a few minutes. Even though it's a server-side error, the 502 Bad Gateway message might appear due to client-side factors like cache or DNS settings.

Is 502 Bad Gateway temporary? ›

The “502 Bad Gateway” error can also be caused by a temporary connectivity issue originating from your local ISP.

How do I fix my internet gateway problem? ›

The error indicates that the system cannot find the default gateway, often your home router, resulting in disconnection. To fix this, try to reset the TCP/IP stack, check your firewall, disable energy-saving features for your network adapter, or update the necessary drivers.

What is the response status of 502 Bad Gateway? ›

The HyperText Transfer Protocol (HTTP) 502 Bad Gateway server error response code indicates that the server, while acting as a gateway or proxy, received an invalid response from the upstream server.

How to fix 502 Bad Gateway wifi calling? ›

Troubleshooting Wi-Fi calling
  1. Go to Settings > Phone > Wi-Fi calling and double-check that the feature is enabled.
  2. Restart your phone. ...
  3. Connect to a different Wi-Fi Network. ...
  4. Turn Wi-Fi calling off and on again (Yes, we know how this sounds, but it works a good deal of the time)
Feb 22, 2024

What is error 502 Bad Gateway origin? ›

An HTTP 502 status code (Bad Gateway) indicates that CloudFront wasn't able to serve the requested object because it couldn't connect to the origin server. If you're using Lambda@Edge, the issue might be a Lambda validation error.

How to fix 502 Bad Gateway reddit? ›

  1. Deactivate plugins temporarily.
  2. Deactivate your theme temporarily.
  3. Disable your CDN temporarily (if you have any)
  4. Limit WordPress Heartbeat API.
  5. Enable WP_DEBUG.
  6. Upgrade Your Server Resources.
  7. Reinstall WordPress with a Fresh Copy.
May 9, 2024

Does 502 Bad Gateway fix itself? ›

The 502 Bad Gateway error could be a temporary issue. For example, the web server may have become overloaded for a few minutes or experienced a brief surge in traffic. Try waiting a few minutes and refresh the page. If that doesn't work, you can try accessing the same site using a different browser.

What causes 502 gateway timeout? ›

A 502 bad gateway message indicates that one server got an invalid response from another. In essence, you've connected with some kind of interim device (like an edge server) that should fetch all of the bits you need to load the page.

What is 502 Bad Gateway out of memory? ›

There's no specific explanation for this, but in most cases, the 502 error happens because of server overload. When the server that the website is hosted on reaches full memory capacity, this happens. That's why people must host their website on a web hosting company with powerful servers.

What does 502 Bad Gateway Timeout mean? ›

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 is the reason for 504 gateway timeout? ›

Your site may be experiencing a 504 Gateway Timeout due to malicious bots crawling your site at excessive rates. They can exhaust your server resources by spawning too many requests toward your site. If your site is under a DDoS attack from bad bots generating abnormal traffic, it will serve an HTTP 504 error.

Top Articles
Latest Posts
Article information

Author: Rev. Leonie Wyman

Last Updated:

Views: 6330

Rating: 4.9 / 5 (79 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Rev. Leonie Wyman

Birthday: 1993-07-01

Address: Suite 763 6272 Lang Bypass, New Xochitlport, VT 72704-3308

Phone: +22014484519944

Job: Banking Officer

Hobby: Sailing, Gaming, Basketball, Calligraphy, Mycology, Astronomy, Juggling

Introduction: My name is Rev. Leonie Wyman, I am a colorful, tasty, splendid, fair, witty, gorgeous, splendid person who loves writing and wants to share my knowledge and understanding with you.