WordPress Tutorial

How to Fix 502 Bad Gateway Error in WordPress

502 bad gateway error

Each time you open a site, the browser sends out various requests to other web servers. The servers then handle these requests and send back an HTTP status code along with the requested resources. Generally, the HTTP status codes are not displayed unless a problem is encountered along the way. This is how the servers inform each other and the end-user what went wrong.

502 bad gateway is one of the HTTP status codes that you can run into from time to time. While not as frequent as the 500 internal server error or 503 service unavailable error, it can still give quite a headache. Hence, this tutorial focuses on the causes and fixes of the 502 bad gateway error on WordPress websites.

What Does 502 Bad Gateway Mean?

HTTP status codes that start with the digit “5” relate to errors that occur when there’s a miscommunication between several servers. Though the exact reason for their appearance varies, in most cases the cause lies within the server-side.

Getting a 502 bad gateway error means that the origin server sent out an invalid response to another server that acted as a gateway or proxy. Since all requests on the web are forwarded through multiple gateways, it can be quite tricky to locate the exact point or process which caused the issue. However, there are general troubleshooting steps that you can follow to get it fixed.

502 bad gateway error in browser

The 502 bad gateway error may also come in various shapes and sizes. Here are some alternatives that you can encounter:

Temporary Error (502)
Error 502
HTTP Error 502 Bad Gateway
502 Server Error: The server encountered a temporary error and could not complete your request
502 - Web server received an invalid response while acting as a gateway or proxy server
HTTP 502
502 Service Temporarily Overloaded
502 Bad Gateway Nginx

How to Fix 502 Bad Gateway Error

While the 502 bad gateway error usually relates to server-side problems, it can also be caused by misconfigurations or issues from the client-side. Hence, we’ll overview the common troubleshooting steps with both causes in mind. While some solutions are focused towards WordPress, most of them can be applied to any website. Without further ado, let’s see the steps to fix the 502 bad gateway error:

1. Refresh the Page

The first solution is a fairly simple one. Wait around for a minute or two and refresh the page you’re on. In a lot of cases, the error is temporary and a simple page refresh will do the trick. Meanwhile, you may also check if the website is down using any online tool.

Checking website availability using online tools

2. Clear Browser Cache

If the error persists, there is a chance that a certain cached element causes it. Thus clearing the browser cache is a good approach when troubleshooting the 502 bad gateway error.

3. Try a Different Browser

Checking the connection using a different browser or incognito mode is also a great idea. It will let you rule out the option that the error appeared due to a browser related problem.

4. Flush DNS

The 502 bad gateway error can also pop up due to DNS issues, such as incorrectly cached IP address values. In such cases, flushing DNS is another thing that you can try. Here’s a tutorial on how to flush DNS on Windows, Mac, and Linux.

You may also try temporarily switching your default DNS server to Google Public DNS.

5. Test on Another Device

If none of the above solutions fixed the 502 bad gateway error, test the connection on another computer or a mobile device, preferably connected to a different network. This is the final step that will rule out whether the error is related to your machine or if the problem lies elsewhere.

6. Check Error Log

If the 502 bad gateway error appeared after a certain change or update, it’s possible that the fault lies within the website itself. The best approach is to check your error log for any hints.

In WordPress, you can enable error logging by adding the following lines in wp-config.php:

define( 'WP_DEBUG', true ); 
define( 'WP_DEBUG_LOG', true ); 
define( 'WP_DEBUG_DISPLAY', false );

All the generated entries will appear in wp-contents/debug.log file.

A log file that collects all WordPress errors

7. Check Plugins

It’s also important to check your plugins and extensions. Issues with caching plugins can often lead to 502 bad gateway error popping up. A simple way to check if plugins are at fault is by disabling all of them for a short moment. To do it, navigate to the wp-content directory and rename the plugins directory.

Disabling all active WordPress pluginsIf the website starts working after all plugins are disabled, you may rename the folder back to plugins and enter it. Then try disabling the plugins one by one to determine which one caused the error in the first place.

Disabling a single WordPress plugin

8. Check CDNs

Another cause of the 502 bad gateway error can be CDNs or DDoS mitigation services. One notable example would be CloudFlare, where the 502 bad gateway can occur in two different variations depending on the issue.

502 bad gateway error when using CloudFlare - version 1This screen indicates that the issue in on CloudFlare’s side, and to fix it you’ll need to reach out to their customer support team. Alternatively, you may choose to disable CloudFlare, though keep in mind that DNS propagation may take a couple of hours.

502 bad gateway error when using CloudFlare - version 2However, if you see this version of the error, it means that the issue lies with your current hosting provider.

9. Contact Customer Support

If none of the above solutions fixed the 502 bad gateway error, then it’s best to contact the customer support team. While describing the issue, try to include what troubleshooting steps that you took. Provide as much information as possible and you’ll surely be assisted!

Conclusion

In this tutorial, we’ve learned what 502 bad gateway error is and how to approach it with basic troubleshooting steps.

In case you have any extra tips, tricks, or solutions, feel free to share them with us in the comments below!

Add Comment

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share this