This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

How to Fix the “502 Bad Gateway Error” in WordPress (10 Easiest Methods)

Updated on December 21, 2021

8 Min Read
fix 502 bad gateway error in wordpress

WordPress is easy, but it is equally frustrating to troubleshoot the errors that can occur at any time. Just like prescribing the right medicine to fight disease effectively, you need complete knowledge about that disease. Knowing the error and its causes are essential before troubleshooting it.

When your website has the 502 Bad Gateway Error, it’s like solving a mystery. You don’t know what exactly happened or why you expect that something is wrong, and you need to fix it. In this article, I’ll tell you about the 502 Bad Gateway Error and how you can fix it in your WordPress.

What Is the 502 Bad Gateway Error?

To understand the 502 Bad Gateway Error, you should know how a browser loads data from the server. When a user visits a website, the server sends a request to fetch the data required to display the content in the browser.

If the server responds accurately to the requests, it receives the requested content. Otherwise, the 502 Bad Gateway Error screen comes up.

WordPress websites run on multiple servers allocated to a specific task. For example:

  • Database server for WordPress databases,
  • Application server to run PHP and other app-related content,
  • The reversed proxy server responsible for Nginx, Apache, Varnish,
  • Web server to serve website files.

The multiple servers together can complicate the way the browser handles the requests. Upon receiving the request, the reversed proxy server fetches data from origin servers like a database server, application server, and web server.

If any of these servers send an invalid response, the reversed proxy server returns to the browser and displays a 502 Bad Gateway Error.

We often see 502 Bad Gateway Error differently on different websites, but they all point to the same: the server could not respond to the requests. Let us look at some of the examples this error shows.

  • “502 Bad Gateway”
  • “HTTP Error 502 Bad Gateway”
  • “502 Service Temporarily Overloaded”
  • “Error 502”
  • “502 Proxy Error”
  • “HTTP 502”
  • “502 Bad Gateway NGINX”
  • “502 Server Error: The server encountered a temporary error and could not complete your request”
  • “502. That’s an error. The server encountered a temporary error and could not complete your request. Please try again in 30 seconds. That’s all we know.”

502 bad gateway nginx

Twitter displays 502 Bad Gateway Error in a friendlier way.

twitter 502 error

Google displays a 502 Bad Gateway Error with the suggestion of trying again after some time.

google 502 error

Now that we have understood what is 502 Bad Gateway Error is and how different websites display it. Let us move ahead and explore what causes this error and how can we fix it in WordPress?

Why Does 502 Bad Gateway Error Occur in WordPress?

We get a 502 Bad Gateway Error when the server fails to respond accurately and returns the request with invalid information. However, there are other possibilities as well, and knowing them is crucial if you wish to troubleshoot this error effectively.

  • Your server is busy with other tasks or hit by traffic spikes
  • Origin servers are unresponsive or inaccessible
  • Errors in the database
  • Problem with the reverse proxy server
  • Corrupt PHP scripts in WordPress files
  • WordPress CDN is acting up
  • DNS issues

All of the above possibilities can result in WordPress 502 Bad Gateway Error. However, troubleshooting any error gets trickier if you do not know the elements involved in triggering that error.

How Does 502 Bad Gateway Affect the SEO

If your site often goes down because of the 502 Bad Gateway error, it will also affect your site’s traffic. Imagine your visitor gets this error on your site; he might not visit your site next time. Similarly, it will impact the crawling and indexing of your site due to unavailability. Hence, you will lose your organic ranking and traffic.

Fix 502 Bad Gateway Error in WordPress

These are the easiest methods to fix the 502 Bad Gateway Error in WordPress.

  1. Check Hosting Server
  2. Reload Web Page
  3. Clear Browser Cache
  4. Check DNS Issues
  5. Clear DNS Cache
  6. Disable CDN/Firewall
  7. Audit Themes/Plugins
  8. Check Error Logs
  9. Set PHP Timeout
  10. Check Custom Scripts

1. Check Hosting Server

The first thing you need is to check if your web server is responsive or not. It is not always something terrible happening to your WordPress website. The easiest way to determine if your server is the culprit is to run an online scan. Visit site24x7 and enter your site URL.

online site scan

The multiple locations will ping your server and show you the stats like Load time, Package Loss, and Response time.

Another way to check your web server’s responsiveness is to ping it manually using SSH. Simply access the SSH terminal and run the following command:

ping (server IP)

Now, replace “server IP” with your server IP address.

ping server ip

If your server is responsive, it will show the ping on each interval.

Sometimes any query or task takes more time than usual; the server cancels it and returns with a 502 Bad Gateway Error. It is common in shared hosting, and the provider kills the script to avoid any negative impact on other websites hosted on the same server.

If you are using Cloudways, you will have a low chance of getting this error. That is because you are the only owner of your server and control the websites hosted on it, and we use a powerful stack that can cope with a load on servers.

However, if you still encounter such issues, Cloudways’ 24/7 live chat support can help you recover from this situation.

2. Reload Web Page

Sometimes just by reloading the web page, you can save hours’ worth of troubleshooting. It is possible that you get an overloaded server for some time and when you check back in a minute or so, it brings back on.

Also, confirm if the website is down for you or everyone else. Test the URL on Down for Everyone or Just Me to do this.

down for everyone or just me

If the website is up for everyone else, then the problem is at your end. Try switching the web browser.

3. Clear Browser Cache

The browser caches or stores site data so the next time the user visits, it does not have to repeatedly download the same static content. It is an effective way of utilizing resources but has some drawbacks.

Let’s say you went to a different browser and the web page loaded just fine. Knowing that your web page loads correctly, you return to your default browser, but the issue persists. That is because your browser displays the cached copy of that web page. To fix that, clear your browser cache via Ctrl+Shift+Del (for Windows) or Shift+Cmd+Del (for Mac).

clear browsing data

4. Check DNS Issues

A Domain Name System (DNS) is a way of linking a domain name with an IP address. If the domain fails to resolve to the correct IP, it can trigger a 502 Bad Gateway Error. It commonly occurs while migrating a WordPress site to a new host that requires changes in the DNS name server.

The DNS changes can take between 24 to 36 hours to propagate. If you try to access your site during this period, you might get a WordPress 502 Bad Gateway Error.

5. Clear DNS Cache

You can clear the DNS cache from Windows Command Prompt. In Windows, run ipconfig/flushdns command to clear the DNS cache. In Mac, run the command as dscacheutil -flushcache inside the terminal window.

clear dns cache

6. Disable CDN/Firewall

If you use a CDN service or a firewall on your website, their servers may be acting up.

A CDN serves static website content and loads your site to a global audience faster. In contrast, a firewall protects your site against DDoS and other online attacks. However, A CDN/firewall can be one of the reasons for the 502 Bad Gateway Error in WordPress due to an extra layer between the server and browser.

To cross this from your list of possible causes, simply disable your CDN/firewall and then try to access your website. If the website loads correctly, then you have caught the culprit. You just need to contact CDN/firewall service provider to get it fixed.

7. Audit Themes/Plugins

A fully functional WordPress site is nearly impossible without adding themes and plugins. But they can also become one of the reasons for the 502 Bad Gateway Error. The problem lessens with the best wordpress plugins, but the threat of 502 error lurks with them as well. If they are not well-written, they can cause issues with your web server or take too long to process the requests. The problem can arise even if you work with the best wordpress themes for your website.

Start by deactivating all the plugins from FTP. Simply access your root directory where your WordPress files are installed, i.e., public_html folder, navigate to wp-content → plugins, and rename the plugins folder so it will become inaccessible to your site.

rename plugin directory

Now check your website to see if it loads correctly, then you can start activating plugins one by one until you find the one causing 502 Bad Gateway Error.

Look for a defective theme if you don’t find any faulty plugins. Go to your wp-content folder, navigate to themes and rename your activated theme to deactivate it. But remember, removing your theme might not be suitable as uploading it again can lose custom styling.

rename theme directory

In the next step, refresh your website and if you see a white screen instead of an error, then your theme was causing the issue. Log in to your wp-admin and activate the default WordPress theme.

8. Check Error Logs

WordPress logs are useful when it comes to troubleshooting errors. You can enable the error logs by adding the following code inside the wp-config.php file.

define( 'WP_DEBUG', true );

define( 'WP_DEBUG_LOG', true );

define( 'WP_DEBUG_DISPLAY', false );

The logs are located inside the wp-content folder. If you’re a Cloudways user, you can take advantage of the integrated monitoring tool New Relic for precise and comprehensive analysis.

new relic in cloudways

9. Set PHP Timeout

When PHP reaches the maximum time in server configuration to execute a script, it shows an error. It can sometimes trigger WordPress 502 Bad Gateway Error. To avoid this, simply increase the maximum execution time value. It is set to 300 seconds by default, which is 5 minutes.

10. Check Custom Scripts

We create custom functionality and themes in WordPress. Sometimes, our web server doesn’t process these custom functionalities. Also, calling third-party APIs, such as Google reCAPTCHA, which generates long tokens, can stress the server and show the 502 Bad Gateway Error.

Summary

After reading this article, I hope 502 Bad Gateway Error will not look so scary the next time you see it. The troubleshooting is easy if you can predict the source and use the techniques listed in this article to fix it.

You can still fix the WordPress 502 Bad Gateway Error just by reloading and clearing the browser cache but not every day is sunny, so it is wise to prepare for the dark.

Frequently Asked Questions

Q: What causes a 502 Bad Gateway Error?

A: When you get an invalid response on your browser when trying to visit your site causes the 502 Bad Gateway Error.

Q: How do I fix Google 502 error?

A: You can fix the 502 Bad Gateway Error by following these methods:

  • Check Hosting Server
  • Reload Web Page
  • Clear Browser Cache
  • Check DNS Issues
  • Clear DNS Cache
  • Disable CDN/Firewall
  • Audit Themes/Plugins
  • Check Error Logs
  • Set PHP Timeout
  • Check Custom Scripts

Q: Is 502 Bad Gateway a virus?

A: No, it’s not a virus. You get the 502 error because of the bugs in your PHP. Server configuration or network error among servers can cause 502 Bad Gateway.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Customer Review at

“Beautifully optimized hosting for WordPress and Magento”

Arda Burak [Agency Owner]

Ibad Ur Rehman

Ibad Ur Rehman is a WordPress Community Manager at Cloudways. He likes to explore the latest open-source technologies and to interact with different communities. In his free time, he likes to read, watch a series or fly his favorite Cessna 172SP in X Plane 11 flight simulator.

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!