Home > How to Tips

What is 502 Bad Gateway on Mac/Windows & How to Fix it?

Updated on Tuesday, December 3, 2024

Written by

Eudora Liu

Approved by

Jessica Shee

English

Summary: If you see 502 Bad Gateway on your Mac and Windows when you browse the Internet, this post is best for you to learn what it is, and how to fix it on Mac and Windows.

When you browse the internet for a long time, or you frequently browse some websites known to be unreliable, you will turn into a 502 Bad Gateway error code on your screen. "502 Bad Gateway Nginx" may be the most common prompt.

Like a 404 error code, the website designer can customize the appearance of 502 Bad Gateway on their website. So different web servers have different 502 errors, and you may have seen the following prompts.

  • HTTP Error 502 Bad Gateway
  • HTTP 502
  • 502 Service Temporality Overload
  • Temporary Error (502)
  • 502 Server Error: The server encountered a temporary error and could not complete your request.
  • 502 Bad Gateway: Cann't Connect To Upstream Server

Don't be frustrated when you encounter such an error code, it's easy to be fixed. Just keep reading and try to fix 502 Bad Gateway on your Mac or Windows.

Share this post to help more people that have the same problem as you!

 

What is 502 Bad Gateway?

A 502 Bad Gateway on your Mac/Windows indicates that the web server you've connected to is acting as a proxy for relaying information to another server (also called the upstream server), but it could not get a valid or any response from the origin server. The most common cause of this issue is an incorrect or outdated DNS record.

But what are the reasons for the 502 Bad Gateway error code? Answers may be the following.

  • Origin server down: The server is not accessible, because it is down or it is not connected to the server.
  • Domain name not resolvable: The domain name is not resolving the correct IP or does not resolve any IP.
  • Firewall blocks request: The firewall blocks the connection between the web server and the upstream server.

Turning to the web server's error log file, you can see more details of what the error especially entails. All the error and diagnosis information is stored in this file which is a valuable resource when you need more information about a peculiar error.

How to fix 502 Bad Gateway on Mac/Windows?

Usually, 502 Bad Gateway is the result of the server error, which means the server you trying to access is not accessible or down.

Now, you can use the following ways to fix 502 Bad Gateway on Mac or Windows.

Refresh the page

Refresh the browser is always worth a shot. Sometimes, the 502 Bad Gateway is just temporary, and refreshing the browser can solve the problem. Most browsers can do a hard refresh with a shortcut.

You can press Control + R on Windows or Command + R on Mac to refresh your browser. It's the easiest way you can do to fix 502 Bad Gateway. A refresh will send a new request to the server. The server may be down, but it can also be that the upstream server request times out. And refresh can fix this problem.

Check your Mac or Windows

If the above ways can't solve the problem, try to restart your Mac or Windows. If you have installed new software or made changes to your computer, it may cause 502 Bad Gateway. Try to restart your Mac or Windows and check if the error is fixed.

502 Bad Gateway may be caused by one of your extensions, try to disable all your extensions and load the website again, and see if the problem is solved. If you can access the website successfully, it's likely that a plugin is causing the problem. Just enable your plugins one by one to find the culprit.

If the problem still exists, try to reset your router. Unplug your router from the power and wait 30 seconds. Then plug in the power outlet again and wait for it to connect to the internet. And load your website again.

If you think this post is helpful, share it with your friends.

 

Clear your browser cache and cookies

Before clearing your browser cache and deleting cookies, you can change the browsers to enter the same website. If it works, it proves that your main browser may be has cached outdated or corrupt files that may cause 502 Bad Gateway. Clear these cache and delete cookies, then open the website again could fix it.

Here are different ways to remove cache and delete cookies in different browsers:

In Safari:

  1. Open the Safari on Mac.
  2. Click the Safari icon on the left upper of the screen.
  3. Choose Settings (or you can press "Command + Comma(,)" on the keyboard) in the pop-up menu.
  4. Select Privacy in the top menu.
  5. Click Manage Website Data.
  6. Choose all cache and cookies in the list.
  7. Click Remove All.

In Google:

  1. Click the three dots on the right upper of the Google website.
  2. Choose Settings (Command + Comma) in the pop-up menu.
  3. Click Privacy and security in the left sidebar.
  4. Click Clear browsing data.

In Microsoft Edge:

  1. Click the three dots on the right upper of the Microsoft Edge website.
  2. Choose Settings.
  3. Choose Privacy and Services in the left sidebar.
  4. Click "Choose what to clear" below Clearing browsing data.
  5. Check the cache and cookies you need to clear and click Clear Now.

After these steps, you can quit the website and turn to it again.

Change your DNS servers on your Mac or Windows

If the problem still exists, you can try to change your DNS servers on your Mac or Windows. If you have ever changed your DNS servers before, your ISP may assign the default ones to you.

If your domain name is not resolving the correct IP or your DNS server is not responding, it can also cause 502 Bad Gateway. But you can try to use a public DNS server, such as Google's DNS server.

Now, you can follow the below steps to change your DNS servers to fix 502 Bad Gateway on your Mac or Windows. (Set Google's DNS server as an example)

Change DNS servers on Mac:

  1. Check System Settings in Dock.
  2. Choose Network in the left sidebar of the pop-up window.
  3. Choose the network that you want to change the DNS server, such as Wi-Fi or Ethernet.
  4. Click Details, and then select DNS in the left sidebar.
  5. Click "+" at the bottom of the DNS Servers list, then enter the IPv4 or IPv6 address for the DNS server. Enter 8.8.8.8 for the Preferred DNS server, and enter 8.8.4.4 for the Alternative DNS server.
  6. Click OK to save your settings.

Change DNS servers on Windows:

  1. Open Settings, and click Network and Internet.
  2. Scroll down and click Change Adapter Options.
  3. Right-click the network (Wi-Fi or Ethernet) you want to change the DNS server.
  4. Select Internet Protocol Version 4 and click Properties.
  5. Select Use the following DNS server address, and then type in 8.8.8.8 for the Preferred DNS server and 8.8.4.4 for the Alternative DNS server.
  6. Click OK to save the new DNS server for your Windows.

Except for these ways, you can change your DNS server in your router's settings. The process will be depending on your router, but you will be able to find the DNS settings in the Network or Internet section of the router's settings.

After you change the DNS server on your Mac or Windows, try to load the website again.

Clear DNS cache

Sometimes, DNS caching can also cause 502 Bad Gateway on your Mac or Windows. When you visit a website, your computer will store certain information about this site in your DNS cache. This can help your computer to load the site quickly the next time. But if the information is outdated, it will be due to a 502 error.

How to clear the DNS cache to fix 502 Bad Gateway on Mac or Windows:

Clear DNS cache on Mac:

  1. Open Terminal by using the Spotlight or press Command + Space.
  2. Type in Terminal and double-click to open it.
  3. Type in the following command.           
    sudo dscacheutil-flushcache; sudo killall -HUP mDNSRespnoder
  4. Enter your Mac's password.
  5. Press Enter to finish.

Clear DNS cache on Windows:

  1. Right-click the Windows icon and choose Windows Terminal (Admin).
  2. Click the down arrow icon and choose Command Prompt (or press Ctrl + Shift + 2).
  3. Type in the following command.        
    Clear-DnsClientCache
  4. Press Enter to finish.

After you flush your DNS cache, try loading the website again.

Temporarily disable the firewall

As the above text refers to that, the firewall may block the connection between the web server and the upstream server. So you can temporarily disable the firewall to fix 502 Bad Gateway on your Mac or Windows.

Disable the firewall on Mac:

  1. Click System Settings in Dock.
  2. Choose Network in the left sidebar.
  3. Select Firewall and switch the setting to Off.

Disable the firewall on Windows:

  1. Click Win > Settings.
  2. Select Privacy & Security > Windows Security > Firewall & network protection.
  3. Select both Private network and Public network.
  4. Under Microsoft Defender Firewall, switch the setting to Off.

If this post helps you solve the problem, share your happiness with your friends.