fbpx

How to Fix the 502 Bad Gateway Error in WordPress

fix the 502 bad gateway error in wordpress

If you are a site owner, one of the worst feelings is seeing a cryptic error message while trying to load your WordPress website. You may be familiar with the 404 Page Not Found Error, but are you ready to tackle the 502 Bad Gateway Error?

What Is a 502 Bad Gateway Error?

To learn more about the 502 Bad Gateway Error, you should have knowledge of how a browser loads data from the server. The server sends a request to fetch the data required to display when a user visits a website.

The requested content will appear if a server accurately responds to the requests. If not, the 502 Bad Gateway Error screen comes up.

WP sites run on numerous servers, each allocated to a specific task. For example:

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

The numerous servers together can complicate the way the browser manages the requests. After receiving the request, the reversed proxy server finds data from origin servers like web servers, database servers, and application servers.

If these servers send an invalid response, the proxy server returns to your browser, and you’ll see a page that will display a 502 Bad Gateway Error.

Why Do 502 Bad Gateway Errors Occur in WordPress?

One of the most common questions asked is about the reason why we see this error. You’ll see this error if the server fails to respond properly and returns a request with the wrong information. However, there are other reasons as well. Knowing these reasons is vital if you wish to resolve this error effectively.

Fix the WordPress 502 Bad Gateway Error
  • DNS issues
  • Traffic spikes
  • Server is busy with other tasks
  • Problems with reverse proxy server
  • Database errors
  • WP CDN not operating properly
  • Corrupt PHP scripts in WP files
  • Origin servers are inaccessible or unresponsive

All the mentioned reasons can result in WordPress 502 Bad Gateway Error. However, resolving wordpress errors can become a challenge if you aren’t aware of the elements involved in triggering the error.

How to Fix the WordPress 502 Bad Gateway Error

The basic reason behind this error is that the server can’t find the cause of the invalid response. Therefore, we’ll try various troubleshooting techniques until we discover the problem.

Step 1: Reload Your Website

There are times a server takes longer to respond due to low server resources or high traffic. The problem may resolve automatically within a few minutes in such a case. All you should do is reload the web page to check if this is the actual issue.

If reloading resolves the issue, there is no need to look for other reasons causing the error. However, if you see this error constantly, then you need to read ahead to figure out what else requires fixing..

Step 2: Clear Your Browser Cache

There are strong chances that your browser will show you the cache’s error page. Regardless of the issue being fixed, you’ll see the error as the browser will load your website from the cache.

To resolve this issue, users of Mac OS can press CMD + Shift + R, and Linux/Windows users can press Ctrl + F5 buttons on their keyboard to refresh the page. You can also remove the cache from your browser settings.

browser cache

Step 3: Restart LiteSpeed Server

If you are a CloudPages user, you can try to restart the LiteSpeed server and check if this helps remove the error. As you know by now, the Bad Gateway Error is caused due to server issues, which means restarting it can help you resolve it. 

To restart LiteSpeed Server, you can click “LiteSpeed Settings” on the left menu of the CloudPages dashboard.

Restart LiteSpeed Server

After that, click “Restart LiteSpeed Server” and wait for it to reset.

Restart LiteSpeed Server

Once it reloads, open your website and check if it opens. If you still see the error, read on to try the other solutions we recommend. 

Step 4: Disable the Firewall or CDN

If you are using a website firewall or CDN service on your WordPress site, then it is likely that the servers are acting up. You’ll need to temporarily disable CDN to test this.

Once you disable it, the additional layers between your hosting server and browser will be removed. Your site will load entirely from your server. If the reason behind the error is caused by the firewall/CDN server, then it will be resolved. 

After that, you can contact your CDN service provider for support. You can re-enable CDN once this error has been resolved.

Step 5: Update All WordPress Plugins and Themes

Are you still seeing the error? Well, next, you need to check all your plugins and themes. To begin, deactivate all plugins via FTP. Next, open your website to check if the error has been resolved or not.

If it is, then that means one of your plugins is malfunctioning and causing the problem. In order to find out which plugin it is, you need to activate all of them one by one until you see the error again. This will help you find the faulty plugin in no time.

Once you find the plugin, you can consider using an alternate, or you can also contact the plugin author for support.

You should check your WP theme if you still see the error after deactivating all plugins. You can switch your theme via phpMyAdmin. After you switch your theme to the default one, visit your site to check if it is working. If the error still exists, you should read on for more steps.

Step 6: Check DNS Issues

A DNS (Domain Name System) is how a domain name is linked with an IP address. If the domain fails to resolve the correct IP, it can show you a 502 Bad Gateway Error. This commonly occurs while moving a WP website to a new host. This process requires changes to the DNS name server.

DNS changes take up to 36 hours to propagate. If you try to open your website during this time, you may get a WordPress 502 Bad Gateway Error. 

Step 7: Clear DNS Cache

Though it may sound tricky, this step is quite simple. You can clear the DNS cache from the Windows Command Prompt. On a Mac,  run the command “dscacheutil -flushcache” inside the terminal window to clear the DNS cache. On the other hand, if you are a Windows user, run the “ipconfig/flushdns” command.

Step 8: Contact your hosting provider

If none of the above solutions work, it’s quite likely that the hosting server causes the error. You can try contacting your hosting provider to confirm if they are aware of any outrages or issues that may be affecting your website. It can be due to scheduled maintenance or a server overload. Also, a power outage can affect the service.

The 502 Bad Gateway Error can negatively affect your site’s search engine ranking as it stops traffic from entering your site. If your hosting service is the source of this error, and you often witness this issue, you may want to consider a better service provider to avoid future complications. 

Step 9: Restore a Backup

If you discover that your host isn’t the source of your problem, or if you can’t find any other solution, you can try restoring a backup of your website. If the backup works, then you’ll have to analyze what caused the error in the first place. In order to do that, you’ll have to track all the changes you’ve made since the last time you backed up your WordPress website.

Though this process may seem time-consuming, you can use various WP plugins that come with an activity log to track every change. A plugin like this will help you figure out what changes you made recently that might have led to the WordPress 502 Bad Gateway Error.

What if the “502 Bad Gateway” error still exists?

On rare occasions, if none of the solutions give you success, you’ll have to hire a professional WordPress development agency. Such an agency will have professional WP developers with the required experience to determine why your website is getting this error.

Final Words

Fixing some WordPress website errors can turn out to be time-consuming and annoying. Therefore, we advise that all WP website owners take daily backups so that whenever you get stuck with an error, you can just restore the previous version of your website and bring everything back to normal.

Become CloudPages

Community Member to Get Latest Updates.

Pin It on Pinterest

Share This
Scroll to Top