What 502 Bad Gateway Means and How to Fix It

A 502 Bad Gateway error is a pretty common, yet annoying issue for most web users. It’s one of the HTTP status codes that point out the presence of a communication breakdown with a given server. Are you frequently encountering this kind of response and wonder how to deal with it? Then our article might be of help. We will first define in more detail the 502 error code. This is necessary in order to understand the core of the problem. In the second part of our article, we will have to identify the different factors that may generate such glitches. We will also expose the consequences that they may have on your site, especially regarding your SEO practice. And of course, most importantly, we will see how to solve them.

What Is a 502 Bad Gateway?

Perhaps the easiest part here is that the name already gives some clues, right? At least it indicates that something went wrong and needs to be remediated. First of all, let’s revisit the general context of a 502 Bad Gateway. You probably know that servers communicate with one another through Hypertext Transfer Protocol (HTTP) response status codes. When you type an URL, your browser sends a request to the server of the site you are trying to reach. That server responds to your request with a certain status code along with the content you are looking for. Or not… There are indeed 5 different types of codes. Each category begins with a distinct digit that represents the nature of the response:

1** informational response means that the response was received and is being processed.

2** successful means that the request was received, processed, and accepted.

3** redirection indicates that the request needs additional action to be fulfilled.

4** client error may be pointing out some bad syntax or unachievable request.

5** server error means that even though the request was plausibly valid, the server can’t fulfill it. 

As you see, the 502 status code belongs to the fifth and last category. This is where you also find the other 5** error types. Think of 501 Not Implemented, 503 Service Unavailable, 504 Gateway Timeout, 505 HTTP Version Not Supported, 506 Variant Also Negotiates, etc. They are all server-related (versus client-related). You are connected to a specific server that acts as a proxy and transmits information properly. Unfortunately, your recipient (that is, your target server) is not able to send you a valid response.  

502 Bad Gateway Error

Being Aware of Equivalents

It’s good to keep in mind that 502 Bad Gateway errors can appear on your screen in slightly different forms. Among the possible variations, we have:

  • Error 502
  • HTTP 502
  • HTTP Error 502 – Bad Gateway
  • 502 Proxy error
  • Temporary Error (502)
  • 502 Service Temporarily Overloaded
  • 502. That’s an error.
  • 502 – Web server received an invalid response while acting as a gateway or proxy server.
  • Bad Gateway: The proxy server received an invalid response from an upstream server.
  • Blank pages

Despite some nuances, all those notifications express the same kind of problem. Sometimes you may also see a totally different display depending on the browser or the platform you are on. There may be varied colors and terms such as ‘too much time to respond’ or ‘overcapacity’. Observe the elements of information carefully in order to spot commonalities.

Where Do 502 Bad Gateway Errors Come From?

We can list several causes for 502 Bad Gateway Errors. As we said, the problem is usually not client-related, meaning that it’s not your ‘fault’. However, the below list also includes some scenarios in which you may have to check things out on your end as well. The HTTP system is indeed quite complex and capable of taking into account even minor blockages.

So here’s the list of possible causes. It might not be exhaustive, but nonetheless very likely to contain a match with your specific situation.

Domain Names

Domain Name Issues

The domain name may not be resolving to the proper IP or sometimes even to any IP at all. This is often due to DNS (Domain Name System) changes). Such modifications require up to 24 hours to be fully processed and come into effect. The determining element here is TTL (time to live). So when a domain is being moved to another host, there’s a recalculation of lifespans and other revalidations to be made. All in all, we venture that this issue is more or less a matter of patience.

Browser Issues

Sometimes one may see the status code 502 popping up seemingly out of nowhere. The network and server may seem to function flawlessly for any other tasks. It’s wiser to double-check anyhow because there might be a hidden problem. For instance, are you sure that your browser version is up-to-date? Are you using an ad blocker or any other potentially interfering extensions? How about the state of the files in your browser cache? Defective ones may be spoiling the normal activity of your browser.

Origin Server Issues

502 Bad Gateway errors may also originate in the main or origin server. As you know, that’s the one responsible for storing the original versions of web pages and addressing all the requests. When there’s a traffic overload, it naturally becomes unable to deliver what users are asking for. There may also be a hindrance regarding connectivity or memory capacity.

Firewall blocking

Firewall Blocks

A firewall is comparable to a safety valve between the origin server and the edge servers. Under usual circumstances, it preserves your website from various threats and attacks such as DDoS (distributed denial-of-service). The downside is that sometimes it can be more reactive than necessary. As a consequence, CDN (content delivery network) requests might face a blockage. The problem can even spread over an entire service provider.

Home/Office Network Issues 

If you keep seeing HTTP code 502 responses in several browsers or sites, the troublemaker could be your own equipment. You would better check your modem, router, and any other component likely to experience connection perturbations.  

502 Bad Gateway Effects on SEO

This section is important for those of you who are managing a website. As hinted at in our introduction, recurring gateway error cases are not so good news in the context of SEO. The keyword here is recurring. Indeed, you don’t need to worry if you run into 502 responses once in a while. After all, it’s not something that you have full control over. But if it’s a persistent problem occurring on a regular basis, then we have a different story. What are the possible negative consequences? Any guesses? Well, your visitors would probably not be delighted to see their requests constantly fail. This can increase your bounce rate and exit rate.

Another alarming aspect is about search engine bots. When they crawl a page and run into a 502 error, they tend to categorize it as broken. Needless to say, this can have a negative impact on the indexability of your website as well as your ranking.

Now you know why you should care about and tackle bad gateway issues.

502 Bad Gateway

How to Fix 502 Bad Gateway Errors  

In order to avoid any misunderstandings, let’s repeat once again that those problems are often server-related. That is, independent of your initiatives. However, you should always opt for a broader approach and try to contribute to the solution. Bear in mind the aforementioned scenarios where your equipment may also be the culprit. So let’s see which actions you could take.

Reload the Page

This is almost an automatism, right? Don’t hesitate to go for it. The solution may be as simple as that in most cases. So just wait for a couple of minutes and then refresh the page. Don’t forget the shortcuts: F5 or CTRL + F5 for Windows users, CMD + R for Mac users. If you keep getting the same error, you may also want to clear your browser cache before trying again. Make sure to import your data back afterward to avoid losing any important elements.

Additionally, you may need to verify the current availability of the website. To do so, use online services such as Host Tracker. It would be pointless to refresh a page that has been put on an offline mode.

Track DNS Changes

We already said that DNS changes can cause temporary blockages. New host servers and IP addresses need some time before being ‘officialized’. So review carefully any recent modifications that you may have made. Besides, you may need to clear some records to resolve general connectivity issues. Flushing your DNS cache is a good method to get rid of misleading files. When these accumulate, they may indeed result in errors regarding the IP address and DNS server.

Try Again on a Different Device or Network

We also mentioned 502 response scenarios that may be caused by your own network equipment. You can test it by turning off your computer and hardware components (router, etc.). Wait a few minutes before reactivating them. Try also to access your target URL via another computer or portable device. Even better if you have the chance to do that from another network. Similarly, you may also want to retry with another browser. Once again, keep an eye on the updates, extensions, and cache.

Check Server Error Logs

Since 502 Bad Gateway errors are essentially a matter of server, it sounds logical to verify your error log. This becomes all the more necessary if there’s been any recent website update. Use the admin dashboard to enable error logging. If you are on WordPress, there’s another way to proceed. Insert the following lines in the wp-config.php file:

define(  ‘WP_DEBUG’ , true  ) ;

define(   ‘WP_DEBUG_LOG’ , true  ) ;

define (  ‘WP_DEBUG_DISPLAY’ , false ) ;


You should see a list of errors in the wp-contents/debug.log file. This is where you are likely to find the source of the error.

Wordpress Plugins

Browse Plugins and Themes

Speaking of WordPress, it’s highly recommended that you browse and examine your plugins and themes regularly. Why? What we often see is that some of them are incompatible with one another. This happens, for example, in the case of mediocre coding. Your server may react by denying access to your website in order to avoid further confusion.

Some security plugins can make things even worse. Even when they are coded correctly, they can create inter-server obstructions and make them unable to communicate with each other. You may have to decide whether to keep or discard such plugins.

Now, what if you don’t use any problematic security plugin or caching but still deal with 502 errors? A somewhat tedious option is to deactivate all your plugins one by one and then reactivate them. This may be a surgical way to identify the root cause. What you have to do is access your dashboard and select Plugins. Then open the Bulk Actions menu and select Deactivate. Once you are done, you can start reactivating them. Every time you reactivate one, make sure to refresh your site. When you see a 502 code appearing again, this will mean that you have found the faulty plugin.

Don’t forget that you can disable plugins directly from the hosting panel or FTP program. Just go to the wp-content directory and rename the plugins directory by typing the new name in the dedicated dialog box. Choose a self-explanatory name such as ‘plugins-disable’ or ‘plugins-disabled’.  

Disabling CDN

Disable CDN

There’s no doubt that a content delivery network or CDN is extremely useful for serving static site content. This is especially due to its speed which facilitates transmission to a large audience. CDN is often described as an additional layer between the server and the browser. The only disadvantage is that this layer can get somewhat sensitive, so to speak. Thus sometimes, it would turn any issue encountered in the origin server into a 502 response code. 

You could try to disable the CDN service and see if your site becomes accessible afterward. If the problem is solved, it means that the root cause of bad gateways is related to the CDN. Contact your CDN provider to inform them and get a longer-term solution.

Check PHP Values

There are two values to monitor in your PHP configurations: max_execution_time and max_input_time. By default, they are set to 300 seconds. If the loading duration goes beyond (especially in the context of a migration process), this results in a timeout. That’s one of the possible reasons behind a 502 Bad Gateway error.

The best thing to do here is to contact your web hosting provider. They can check the values in a precise way and make changes if necessary.

Contact the Customer Support

So yes, as already said at the end of the previous section, contacting your service provider might be the definitive answer. Even though we have given you a few clues and tips, there’s often no use speculating. What we mean is that your 502 gateway issues can be more complex or hidden than they seem. So asking for professional help would be your best bet. Not to mention that settings and configurations do vary from one service provider to another. Describe the problem in a detailed way, explain how and when it appeared, etc.

Eradicate 502 Errors

Despite not being the worst thing that can happen to your IT system, a 502 Bad Gateway error is not a pleasant experience. For website users, they are a loss of time. For website owners, they can become a threat in terms of performance. Fortunately, they are quite easy to resolve in most cases. Check the troubleshooting tips in our article and see which one fits your particular situation. In case of doubt, don’t hesitate to contact your service provider.

Frequently Asked Questions About

Yes, this could be an effective method to get a clearer idea about the state of connectivity and latency. 502 errors often reflect a delay related to particular IP addresses. The test can help identify them.

Yes, it happens. Third-party APIs can represent an additional load for the server. More importantly, there may be incorrect SSL configurations at play. It’s best to discuss with your service provider in order to identify the exact problem.

No, not really. Rather than a blockage, they show that the edge server couldn’t get a valid response from the upstream server.

As indicated by their name, 504 errors are much more time-related. Simply put, they happen when a user waits for too long to receive a response from another server. Eventually, this results in expiration or timeout. On the other hand, 502 errors are more of a communicational kind.

You don’t have to. However, if you believe or notice that your 502 issues have something to do with the DNS, then you can. Third-party servers like Google Public DNS are often recommended and happen to be quite effective.   

Fatih Karadeniz
Hi my name is Fatih Karadeniz. I graduated from English Language and Literature Department and I have developed an interest in researching and writing about SEO and Digital Marketing related topics.
Be the First to Comment on What 502 Bad Gateway Means and How to Fix It

Your email address will not be published. Required fields are marked *

(Total: 43 Average: 5 )

No comments to show.