WordPress Managed Hosting - 100% Off For 3 Months - Coupon Code: WPB30 Avail Now

How to Fix a 502 Bad Gateway Error on Your WordPress Site

Farhan Ayub — February 3, 2020 6 Minutes Read
502 bad gateway

There are numerous errors that usually appear on your WordPress site, but one of the most frustrating and annoying errors is “502 Bad Gateway Nginx”.

Before we learn how to fix it, though, we need to understand 502 bad gateway WordPress, what it means, and how it appears on your browser. Once you understand why it shows up for your website or any other site that you visit, fixing WordPress 502 error will be a lot easier.  

What does 502 Bad Gateway Error Mean?

502 bad gateway error is a server error that appears when your web server doesn’t send any response to your browser or is unable to establish a connection with your browser.

Whenever a client/user visits a website, the browser sends an HTTP request to the webserver. The web server processes the request, initiates action and sends an HTTP response to your browser. That’s when the site’s content appears on your browser. 

But, when the web server sends an invalid response or none at all, then instead of serving your web content, it displays the dreaded 502 bad gateway error on the browser.

Different web server displays this error in different ways. Sometimes you will see the error like this:

  • 502 Bad Gateway Nginx
  • Temporary Error 502
  • Error 502
  • 502 Server Error
  • HTTP 502
  • White Screen
  • 502. That’s an error
  • 502 Proxy Error
  • HTTP Error 502 – Bad Gateway
  • 502 Server Error: The server encountered a temporary error and could not complete your request

In essence, 502 bad gateway is a server-level misconfiguration but sometimes it appears due to other factors like when your web server takes too much time to respond due to a poorly coded theme or plugin installed in your WordPress site. It can also appear due to high traffic on your Website, server connection break, DNS issue, browser cache or other reasons.

So now that you know what 502 Bad Gateway error means, I’m going to show you some popular and effective hacks through which you can easily fix the 502 Bad Gateway error.

How to Fix a 502 Bad Gateway WordPress Error?

Whenever I’ve faced a 502 error in WordPress, there are 7 hacks that I usually try and fix this issue. Similarly, you can also use the following methods to troubleshoot the 502 error:

1. Try Reloading the Page

When any WordPress site faces high traffic, the server gets overloaded and displays this error. You need to wait for a few minutes and then try reloading the page because this error is temporary and automatically resolves in a few minutes.
If this works then you don’t need to read further. But if it doesn’t, then check the other solutions as well.

You can also check your website on https://downforeveryoneorjustme.com/ to check if it’s down for you only or for everyone else.

check site is down or not

2. Clear Browsing Cache

When you visit any website, your browser saves its content and data in the cache to reduce page load time when you visit that site again.
Similarly, your browser stores the 502 error content and data in the cache and displays the error page again and again. If you simply clear the cache, it might solve the issue straight away. 

3. DNS Issue

If you’ve recently migrated your WordPress site to a new host then you might see the 502 bad gateway error. Basically, website migration takes time, around 24 to 32 hours to fully move your website to a new host, hence you need to wait for the time period and check your website again. 

4. Disable CDN

A CDN or Content Delivery Network is a system of networks that stores static data on your website. It’s an extra layer between the server and browser that helps boost your site speed. If you’re using a CDN service on your WordPress site, it’s possible that the “error 502” is caused by its services.

If that’s the case,  you need to disable your CDN. Once disabled, visit your WordPress site and see if the error is resolved or not.

If the error is resolved, then contact your CDN providers for support because there’s an issue with your CDN service that’s causing this error. If the error persists, keep reading to find out what you can do further.

5. Check your Plugins and Themes

Poorly coded plugins or themes are one of the most common reasons that cause Error 502. First, you need to find out which plugin is causing this error and for this, you need to access your web server via an FTP client and deactivate all the WordPress plugins. 

Open FileZilla FTP client and fill the respective fields to access your web server, then go to your plugins directory through applications > (your DB folder) > public_html > wp-content and rename the plugins folder to anything you like. I changed it to Originalplugins”.

Plugins rename

Create a new empty folder/directory and name it “plugins”.

Create plugins directory

The plugins folder is empty and the Originalplugins folder contains all the plugins.

2 plugin folders

Now visit your WordPress site, and if it runs without the error then it means one of your plugins caused this error. 

Next, you need to delete the empty plugins folder and change the name of the “Original plugins” folder to “plugins”.

change plugins folder name

You will see that all the plugins are deactivated. Start activating the plugins one by one and visit your website after each until you catch the plugin that’s causing the error. Once you find the culprit, you can either use an alternative plugin, or you can contact the current plugin’s support to resolve the issue.

WordPress installed plugins

If this doesn’t solve the issue as well, you need to check for a faulty theme. For this, you need to change the name of the activated theme folder name to anything that you like and follow the same steps that we used for the plugins. 

Now visit your website, if you see a white screen then it means your theme is faulty. Just login to your wp-admin and activate the default theme. 

6. Increases PHP Execution Time

If even that doesn’t fix the error, then it’s time to check PHP execution time, which is a common reason that causes 502 bad gateway errors in WordPress. You can resolve this issue by increasing the PHP execution time. For this, you need to access the .htaccess file via FTP and paste the following code or change the previous code with this to increase the max execution time and max input time. 

  1. php_value max_execution_time 300
  2. php_value max_input_time 300

Recommendation: 

  • Set the max execution 300 sec (5 mins) and above for large and high traffic websites
  • Set the max execution 300 sec (5 mins) and below for small and low traffic websites

7. Checking Hosting Server

If all the above solutions aren’t working and you still have a 502 bad gateway WordPress error on your web site then you need to check your hosting service. Contact your hosting provider’s support and they will help you resolve server misconfiguration issues.

Conclusion

Now you know what WordPress 502 bad gateway error means and that it’s a server-side error and appears on your website due to high traffic, PHP timeout, DNS issue, and other reasons. The above-mentioned solutions, though, can help you easily fix 502 bad gateway errors.

I hope this tutorial helped you learn “How to fix 502 Error in your WordPress site?

If you found this tutorial useful, don’t forget to share it in your circle. And of course, if you need guidance on anything related to WordPress, just comment below or you can email me at farhan@wpblog.com.

Create Faster WordPress Websites!

Free eBook on WordPress Performance right in your inbox.


Create Faster WordPress Websites!

Free eBook on WordPress Performance right in your inbox.

Farhan is a community manager at WPblog. He loves to work with WordPress and has a passion for web development. Mostly, he spends his time interacting with the people in the WordPress community. Apart from his work life, Farhan spends his time gaming and playing sports. Feel free to contact him at Farhan[at]wpblog.com.

THERE'S MORE TO READ

Newsletter

WordPress Help Zone - Ultimate WordPress Pit-Stop

Learning WordPress? Or are you expert enough to help others? Join our WP Facebook group!