Skip to main content

How to Fix a 502 Bad Gateway Error in WordPress

Blog image

When it comes to WordPress, there might be a lot of different errors that cause lost revenue, poor performance, and low SEO rankings. The most common one is a 502 bad gateway error. 

Although this issue is quite frustrating, there are several easy ways to fix it. In this blog post, we will show you how to fix a 502 bad gateway error in WordPress. 

What is 502 bad gateway?

When you visit any website, your browser sends a request to the hosting server. The hosting server looks for the requested page and sends it back to the browser. A 502 error occurs when WordPress hosting server gets an invalid response for the requested web page.

The 502 bad gateway takes many different forms:

  • Error 502
  • 502 Bad Gateway
  • 502 Bad Gateway NGINX
502 bad gateway error

 

  • 502 Proxy Error
502 proxy error
  • 502 Service Temporarily Overloaded
  • HTTP 502
  • 502 Server Error

What are the Reasons for 502 Bad Gateway Error?

Usually, the 502 error occurs due to the problems on the server side. However, it can also happen on your side. Here are the reasons why you might face a 502 bad gateway error:

  • issues with your content delivery network (CDN)
  • bugs in the database of your WordPress website
  • DNS issues
  • problems with the reverse proxy server
  • the server may be overloaded
  • issues in the PHP code because of a plugin or theme

and more.

Now, when you have understood what is a 502 error and why it happens, it’s time to explore how you can fix it in WordPress.

How to Fix a 502 Bad Gateway Error in WordPress?

  • Try reloading a web page

Easy as it is, just reload a web page. Sometimes it works and saves you hours of troubleshooting. It is possible that the server is overloaded at the moment and when you check it again in a minute or so, it works.

Besides, check if the website is down for everyone or just you on Down For Everyone Or Just Me. If the platform is up for everyone but you, the issue is at your end.
 

  • Clear your browser cache

Try to perform a hard-refresh on your browser (CTRL + F5 on Windows systems and CMD + CTRL + R on OS X systems) or try to clear your browser cache directly. Go to Settings > Advanced and look for Clear Browsing Data feature. Proceed to Basic tab and find Cached Images and Files option. Select it and click on Clear Data. All the cache will be cleared, along with your browsing data.

If you are still facing a 502 bad gateway error, follow our next tips.

  • Check your themes and plugins

You cannot have a fully functional website without adding themes and plugins. However, they can also become a reason for WordPress 502 gateway error. 

If PHP code in a theme or plugin is incorrect, the server will not be able to understand it or it will take too long to process. This results in a 502 gateway error. 

To fix WordPress plugin errors, deactivate all the plugins from FTP. Access your root directory with installed WordPress files, navigate to wp-content > plugins and rename the plugins folder, so WordPress system cannot access it. After that check your website. If it loads properly, start activating plugins one by one until you find the plugin which causes the problems.

If all the plugins are good, check your themes. Inside your wp-content folder proceed to themes and rename your active theme in order to deactivate it. Go back to you site. If you see a white screen instead of a 502 error, your theme was causing the problems. Log in to the wp-admin and activate the default theme.

  • Look for DNS issues

Domain Name System (DNS) links domain name with the IP address. If the domain fails to resolve to correct IP, you get a 502 bad gateway error. This errors usually occurs when migrating WordPress website to a new host, which requires changes in DNS name server.

If you’ve just migrated your WordPress website to a new host, you’ll have to wait up to 24 hours for things to get done. You can also try flushing your local DNS cache, which is similar to clearing your browser cache.

You can also temporarily change your DNS server. By default, DNS servers are assigned by internet service provider (ISP). But you could try to change them to a public DNS server, such as Google.

  • Disable your CDN

Content Delivery Network (CDN) is a network of servers located all over the globe. CDN caches your static content and delivers it to the servers closest to them. In such a way, users receive that content immediately. However, CDN might be one of the reasons of WordPress 502 gateway errors because of the additional layer between the server and browser.

To fix this issue, simply disable CDN for some time. If the website loads properly when CDN is disabled, contact CDN support for additional fixes.

  • Restart PHP

Restarting PHP might also help. However, it is better to contact WordPress support team in order to do things right.

If you still receive a 502 bad gateway error, contact your host.

If you still can’t fix a 502 bad gateway error on your WordPress website, contact your host provider and get professional assistance. Probably something goes wrong on their side.

To Conclude

It is easy to fix WordPress 502 bad gateway error if you know the source of the problem. Besides, you can always rely on the team of web professionals and receive the required assistance as soon as possible.