502 Bad Gateway Error: What It Is and How to Fix It

502 Bad Gateway Error: What It Is and How to Fix It thumbnail

Experiencing a 502 Bad Gateway error? Don’t brush it off too quickly. While a simple refresh often resolves a one-off, recurring errors might signal deeper issues.

If left unattended, these can snowball into significant challenges: Dwindling traffic, poor user experience, and elevated security risks, to name a few.

It’s important to root out the cause of the issue as soon as possible, whether it’s WordPress errors or something else.

The bad news: A variety of potential server-side issues could be throwing the error. The good news is that those error codes you see? They’re your map to effective troubleshooting.

We’ll explain in simple terms what the 502 Bad Gateway error is, why it happens, and most importantly, how to make it disappear.

Let’s get started.

What Is The 502 Bad Gateway Error?

First of all, a little bit of a crash course on what’s going on behind the scenes may help everything make a bit more sense. After all, knowledge is power, right?

Every time you enter a URL into an address bar and attempt to access a site, your browser sends a request to that site’s server. The server processes that request and then displays the website’s content.

DreamHost Glossary

Server

A server is a computer that stores data. A web server is a type of server that stores and delivers web pages to users. Web servers are connected to the internet and use HTTP to send web pages to users who request them.

Read More

If something were to go wrong, you would instead see an HTTP status code. Then the fun begins.

You’ve probably faced a 404 error (page not found) at least once, if not a hundred times. It’s saying the server was able to process the request, but couldn’t locate the specific page or content.

In contrast, a 502 Bad Gateway error happens when there’s a communication breakdown between two servers. The first server relayed the message but received an invalid response from the upstream (or next) server.

In other words, the server, which acts as a gateway or proxy, received an invalid response from an inbound server and was not able to fulfill the request.

Depending on the browser you use, the status may appear in a handful of different ways:

  • 502 Bad Gateway
  • 502 Proxy Error
  • Error 502
  • HTTP Error 502 – Bad Gateway
  • Temporary Error (502)
  • 502 Service Temporarily Overloaded
502 Bad Gateway

The HTTP 502 server error isn’t limited to a problem with a proxy server or server overload, so let’s dig in a little further and look at some common causes.

What Causes The 502 Bad Gateway Error?

Several issues can return a 502 Bad Gateway error. These include:

  • An unresolved domain name – There could be connectivity issues between the domain name and your IP address. This often happens when a website recently migrated from one web host to a new hosting provider, and the DNS server hasn’t had time to propagate.
  • An oversensitive firewall – If your website (perhaps a WordPress site with a firewall plugin) or your web host has firewall settings that are too restrictive, some Internet providers or IP addresses may be blocked. This can happen when the firewall detects them as a false threat.
  • Server overload – A sudden spike in traffic can cause the origin server to crash. If your website’s server is on a shared hosting plan, your traffic can be impacted by everybody else’s traffic (like your neighbors are having a big party, and their guests are taking up all the parking spots.)

Having said the above, it should be noted that the 502 Bad Gateway error isn’t restricted to problems with the server. Client-side issues such as outdated browsers or corrupted files in the browser cache can also be a cause of the status error.

How Do You Fix The 502 Bad Gateway Error? (9 Possible Solutions)

Now, let’s look at how to fix the 502 Bad Gateway error! We’ll cover two scenarios: an issue on the client side and a problem with the server.

1. Refresh The Webpage And Try A Different Browser

We should always start with the simplest solution. The 502 Bad Gateway error could be a temporary issue. For example, the web server may have become overloaded for a few minutes or experienced a brief surge in traffic.

Try waiting a few minutes and refresh the page. If that doesn’t work, you can try accessing the same site using a different browser. If that works, then the issue may be with the original browser. If the page still doesn’t open, the website itself may be the problem.

Another way to determine whether the problem is on your end or at the web server is to use a tool like Down for Everyone or Just Me, or Is It Down Right Now to confirm whether the problem is on your end or with the site’s host.

Down for Everyone or Just Me

Using one of these tools will identify the status of your site. If your site isn’t down for everyone, you’ll need to troubleshoot on your end, and the first several steps below will help with that. If your site is down for everyone, you’ll need to check into your site’s backend to find the source of the problem, which will be addressed later in the post.

2. Test Using Another Device

Assuming you’ve been using your computer and ISP, try to access your website from your cell phone. First, go to your phone’s settings and turn off your wifi, then make sure your mobile data is enabled. If you’re able to access your site, the problem is at your end, and rebooting your network may fix the issue.

To reboot your network, shut your computer down, then unplug your modem and router. If you have an integrated modem and wifi router, unplug it, wait for about a minute, then plug in your modem and let it reboot. Then plug in your router and let it boot up. If you have integrated hardware, plug it in and let it boot.

Finally, start your computer and try to access your site.

3. Clear Your Browser’s Cache

Browsers store a lot of data, primarily to help pages load faster the next time they’re opened. However, your browser cache may contain outdated site data or corrupted files, leading to the Bad Gateway error.

Based on this, the next thing to do is clear your browser cache. Depending on which browser you use, steps may vary.

If you use Mozilla Firefox, access the hamburger menu (three horizontal bars) at the top right. Go to History > Clear recent history.

Clear Recent History

From there, you’ll open a new menu and further options. If you were able to access your site without issue yesterday, then you can choose Today in the time range field, select Cache — you can deselect the other options if you want — and then click Clear Now.

Clear Cache

For the most part, the process will be much the same if you’re using Google Chrome, Microsoft Edge, Safari, or something else. If you’re unsure, check the process for clearing cache in other browsers for specific details.

If you try to access your site after clearing the cache and still get a status error, move on to the next step.

4. Flush The DNS Cache

A 502 Bad Gateway error could also be caused by a Domain Name System (DNS) issue. For example, if you’ve just migrated your site to a new web host, the propagation process can take up to 48 hours.

However, the issue may also originate with your local DNS cache. This temporary storage on your device contains information about previously visited domain names.

If you’re using Windows, you can flush the DNS cache using the Command Prompt. To access it, type “CMD” into the Windows search on your taskbar, and press Enter.

You’ll now have access to your Command Prompt.

Command Prompt

Once the Command Prompt box is open, copy or type the following command:

ipconfig /flushdns

Let it run. When it’s finished, you’ll see a message that says, “Successfully flushed the DNS resolver Cache.”

DNS Resolver Cache

If you’re using a Mac operating system, enter or copy the following command in the terminal.

dscacheutil -flushcache

If you’re uncomfortable doing either of these, you can also use a third-party service such as Google Public DNS to temporarily change your DNS server.

5. Check Your Site’s Error Log

If your site is down for everyone and the problem is local, you can also check your site’s error logs, which may help you identify the cause of your issue. For example, it may flag a plugin conflict or update as the source of your 502 Bad Gateway error.

Your website’s log files can be accessed via a Secure File Transfer Protocol (SFTP) client, such as WinSCP or SmartFTP. Once you’ve installed your client of choice, DreamHost provides a comprehensive Knowledge Base entry on accessing your error logs via SFTP.

DreamHost Glossary

SFTP

Secure File Transfer Protocol (SFTP) is a safer version of the FTP protocol that uses a secure shell data stream.

Read More

6. Deactivate Your Plugins And Themes

Although it doesn’t happen often, a new or updated plugin or theme can cause conflict with other plugins or tools, resulting in a 502 Bad Gateway error.

Since you can’t access your WordPress admin dashboard, you’ll need to deactivate your plugins and themes using an SFTP client.

Once you’ve installed or logged into your SFTP client (see the section above for options) please refer to this DreamHost walkthrough for the steps to deactivate/disable your plugins. Note that you have the option of deactivating all of your plugins at the folder level or any single plugin of choice, perhaps the ones you’ve most recently updated or added.

When you’ve completed that step, try accessing your site again. If it’s up and running, log into your dashboard, access your plugins menu, and reactivate each deactivated plugin individually. Each time, make sure you refresh the page to determine if you still have access to your dashboard.

If you identify that a plugin is causing the status code error, either disable or delete it until the developer has released a fix.

If the problem didn’t originate from one of your plugins, you can go through this entire process again, except this time, focus on your Themes folder. Or carry on to the next possible fix.

7. Disable Your CDN Or Firewall

If everything so far has failed, the next thing to check is your Content Delivery Network (CDN) or firewall. Note that your firewall could be a stand-alone plugin, part of your overall security plugin, or implemented by your host.

DreamHost Glossary

CDN

CDN is an abbreviation for “Content Delivery Network”. It refers to a geographically-distributed network of web servers (and their data centers). The entities that make up a CDN collaborate to ensure speedy content delivery via the internet.

Read More

If you’re using Cloudflare, you can check to see if there are any reported issues. For example, the server might be undergoing scheduled maintenance:

Cloudflare System Status

If maintenance isn’t the issue, you can also try deactivating both your CDN and firewall through your host’s control panel. Since all hosts do not use the same control panel, it’s recommended that you contact them for assistance.

8. Restart PHP And Increase Your PHP Limits

The 502 Gateway Error could also be caused by a PHP timeout issue. This happens when the PHP process takes longer than the maximum load time and the request timed out.

Restarting PHP may help resolve your connectivity issues. Most hosts provide an option to restart your services via your control panel but if you don’t see that, you may want to ask them to do this for you.

Unfortunately, changing your server’s max_execution_time or max_input_time values may be necessary. By default, WordPress has these values set to 300 seconds, but you can increase PHP execution time via your host’s control panel, or reaching out to their technical support and asking them to do it for you.

9. Contact Your Hosting Provider

If you’ve been through the previous steps and nothing has helped, it’s time to consider contacting your hosting provider. There may be a server issue that’s affecting your site. Unfortunately, if that’s the case, there’s nothing you can do except wait for them to fix it.

Additionally, they may be able to identify the source of your 502 Bad Gateway error and walk you through a solution. Many hosts offer 24/7 support via chat and should be able to resolve the issue quickly.

Solve The 502 Bad Gateway Error

The 502 Gateway Error is typically caused by a problem at the server. For instance, it may have experienced a spike in traffic that’s affecting performance and availability. However, the error could also be triggered by plugin conflicts and updates.

To troubleshoot the problem, start by clearing your browser cache and local DNS cache to rule out any issues on your end. Then, you can try disabling your plugins, themes, CDN, and firewall. If you’re still experiencing problems, consider contacting your hosting provider for assistance.

If you’re on a shared hosting plan, your 502 error may be because of another website’s traffic spikes. DreamHost offers VPS hosting that provides you with isolated resources and better performance, giving you more control and room to grow. Learn more about our VPS Hosting plans.

We Know You've Got Lots of VPS Options

Here’s how DreamHost’s VPS offering stands apart: 24/7 customer support, an intuitive panel, scalable RAM, unlimited bandwidth, unlimited hosting domains, and SSD storage.

VPS hosting provider
Photo of Luke Odom
About the Author:

Luke is the Director of IT Operations. He is responsible for the teams that keep operations running smoothly... In his free time, he enjoys reading fantasy/sci-fi and hanging out with his wife and 4 kids. Connect with Luke on LinkedIn: https://www.linkedin.com/in/luke-odom-039986a/