Error 502 Bad Gateway and How to Handle It

What is Error 502 Bad Gateway?

When we visit a website, the browser will automatically send your request to the website server. The web server receives and processes your request, then sends back the source you requested through the browser along with the HTTP header and HTTP status code.

Usually this HTTP status code is not visible unless our website has an error. This code serves to tell you that something is wrong and will usually show you how to diagnose the error.

There are many types of error codes that begin with the number "5" including codes 500, 501, 502, 504, 520 and others. All of these codes have different meanings. It generally means that the request was accepted, but the server prevented the acceptance. In this article we will discuss error 502 Bad Gateway.

If you get this error code 502 bad gateway, then it means that the initial server is sending an invalid response to another server, which this server serves as a gateway.

Because requests on the web are forwarded through various other gateways. Then, how to solve this error? Take a look below at some ways to resolve error 502 bad gateway.

How to resolve Error 502 Bad Gateway

Error 502 bad gateway usually occurs because of a problem with the server. However, it can also happen because of an error on the other side, such as on the client side. Therefore, we will discuss this from both sides. Including the common causes.

1. Reload Page

One of the easiest and first ways you should try when facing an error like this is to wait a minute or so, then reload the page by pressing F5 or Ctrl + F5.

Why? Because sometimes errors like this occur because the host or server is overloaded and the site will usually recover. While waiting, you can try again using another browser.

2. Clear Browser Cache

When you encounter a 502 bad gateway error, you can first clear all browser caches. Read this article about the importance of clearing browser cache.

3. DNS Problem

This error 502 bad gateway problem can also occur due to problems with the DNS (Domain Name Server), such as the value of the cached IP address. If this is the case, then a DNS flush may be the best thing to try.

How to use DNS flush? Check it out below!


If you are a Windows user, you can use CMD (Command Prompt) and enter the code below:

ipconfig / flushdns

If successful, there will be a message like this:  "Successfully flushed the DNS resolver Cache"


If you are a Mac operating system user, you can use the code below in the terminal:

dscacheutil -flushcache

And the last way you can try is to temporarily change your DNS servers. By default, DNS servers are set by your ISP (Internet Service Provider). However, you can try temporarily changing it to a public DNS server like Google for example.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.