The 502 Bad Gateway error code can be encountered if you browse the internet for a long time. It is especially critical if you frequent unreliable websites frequently. Despite its frustration, this error is generally easy to fix.

The purpose of this article is to explain what a 502 Bad Gateway error code is and how it can be resolved on your own.

502 Bad Gateway: What does it mean?

The 502 Bad Gateway indicates that the edge server (server acting as a proxy) could not receive a valid response from the origin server (also known as the upstream server). Several reasons can cause this, which we'll discuss below. Your origin server will return a 500 Origin Not Reachable page if it receives a 502 Bad Gateway response from one of AgileCDN's edge servers.

We have a CDN Error Codes page that explains how AgileCDN handles certain error codes.

In most cases, a 502 Bad Gateway error code is accompanied by a message informing you that a "bad gateway" exists. There was a problem relaying information to another server (usually an upstream server). DNS records that are incorrect or out of date are usually the cause of this issue.

502 Bad Gateway

How Does a 502 Bad Gateway Response Occur?

The most common causes of 502 Bad Gateway responses are three. The following are among them:

1.There is a problem resolving the domain name to the correct IP address or it does not resolve to any IP address. In addition, DNS changes could take the same amount of time to propagate globally and become active. This is dependent on the TTL, or time to live, defined per record.

2.There is no connectivity to the origin server, either because the server is down or there is no connection to the server at all.

3. Using firewalls to block requests: Firewalls prevent edge servers from communicating with origin servers. You may also experience this problem if your CMS contains security plugins. Some DDoS protection and mitigation systems might are too overreactive and start blocking requests from our content delivery servers.

Error 502 Bad Gateway: How to Fix It

How to Fix Error 502 Bad Gateway

You may see different 502 errors depending on your web server.

It always means the same thing. There is only one difference between the two components: their naming conventions. The following are a few examples:

  • 502 Bad Gateway
  • HTTP Error 502 - Bad Gateway
  • 502 Service Temporarily Overloaded
  • Error 502
  • 502 Proxy Error
  • HTTP 502
  • 502 Bad Gateway NGINX

AgileCDN

A web developer's guide to solving 502 errors

You may be experiencing a 502 Bad Gateway error on your origin server if you are a web developer or owner of the website. To resolve the issue, you may need to try various methods. Below is a list of suggestions:

  • Using our DNS test tool, you can check whether your fully qualified domain name (FQDN) resolves correctly.
  • Test your server's reachability using ping or traceroute.
  • If you are seeing unusual drops, check your firewall logs.

A visitor's guide to resolving 502 errors

Website visitors who encounter a 502 Bad Gateway error also have a few options for resolving it. In most cases, the web developer will be responsible for the primary problem, but visitors can try the following:

  • You should perform a hard refresh in your browser. For Macs, press Cmd + Shift + R.
  • Clear the cache and cookies in your browser. There is a possibility that your browser is still holding onto files saved when you visited a website with a 502 error.
  • It is a good idea to restart your computer/networking equipment
  • Make sure your DNS servers are updated. The default DNS servers assigned to you by your ISP are likely still there if you've never changed them. Try using an open DNS server like Google's Public DNS instead.

The Most Common Solutions for 502 Bad Gateway Error Code

An error 502 usually results from a server error. When you encounter a server error, you are trying to access an unavailable or down server. On the other hand, the client can also do it.

To fix it, here are some common methods:

The page should be reloaded

It is easiest to simply reload the page. There are two types of server-side errors: 502 and 504. The server must be malfunctioning. A server downtime or too much traffic could be the reason for the problem.

By reloading, a new request will be sent to the server. A server may be down, but it may also be due to a timeout. A reload will often fix the problem.

For checking whether the issue is server-side or client-side, some tools are useful.

Delete the cache in your browser

There is also a possibility that your browser's cache is causing the problem. A recent visit to the website may have caused your browser to attempt to use an old version of the website. The cache can be cleared in your browser by going to its settings and looking for the option to do so.

Click More tools when you are in Google Chrome's three dots. Click on Clear browsing data.

Firefox has three bars in the top right corner, where you can click Options. Scroll down to Cookies and Site Data and click Privacy & Security. Then click Clear Data.

You can access Settings in Microsoft Edge by clicking the three dots in the top right corner. Then, click Clear browsing data and select what to clear.

Select Preferences from the Safari menu. Click the Privacy tab and select Manage Website Data. Then click Remove All.

Make sure your computer and router are both restarted

It is also possible that the problem lies on your end. Installing new software or making changes to your computer could be the cause of the problem. If the problem persists, restart your computer.

The problem may be caused by one of your browser's extensions. If the problem still persists, try disabling all your browser's extensions.

If the problem still persists, you can reset your router. You will need to unplug your router and wait 30 seconds. Then plug it back in and wait for it to connect to the internet after 30 seconds.

Your DNS server needs to be changed

Change your DNS servers if you continue to have problems. Default DNS servers are likely to be assigned to you by your ISP if you have never changed them before. There can be a 502 error if your DNS server doesn't respond or if your domain doesn't resolve the correct IP address.

A public DNS server such as Google's Public DNS might work for you.

Click Network and Sharing Center in the Control Panel to change your DNS servers. You can find your internet connection by double-clicking Change adapter settings.

Select the Networking tab under Properties. You can now double-click TCP/IPv4 (Internet Protocol Version 4) there.

Select Use the following DNS server addresses from the General tab. You should enter 8.8.8.8 as your preferred DNS server and 8.8.4.4 as your alternate DNS server.

Once you have made your changes, click OK to save them.

The DNS servers can also be changed in the router's settings. There will likely be a DNS setting in the Network or Internet section of your router's settings, depending on your router.

Reload the website once you have changed your DNS servers

The DNS cache needs to be flushed

It is also possible for DNS caching to cause 502 errors. Whenever you visit a website, your computer stores certain information about that site in its DNS cache. When you visit the website again, your computer will load it faster. An outdated piece of information can, however, result in a 502 error.

Using the command prompt, flush the DNS cache by entering the following command:

  • Windows: ipconfig /flushdns
  • Mac: sudo killall -HUP mDNSResponder
  • Linux: sudo /etc/init.d/networking force-reload

After flushing your DNS cache, try loading the website again.

Disable your firewall or CDN temporarily

AgileCDN is a popular content delivery network (CDN). In spite of their importance, these services can sometimes result in 502 errors. You can temporarily disable a CDN if you are using one.

Disable your CDN in WordPress by clicking the Disable CDN button under the CDN tab in the Settings section of your dashboard. Then click Save Changes.

Similar processes will apply to other CMSs. You can find the settings for your CDN or Content Delivery Network in the dashboard of your CMS.

It is also possible that your firewall is causing 502 errors. Try temporarily disabling your firewall to see if that helps.

Go to the Control Panel and click System and Security. Click Windows Firewall from there.

To turn Windows Firewall on or off, click the link in the left sidebar. In the event that you are prompted for an administrator password or confirmation, enter it.

Then click the Turn off Windows Firewall (not recommended) option for both private and public networks.

Summary

If you see 502 Bad Gateway errors, there are a few things you can do to try and fix the problem. Usually, this error code is an easy one to fix and requires one of the following:

  • Reload the page
  • Clear your browser's cache
  • Restarting your computer or router
  • Flushing your DNS cache
  • Temporarily disabling your CDN or firewall

If you are still having problems, you can try changing your DNS servers. If you have never changed your DNS servers before, you likely have your ISP's DNS servers configured. However, you can try using public DNS servers such as Google's Public DNS.

Worst case scenario, you will have to contact your ISP's customer support. They should be able to help you troubleshoot the problem and get you back online.