What does 502 bad gateway mean and how to fix it

Using the web is such a common and natural part of everyday life that few of us give any thought about how it works or how the servers and clients that make up the internet connect to each other. Only when things go wrong do we wonder why and start to think about how it all works. One quite common error is ‘502 bad gateway.’ It’s one of those error messages that, on its own, is meaningless to most of us and leaves us none the wiser as to why we can’t access a web page. So, in this article, we’ll explain what this error means and how to fix 502 bad gateway on Chrome or any other browser.

What does 502 bad gateway mean?

Before explaining what 502 bad gateway means, it’s helpful to understand a little about how the web works. When you click on a link or type a URL, the request is sent from your Mac via your router to a domain name system (DNS) server, usually configured by your broadband provider. The DNS server translates the URL to an IP address and forwards the request. Once you connect to the IP address, depending on what you do on the page, the server hosting the web page might relay requests and data to and from another server. For example, if a video you want to watch is hosted on a third-party content distribution system, your request to view it would be forwarded to that system’s server. A 502 bad gateway error occurs when the server relaying your request can’t connect to the other server or it gets an invalid response from that server.

What causes 502 bad gateway error?

There are a number of possible reasons for 502 bad gateway errors:

  • The server could be down.
  • The server could be overloaded and refuse new connections.
  • The request could be improperly configured.
  • There could be a problem with a firewall.
  • There might be an issue on your Mac or browser.

As you can see, most of the causes of the 502 bad gateway error are on the servers relaying your request or hosting the content.

How to fix 502 bad gateway error

Sometimes, the only thing you can do when you encounter a 502 bad gateway error is be patient and wait until it’s fixed by itself. How long that takes is anyone’s guess. If the server is overloaded, it could just be a few minutes. But if there’s a problem with the connection between the two servers, it could take longer. In some cases, if the server has been shut down or removed, it might never be fixed.

Try refreshing the page, and if that doesn’t work, wait for half an hour or an hour and try again. If it still doesn’t work, you should check whether other people are having the same issue. There are a few websites that allow users to log websites they are having problems with. If the page you are trying to access is on a well-known website, the issue may have been reported to one of these sites. Two of the most widely used of these sites are isitdownrightnow.com and downforeveryoneorjustme.com. Try both of them. If the page giving you the error is reported by other users on one of these sites, all you can do is be patient. If it hasn’t been reported, follow the steps below.

If you’ve tried several times over the course of a couple of days and keep getting the same error, and you know it is just you who is getting the error, the next thing to do is to rule out any possible causes at your end. We’ll show you how to do that.

The 502 bad gateway fix is to try and connect to the website using a different browser. If that works, then it’s the original browser that’s at fault. The cause could be cached files, cookies, extensions, or plug-ins.

Clear cached files and cookies

The method for clearing cached files and cookies is different for different browsers. We’ll show you how to do it in Safari and Chrome. The method in most other browsers is similar.

Safari

  1. Open Safari and click on the Safari menu, then choose Settings.
  2. Go to the Privacy tab and click Manage Website Date.
  3. Wait for the data to load and then click Remove All.
  4. Quit Settings.

Chrome

  1. Click on the three dots next to the address bar and choose Settings.
  2. Select Privacy and Security in the sidebar.
  3. Choose Clear browsing data.
  4. In the window that opens, check the boxes next to ‘Cookies and other site data’ and ‘Cached images and files.’
  5. Click Clear Data.
  6. Close the browser tab.
Tip

Maintain your Mac

Your Mac is just like a car or a house — if you maintain it regularly, it will perform better and last longer. In the case of your Mac, that means freeing up RAM, clearing purgeable disk space, repairing disk permissions, and flushing the DNS cache. Clearing the DNS cache may even fix a 502 gateway error. You should also run macOS maintenance scripts. Doing all that manually is time-consuming and difficult if not impossible. Thankfully, there is an easier way to do that — CleanMyMac X’s Maintenance module can run all those tasks for you at the click of a few keys. Just choose the tasks you want to run and click Run. Best of all, CleanMyMac X is free to download here, so you can install the app and try it for yourself.

Flush DNS cache in Maintenance


Check plug-ins and extensions

If you’re still seeing the 502 bad gateway error after clearing the browser cache and cookies, the next step is to disable extensions and plug-ins and try again. If the error disappears, you’ll know that one of the extensions was causing the problem. You can then start to enable them again, one at a time, checking the website connection each time. If you find the culprit, check whether it’s up to date. If not, update it. If it is, consider leaving it disabled or removing it altogether.

How to disable extensions in Safari

  1. Click on the Safari menu and choose Settings.
  2. Select the Extensions tab.
  3. Look for extensions that have a checkmark next to them in the sidebar.
  4. Deselect the box next to each and confirm you want to disable them, if you’re asked.
  5. Quit Settings.

How to disable extensions in Chrome

  1. Click on the three dots next to the address bar and choose Settings.
  2. Click Extensions in the sidebar.
  3. In each extension, look for the switch at the bottom right corner and set it to off.
  4. Close the browser tab.

Restart your device

If disabling extensions doesn’t work, or if the problem affects more than one browser on your Mac, the next step is to restart your Mac. Restarting your Mac is good practice whenever you run into problems on your Mac. It clears out temporary files and settings that may be causing the issues you’re facing. On Macs with Apple silicon, it also runs a check on the disk and fixes any problems it finds. If that doesn’t work, try restarting your router. Wait for it to complete startup, then try again. As with your Mac, restarting your router can fix lots of issues, from incorrect settings to reissuing IP addresses.

Change DNS server

By default, your Mac uses the DNS server that is used by your broadband provider. However, if there are problems with that DNS server or if its directory is out of date, you may get a 502 gateway error when you try to connect to some websites. Google runs DNS servers that you can use for free and are a great alternative to your broadband provider’s DNS server.

Here’s how to change the DNS settings on your Mac:

  1. Click the Apple menu and choose System Settings.
  2. Select Network in the sidebar.
  3. Choose your Wi-Fi network or Ethernet connection, then click Details.
  4. Go to the DNS section and select the DNS server.
  5. Click the ‘-‘ to remove it.
  6. Click the ‘+’ to add a new DNS server.
  7. Type: 8.8.8.8.
  8. Click the ‘+’ again and type: 8.8.4.4
  9. Click OK.
  10. Quit System Settings.

Now, when you click a link or type a URL, your Mac will first try Google’s 8.8.8.8 DNS server, and if that’s not working, it will try 8.8.4.4. If DNS was the problem causing the 502 bad gateway error, it will now be fixed.

A 502 bad gateway error occurs when one web server is unable to connect to another in order to serve the content you have requested. It’s normally the fault of one of the servers but can sometimes be the result of issues on your Mac. Follow the steps above to identify the problem and fix it.

Laptop with CleanMyMac
CleanMyMac X

Your Mac. As good as new.