What is a 502 Bad Gateway Error? Causes and Quick Fixes

A 502 error is a server-related issue that can impact your online business. Learn what causes the bad gateway and how to fix it.
We receive compensation from the products and services mentioned in this story, but the opinions are the author's own. Compensation may impact where offers appear. We have not included all available products or offers. Learn more about how we make money and our editorial policies.

A 502 bad gateway error means that one server received a confusing message from another web server.

Since the communication wasn't clear, a 502 error message appeared instead of the website. The invalid response can impact traffic and stop visitors from browsing your website.

Learn why 502 errors happen, how to fix them, and ways to avoid them in the future.

In this article
What is a 502 bad gateway?
Common causes for a 502 bad gateway error
5 ways to fix a 502 bad gateway error
Ways to prevent future 502 bad gateway messages
FAQs
Bottom line

What is a 502 bad gateway?

A 502 bad gateway error occurs if there's a server miscommunication. It's one of many HTTP error codes that can happen when visiting a website.

In a normal situation, a user’s computer sends a message to a server, which retrieves the website and sends it back to the user’s computer to be displayed.

But sometimes you may get a 502 bad gateway error. It indicates that one of the servers sent a “bad” or confusing message that resulted in the website not loading.

Visitors might encounter a 502 bad gateway due to a temporary glitch with their network connectivity. In this scenario, the user might solve the problem by refreshing the webpage or restarting the modem.

More commonly, however, 502 errors are a server or network issue that the site owner needs to fix.

Common causes for a 502 bad gateway error

Many issues can cause a 502 bad gateway error. Here are a few of the most common reasons:

  • Server downtime or overload: Servers can get overwhelmed with sudden spikes in traffic, especially if the site is using shared hosting with limited resources. If a server receives too many requests, it may slow down its response time.
  • Domain Name System (DNS) issues: The DNS server connects a web address with its IP address. Errors in communication can cause 502 errors, like DNS servers going down. DNS issues can also occur if you have recently changed hosting providers.
  • Security settings: Web hosting can have strong security settings that can inadvertently cause 502 errors. An overly cautious or misconfigured firewall can block legitimate requests.
  • Poor or buggy coding: The site may have faulty coding in plugins or themes. Bad code can introduce a bug and crash the server.

5 ways to fix a 502 bad gateway error

Fixing a 502 bad gateway error is a matter of assessing your current settings and repairing the problem. Start by making sure it's not a device issue. Refresh the page, restart the modem, and clear the browser cache.

If that doesn't work, the site's server may be causing the problem. Here are 5 troubleshooting methods site owners can use to solve the issue:

1. Confirm DNS settings

Moving your site from one hosting provider to another can cause 502 errors. In this case, the internet may still reference the old IP address instead of the new DNS record.

Acknowledging the change can take anywhere from a few minutes to 48 hours. More than 48 hours could signal a 502 error. Check for misconfiguration on the DNS servers, flush the DNS cache, or contact the hosting provider for help.

If you haven't changed the DNS records, it could mean the DNS servers are down. Reaching out to the hosting provider can help troubleshoot the problem.

2. Assess server and resource usage

Your server might get overwhelmed by too many traffic requests or low memory. The hosting control panel usually has monitoring tools to track the server's central processing unit (CPU) and random access memory (RAM) usage. High usage indicates that the server is overloaded.

Causes include legitimate high traffic spikes, a bot attack, or a buggy script. Depending on the problem, you may need to upgrade to a premium server, review your site’s security protocols, or troubleshoot plugins.

3. Check upstream servers

There's a hierarchy of servers, and upstream servers sit at the top of the communication chain. If any server experiences downtime, it can affect website requests and cause a 502 error.

You'll want to check that all servers are working. Many hosting control panels have a section for reviewing server status.

If everything looks normal, reach out to your web hosting provider to share your problem. Its tech support can verify that all of its servers are functional.

4. Verify firewall settings

A firewall is a great tool for monitoring traffic and protecting your site from malicious bots. However, if it's misconfigured or too aggressive, it can block legitimate traffic. This misinterpretation can cause 502 errors.

Take a look at the security logs to see if any traffic was blocked. If you find that the firewall blocked an authentic request, whitelist the IP address to unblock it.

5. Uninstall plugins or themes

Plugins and themes could have poor coding that causes server issues. Even reliable extensions could receive an update that creates problems.

Figuring out which plugin or theme triggered the error can be complicated. Instead of investigating each one, disable them all. Then, turn them on one by one. This helps isolate which one is causing server issues.

Ways to prevent future 502 bad gateway messages

Maintenance is the best prevention for 502 bad gateway messages. Some of these tasks are done by the hosting provider, but as the site owner, there are steps you can take to prevent 502 errors:

  1. Ensure your server capacity is adequate. Checking server resources can help determine if you need to upgrade to premium hosting types, like dedicated hosting. Scalability is important when considering a web hosting provider. If you experience occasional high traffic spikes, another option is to set up load balancing. This spreads traffic across multiple servers to prevent overload.
  2. Stay on top of your site’s uptime. Reviewing your site's uptime can help identify early signs of server overload. A tool like UptimeRobot can help monitor your site's uptime and identify any significant dips.
  3. Routinely update DNS/SSL configurations. Monitor your DNS records, especially after a change in web hosting, to ensure they have the proper configuration. Your Secure Sockets Layer (SSL) certificate is what encrypts data between servers. Don’t let your SSL certificate expire, as it can stop visitors from viewing your site.
  4. Run the most recent software version. Keeping software updated ensures that coding is compatible and has the latest patches to protect from cyberattacks.
  5. Optimize caching. Enabling caching and effective content delivery networks (CDNs) can create copies of your site on other servers. Spreading out files across multiple servers can reduce overload and speed up content delivery.

FAQs

How do I resolve a 502 bad gateway error?

As the site owner, you can resolve 502 errors by verifying server functionality, DNS settings, and security tools. You may also want to troubleshoot plugins and themes to see if they are causing a bug. If all else fails, contact your provider’s tech support team to report the problem.

Does a 502 bad gateway mean I'm blocked?

No, a 502 Bad Gateway error doesn't mean you're blocked. However, you may have received a notification that prevented you from seeing the site. A 502 error message indicates that servers are receiving or sending invalid requests, which prevents a site from loading.

Is a 502 bad gateway a hack?

A 502 bad gateway isn't a hack. It's a common technical error that occurs when servers are miscommunicating. Bad or unreadable responses are transmitted between servers, which prevents a site from loading.

Is a 502 bad gateway permanent?

No, a 502 bad gateway isn't permanent. It's a temporary issue, and servers often fix themselves. As a user, refreshing your page can resolve the problem. Other times, a site owner may need to reconfigure hosting settings to get a server operating again.

Bottom line

A 502 bad gateway is a common error, but site owners can fix it by checking DNS records, security settings, and plugins. This can help clear barriers that are blocking servers from operating.

Choosing a scalable web hosting service can help manage your site as your traffic grows. Bluehost and IONOS are just a few reliable web hosting providers for sites that need scalability.

4.9
Editorial Rating
Learn More
On Hostinger web hosting's website
Website Hosters
Hostinger web hosting
BLACK FRIDAY: Up to 80% Off
  • Robust user-friendly AI tools for quick web building
  • Cheaper than other all-in-one ecommerce web host & builders like Wix and Shopify
  • Passed tests for reliability and speed

Author Details
Sara J. Nguyen is a writer specializing in cybersecurity. She aims to help people protect their data while enjoying technology. She has written about online privacy and tech for over 5 years for several organizations. When she's not writing about the latest cybersecurity trends, you can find her on LinkedIn.