Written byEudora Liu
What is 502 Bad Gateway on Mac/Windows & How to Fix it?
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!
Table of Contents:
- 1. What is 502 Bad Gateway?
- 2. How to fix 502 Bad Gateway on Mac/Windows?
- 3. FAQ about 502 Bad Gateway
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:
- Open the Safari on Mac.
- Click the Safari icon on the left upper of the screen.
- Choose Settings (or you can press "Command + Comma(,)" on the keyboard) in the pop-up menu.
- Select Privacy in the top menu.
- Click Manage Website Data.
- Choose all cache and cookies in the list.
- Click Remove All.
- Click the three dots on the right upper of the Google website.
- Choose Settings (Command + Comma) in the pop-up menu.
- Click Privacy and security in the left sidebar.
- Click Clear browsing data.
In Microsoft Edge:
- Click the three dots on the right upper of the Microsoft Edge website.
- Choose Settings.
- Choose Privacy and Services in the left sidebar.
- Click "Choose what to clear" below Clearing browsing data.
- 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:
- Check System Settings in Dock.
- Choose Network in the left sidebar of the pop-up window.
- Choose the network that you want to change the DNS server, such as Wi-Fi or Ethernet.
- Click Details, and then select DNS in the left sidebar.
- Click "+" at the bottom of the DNS Servers list, then enter the IPv4 or IPv6 address for the DNS server. Enter 184.108.40.206 for the Preferred DNS server, and enter 220.127.116.11 for the Alternative DNS server.
- Click OK to save your settings.
Change DNS servers on Windows:
- Open Settings, and click Network and Internet.
- Scroll down and click Change Adapter Options.
- Right-click the network (Wi-Fi or Ethernet) you want to change the DNS server.
- Select Internet Protocol Version 4 and click Properties.
- Select Use the following DNS server address, and then type in 18.104.22.168 for the Preferred DNS server and 22.214.171.124 for the Alternative DNS server.
- 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:
- Open Terminal by using the Spotlight or press Command + Space.
- Type in Terminal and double-click to open it.
- Type in the following command.
sudo dscacheutil-flushcache; sudo killall -HUP mDNSRespnoder
- Enter your Mac's password.
- Press Enter to finish.
Clear DNS cache on Windows:
- Right-click the Windows icon and choose Windows Terminal (Admin).
- Click the down arrow icon and choose Command Prompt (or press Ctrl + Shift + 2).
- Type in the following command.
- 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:
- Click System Settings in Dock.
- Choose Network in the left sidebar.
- Select Firewall and switch the setting to Off.
Disable the firewall on Windows:
- Click Win > Settings.
- Select Privacy & Security > Windows Security > Firewall & network protection.
- Select both Private network and Public network.
- Under Microsoft Defender Firewall, switch the setting to Off.
If this post helps you solve the problem, share your happiness with your friends.
FAQ about 502 Bad Gateway
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.
Because 502 Bad Gateway errors are often caused by issues between online servers that you have no control over.
Yes. Sometimes, a fault firewall configuration will cause your firewall to block requests from a content delivery network as an attack on your server and reject them, resulting in 502 Bad Gateway.