Published

Update

6 minutes

Error 502, 502 Bad Gateway In fact, the wording doesn't matter. When this kind of message appears on a page of your screen, no translation is needed. 

The damage is already done. And you quickly realize there's a problem. The screen is (almost) completely white. You can't see the page content. In short, You are now facing a 502 error..

This is the kind of error every webmaster wants to avoid encountering too often. When it does happen, it's best to fix it as quickly as possible. 

By the end of this article, you will be able to Fix a 502 error on WordPress with 8 practical solutions, practice-oriented. 

And if that doesn't solve your problem, don't hesitate to contact ourWordPress agency.

What is a 502 error?

Definition of error 502

The HTTP error 502, commonly called 502 Bad Gateway, is a server-side error.
When this happens, the server cannot respond to a request sent by your web browser: an error message then appears on your screen. The page or article you want to view is unavailable and does not display.

In its official documentationThe Mozilla browser specifies that in the case of a 502 error, "The server, acting as a gateway or proxy, received an invalid response from the upstream server.".

In practice, here's what happens, in order, when you encounter an error or error 502: 

  1. You want to access a web pageeither by typing its URL (web address) into the search bar of your favorite browser, or by clicking on a link.
  2. Your browser sends a request to your website's hosting server. websiteIn short, he is asking him if he is able to display the page.
  3. If all goes well, The server executes the request and displays the content of the web page.It then returns a successful HTTP response code (code 200). You don't see it on the screen; it all happens in the background.
  4. If there is a problem, a server error HTTP response code will be displayed on the screen. : the infamous Bad Gateway. 
The 502 Bad Gateway error on WordPress.
Source: Mozilla.

What are the other types of server errors?

Error 502 belongs to the family of server errors (HTTP response codes from 500 to 599). Examples include: 

  • error 500 (Internal Server Error): the server has encountered a situation that it cannot handle;
  • error 501 (Not Implemented): The server does not support the request method;
  • error 503 (Service Unavailable), when the server is not ready to process the request (it is unavailable or undergoing maintenance); 
  • error 504 (Gateway Timeout): The server failed to provide a response in time;
  • error 505 (HTTP Version Not Supported): The server is unable to support the HTTP version used in the request.

Beyond that, you will also sometimes encounter:

  • HTTP client errors (your web browser), such as the 404 error (page unavailable);
Part of the 404 page of WP Maintenance.
Part of the 404 page of WP Maintenance.
  • redirection errors, such as the 301 redirect response status code. It indicates that a page has been permanently moved to another URL.

The 502 error is not limited to WordPress. You can encounter it on other platforms. CMS (Content Management System) such as Shopify, Squarespace, Wix, Drupal, Joomla etc. But you can also encounter a 502 error on Google, or on any web server unable to transmit a request to access a website.

How can a 502 bad gateway error be displayed on the screen?

On your screen, a 502 error can appear in different ways. For example, it might look like this:

A 502 error is displayed on the screen.
Source: Blog of Kinsta.

However, variations are possible, primarily in terms of form. Some hosting providers can customize their appearance to make it less austere. 

Then, The label displayed on the screen can appear in different variations., mostly using English terms. Here is a non-exhaustive list: 

  • Temporary Error (502);
  • 502 Error;
  • HTTP Error 502;
  • 502 Server Error; 
  • Error 502;
  • 502 Service temporarily overloaded;
  • Error 502 proxy error or 502 Proxy Error;
  • HTTP Error 502 Bad Gateway;
  • 502 Bad Gateway Nginx;
  • HTTP Error 502 Bad Gateway;
  • 502 Service Temporarily Overloaded;
  • 502 Server Error: The server encountered a temporary error and could not complete your request.

What are the causes and consequences of a 502 error on WordPress?

What causes a 502 error?

Like most server-side errors, error 502 provides very little information about its cause. However, experience shows that it can be caused by various factors: 

  • a misconfiguration of the serverThese may be problems related to the configuration of the proxy server, of the PHP server, or of the configuration of the web server configuration files;
  • a lack of resources at the hosting server levelIf it becomes too overloaded, for example due to a spike in traffic to your website, it will not be able to process the request sent by your browser. It will crash and display a 502 error; 
  • a general server outage
  • errors in your web browser when displaying a web page; 
  • the presence of corrupted files or security vulnerabilities within your WordPress plugins or theme; 
  • an incompatibility between plugins or themes after a recent installation or an update ;
  • a security problem On WordPress due, for example, to a DDoS (Distributed Denial of Service) attack.

What is the impact of a 502 error on your WordPress site?

When it occurs, an HTTP 502 error can have negative consequences for your WordPress site, and more broadly for your online business. 

If this error is not resolved quickly, you risk:

  • degrade the user experience (UX), because your visitors will not be able to access your website's content and find an answer or solution to their problem.
    If the error occurs too often, they may turn away from your site and go to your competitors; 
  • damage your brand imageAn unavailable website projects an unprofessional image and can suggest a lack of reliability. You will appear less credible to internet users.
  • experience a drop in trafficIf Google's robots repeatedly encounter 502 errors on your website, this can slow down the crawling of your pages and negatively impact your natural search engine optimisation (SEO). In addition, Google could remove the URLs of your affected pages from its index, which would lead to a significant decrease in your visibility in search results.
  • see your conversion rate dropVisitors who cannot access your pages will be unable to complete desired actions, such as purchasing a product, filling out a form, or subscribing to your newsletter. This can have a significant impact on your revenue.
  • note the cancellation of certain transactionsIf you have a WooCommerce Online ShopFor example, any payment transaction may be cancelled if a 502 error occurs at the same time. 

Unfortunately, a 502 error is uncontrollable by nature: it's impossible to know when it will appear on your screen.

However, there are solutions to resolve this issue should you ever encounter it. Find all our detailed explanations in the following section. 

How to fix error 502 Bad Gateway: 8 solutions

To begin, we recommend backing up your site before proceeding with any technical troubleshooting. You can use a backup plugin for this. UpdraftPlus, or a maintenance tool such as WP UmbrellaWhatever solution you choose, back up both your website files and its database.
If you encounter any problems later on, you will be able to easily restore your WordPress site. 

Reload the page

Before diving into the source code of your WordPress website, see if a simple action can make the 502 error disappear. 

Go to the "broken" webpage and reload it. To do this, Click on the F5 key on your keyboard, or on the "refresh" icon of your web browser:

Refreshing the page may fix a 502 error.

If nothing happens immediately after this operation, wait a few minutes, then repeat the operation again.

The server may have overheated slightly due to a traffic spike. Letting it cool down for a few moments might solve the problem. 

You can also try the following tips in parallel: 

  • Try viewing the page in a different browserFor example, if you're using Google Chrome, check if the infamous 502 Bad Gateway error code also appears in Mozilla Firefox or Safari. If not, Chrome is likely the culprit, perhaps due to one of its extensions (an ad blocker you might have installed could be the cause). 
  • Use a tool to find out if the website you want to visit is down for everyone.Or, if the problem is with you, you can try. Down for Everyone or Just Me ou Is it down right now
The website Down for Everyone or Just Me lets you know if a 502 error affects everyone or just you.

Clear your browser cache to fix a 502 error

The previous tip didn't work? Let's move on to the next solution, which consists of clear your web browser cache.

To display a web page to a visitor as quickly as possible, a web browser caches it – essentially, it stores it in memory – after the first visit. This allows it to serve you a copy of the original page without having to download it again from the original server.

It's an effective method. However, A 502 error will persist on the screen if the page is still cached., even though the server is no longer experiencing any problems. 

To resolve this issue, clear your browser's cache. Here's the method used in the Google Chrome browser: the most used by internet users in France (The process is the same for competing browsers):

  1. Click on the 3 small dots at the top right of the toolbar. 
  2. Choose More tools > Clear browsing data. A highlighted pop-up window will open.
  3. In the “General” tab, choose a period (hours, days, weeks or all data) and check the “Cached images and files” box.
  4. Click on "Clear data" to clear the cache.
Clearing a web browser's cache can fix a 502 error.

Is the 502 error still there? Read on. 

Disable your plugins

Like any webmaster or WordPress user, you use extensions to add new features to your site. 

It must be said that they are very practical, for example for strengthen the security of your siteYes, but here's the thing: sometimes, WordPress plugins can be the cause of a 502 error.

This can appear after an update, due to an incompatibility or a problem in the PHP code.

To resolve this, you will need to find the culprit plugin by disabling all extensions on your site. 

Since the latter may be inaccessible (you will be unable to connect to the administration panel), you will either have to go through: 

  • an FTP client as Filezilla (free) ;
  • the administration interface provided by your hosting providerOne of the best known is called cPanel. 

Here are the steps to follow with FileZilla.

Renaming the plugins directory to resolve a 502 error

Connect to Filezilla using the credentials provided by your hosting provider (username, password and host).

Go to the root folder of your site (ex: public_html), then navigate to wp-content > plugins. Change the name of this directory and create a new plugins folder. (e.g., plugin errors): 

The wp-content folder contains, among other things, the plugins of a WordPress site.

Reactivate your extensions one by one

WordPress will deactivate all your plugins. Is your website working again? Then a plugin is definitely the culprit. 

If possible, log in to your site and reactivate your extensions one by one. Remember to refresh your page each time.

Once you find the culprit plugin, you have two options: 

  • delete it permanently and replace it with an alternative extension
  • disable it until its developer releases a patch.

Finally, once all your plugins are reactivated, don't forget to delete the plugins-error folder on your FTP. 

If this solution still doesn't work, your theme may be the problem.

Check if your theme is causing the 502 error.

To deactivate your theme, the process is the same as for your WordPress plugins. Only the access to their directory differs. Here's how to do it in detail using your FTP client: 

  • go to the wp-content > themes folder; 
  • Download your active theme folder by right-clicking and selecting "Download". 
  • Delete the theme you just downloaded (right click > Delete).
Deleting a theme on the FTP can help resolve a 502 error on WordPress.

Return to your web browser and Reload the page where the 502 error was displayed.If your theme was the cause, the error will have disappeared. In the meantime, WordPress will have activated one of its default themes (e.g., Twenty Twenty-Three).

If it doesn't suit you, activate the theme of your choice (Astra, cadence, Blocky ou GeneratePress are excellent choices). 

Still getting error 502? Reinstall your theme, the one you previously downloaded to your computer, by uploading it to your FTP server. Then proceed to the next solution. 

Disable your CDN and/or firewall

You are using a CDN on your WordPress site (for example, via the cache plugin). WP Rocket) ? If so, disable it to see if it changes anything on the screen.

CDN (Content Delivery Network) stands for Content Delivery Network. It is a set of interconnected servers distributed across different locations worldwide. These servers cache pages that do not need to be updated regularly and serve them more quickly to users by using servers located closest to them. 

Regarding the procedure to follow, It all depends on the service you use. (Cloudflare, KeyCDN, RocketCDN, Bunny.net etc). Consult its documentation for more information.

Is the 502 error still causing problems? In that case, you should check your firewall. 

This is a tool capable of blocking malicious requests from your web server. Many WordPress security plugins offer this option. This is the case, for example, with one of the most famous of them, Wordfence Security. 

To disable your application firewall, go to Wordfence > Firewall in your WordPress admin panel. In the "Web Application Firewall Status" menu, click the dropdown menu and select the "Disabled" option.

Disabling the Wordfence Security firewall.

Finish by saving your changes, then reload your page. If the 502 error has disappeared, you have fixed the problem.

Otherwise, re-enable the firewall to continue protecting your site. Let's continue our investigation by taking a look at the logs. 

Check your server logs

Logs are text files that record events that occur on your server. Some hosting providers allow access to these files through their interface. Contact your provider to see if this is the case.

Alternatively, you can view these files using your FTP client or the file manager provided by your hosting provider (e.g., cPanel).

If a log file is already present in your site's root directory, For example, it will appear in this form: error.logIf you don't have it, activate WordPress debug mode to display it.

Whenever possible, perform this operation in a test environment (locally or on a staging site). Avoid doing this on production sites, in case your sites crash. To create a local site, we recommend the tool DevKinsta ou Local NewsFor a staging site, you can activate the extension WP Staging or take advantage of this service through your hosting provider, if they offer it. 

To do this, access your file wp-config.php, located in the root directory of your site. Then manually replace the value "false" with "true", as shown on the line below:

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

If errors are detected, they will be displayed in a log file called debug.logYou will find it in wp-content > debug.log.

If you need to display your errors on the screen, adjust the constant  'WP_DEBUG_DISPLAY’ on the value true

In conclusion, don't forget to iron. 'WP_DEBUG' on false at the end of the procedure.

Change your PHP version

In WordPress jargon, WP_DEBUG is what is called a PHP constant (the scripting language in which a large part of the WordPress source code is written).

Speaking of PHP, let's continue with it. When updating to a major version of WordPress, or simply installing new plugins, a 502 Bad Gateway error may have appeared. 

Behind the scenes, your site's new configuration may no longer be compatible with the version of PHP you are using. 

An outdated version of PHP This will prevent certain scripts or plugins from functioning correctly, resulting in a 502 error.

For security and performance reasons, it is advisable to use one of the latest versions of PHP.

You can update it in just a few clicks on your hosting provider's interface. But first, follow the recommendations of the official WordPress documentation

  • save your site
  • update The core of WordPress, your themes and extensions; 
  • Check your site's compatibility with the PHP version. that you wish to use thanks to the plugin PHP Compatibility Checker

When you are ready, log in to your cPanel (or a similar interface offered by your hosting provider) and follow these two steps:

  1. In the "Software" section, click on "Select a PHP version".  
  2. In the dropdown menu, select the PHP version you need. At the time of writing, WordPress recommended a PHP version of at least 7.4. We recommend, if your site's compatibility allows, upgrading to at least PHP 8.0. 
Updated PHP version to fix a 502 error on WordPress.

For added peace of mind, test the new PHP version you want to activate on your site in a test environment. With KinstaDev or Local, you can choose your preferred PHP version when creating a new instance. If you encounter no problems, you can confidently switch to production.  

Contact your hosting provider

Have all the solutions listed so far failed you? You can still resolve this 502 error by contacting your hosting provider's support. 

Clearly explain to them the situation encountered and the measures you have taken so far to try to rectify the error. 

With a bit of luck, it's possible that your hosting provider's server is the problem. Their technical team will then take care of resolving it. All you'll have to do is wait.

If that's not the case, ask support if they can increase PHP execution timeThis refers to the maximum time a PHP script can run. This technical measure can help you get rid of a recurring 502 error.

Summary

This article provides you with a comprehensive overview of the 502 error on WordPress. In summary, you have learned the following throughout this article: 

  • what a 502 error is; 
  • what are its variants; 
  • what are the causes and consequences;
  • 8 practical solutions to solve it.

If you ever encounter this server error, don't waste any time fixing it. As you've seen, The longer you wait, the more negative the consequences can be. in terms of SEO, brand image and revenue.

Would you like assistance in implementing our various tips to resolve a 502 error?

Available 7 days a week, our WordPress support service will offer you a tailor-made solution that will meet your needs with speed, professionalism and efficiency.

Discover more blog articles

separator arrow

See more articles