How to Fix the 502 Bad Gateway Error in WordPress?

How to Fix the 502 Bad Gateway Error in WordPress?
Facebook
Twitter
LinkedIn
WhatsApp
Email
Pinterest
Print

Do you need to fix the 502 bad gateway error on your website? This error can be triggered by a wide variety of factors, which makes it highly frustrating. This means it may take some time to fix the 502 bad gateway error. I’ll show you how to quickly fix the 502 bad gateway error in WordPress in this article.

What is a 502 Bad Gateway Error?

When a server (serving as a gateway or proxy) receives an invalid response from an upstream server, it returns an HTTP status code of 502, which means “Bad Gateway.” This may occur if the server is temporarily down or if there is a communication issue between the server and the upstream server.

What is a 502 Bad Gateway Error

When a user tries to access a website that is currently having this problem, the error message frequently shows in the browser. Depending on the browser and operating system you are using, the error message may appear differently, but it is typically displayed as “502 Bad Gateway” or “502 Service Temporarily Overloaded.” The website should become accessible again shortly following this temporary issue.

How to Solve the 502 Bad Gateway Error in WordPress

WordPress’s 502 Bad Gateway error can be caused by a variety of issues such as server overload, plugin conflicts, and incorrect settings. You can attempt the following fixes for this issue, with examples:

Increase your PHP memory limit

As you know this specific error caused due to server overload. So if we can allow your server to use more resources this issue will be solved. By including the following piece of code in your wp-config.php file, you can raise the PHP memory limit:

define( 'WP_MEMORY_LIMIT', '256M' );

Also, you need to contact your hosting provider to ensure that they did not put any restriction on CPU, Memory. If so ask them to increase the resources. Sometimes it is better to upgrade the hosting plan or simply switch to a more reliable hosting provider.

Deactivate all plugins

This will allow you to determine if a plugin is to responsible for the error. By renaming the plugins folder in your WordPress installation, you can deactivate every plugin. []

  1. Open your FTP client and connect to your website using your login credentials.
  2. Navigate to the directory where your WordPress site is installed. This is typically the “public_html” or “www” folder.
  3. Within the WordPress installation directory, navigate to the “wp-content” folder.
  4. Locate the “plugins” folder. This is where all of your installed plugins are stored.
  5. Select all the folders in the plugin folder, and rename them by adding “-old” to the end of the folder name.
  6. Once you have renamed all the folders, all the plugins will be deactivated and will no longer be active on your site.

Note: It is always a good practice to take a backup of the plugin folder before renaming or deleting it.

Check your .htaccess file

Check your .htaccess file

Rewrite rules are one of the many website settings that are controlled by the .htaccess file in your WordPress installation. This file’s corruption may result in a 502 error. If the problem persists, you can rename the file to .htaccess-bak. To check your .htaccess file using FTP, you will need an FTP client such as FileZilla.

  1. Open your FTP client and connect to your website using your login credentials.
  2. Navigate to the directory where your WordPress site is installed. This is typically the “public_html” or “www” folder.
  3. Locate the “.htaccess” file. This file is usually located in the root directory of your website, but sometimes it may be hidden. Make sure that your FTP client is configured to show hidden files.
  4. Once you have located the file, you can download it to your local computer to view its contents.
  5. Once you have finished reviewing the file, you should upload it back to the server and overwrite the existing file.

Update Themes and Plugins

Updating your website’s WordPress themes and plugins is crucial for keeping it safe and secure. Also, it can fix the 502 Bad Gateway Error in WordPress. How to update them in WordPress is as follows:

  1. Log in to the WordPress dashboard of your website.
  2. Go to the “Updates” section, located in the sidebar.
  3. Here, you will see a list of available updates for your themes and plugins. Select the checkbox next to the updates you want to install.
  4. Click the “Update Themes” or “Update Plugins” button to begin the update process.
  5. Once the updates are complete, you will see a message confirming that the updates have been successfully installed.
  6. You can also update individual themes and plugins by going to Appearance > Themes or Plugins > Installed Plugins

Disable the CDN or Firewall for your website

CDN or Firewall may be the cause of this 502 Bad Gateway Error in WordPress. So it is important to disable them to check if it is the cause. Disabling a Content Delivery Network (CDN) or firewall in WordPress can be done through the settings of the plugin or service that you are using. The specific steps may vary depending on the plugin or service you are using, but generally, you can follow these steps:

  1. Log in to the WordPress dashboard of your website.
  2. Go to the “Plugins” section, located in the sidebar.
  3. Locate the plugin or service that you are using for your CDN or firewall.
  4. Click on the “Settings” or “Options” link for that plugin or service.
  5. Look for a setting or option that allows you to disable the CDN or firewall. This may be a switch, checkbox, or button that you can toggle off.
  6. Save your changes and test your website to ensure that the CDN or firewall is no longer active.
  7. If your site is up and running, then we know the root of the issue and seek help from the CDN/firewall provider for help.

Clear Browser Cache

Clear Browser Cache

As I said earlier that it is a temporary issue, but you may experience the issue due to your browser cache. So we need to disable that to see the current site.

Clearing your browser cache is a simple process that can help to resolve issues with your website not loading correctly or displaying outdated information. Here are the steps to clear the browser cache for some popular browsers:

Google Chrome:

  1. Click the three dots in the top-right corner of the browser window.
  2. Select “More tools” and then “Clear browsing data.”
  3. In the dialog box that appears, select “Cached images and files” and any other data you wish to clear.
  4. Select “Clear data” to finish.

Mozilla Firefox:

  1. Click the menu button (three horizontal lines) in the top-right corner of the browser window.
  2. Select “Options.”
  3. In the left sidebar, select “Privacy & Security.”
  4. Under “Cookies and Site Data,” click “Clear Data.”
  5. In the dialog box that appears, make sure “Cached Web Content” is selected, and then click “Clear.”

Microsoft Edge:

  1. Click the three dots in the top-right corner of the browser window.
  2. Select “Settings.”
  3. Under “Clear browsing data,” select “Choose what to clear.”
  4. Check the box next to “Cached data and files” and any other data you wish to clear.
  5. Select “Clear now” to finish.

Safari:

  1. Click “Safari” in the top menu bar of your browser.
  2. Select “Preferences.”
  3. Select the “Advanced” tab.
  4. Check the box next to the “Show Develop menu in the menu bar.”
  5. Click the “Develop” menu in the top menu bar.
  6. Select “Empty Caches.”

Note: Clearing the browser cache will also remove your browsing history, so you may want to save your bookmarks or browsing history before clearing the cache.

It’s important to note that, in case of a server overload, the error might persist and your hosting provider will have to handle it. Also, if you’re experiencing this error frequently, you might want to consider moving to a more powerful hosting plan. If none of the above solutions fixed the error, you might want to consider hiring a professional WordPress developer to take a look at your website and help you identify and fix the problem.

 

Related Posts

About The Author

Dr. Sabbir is a  front-end software engineer and WordPress expert with over 12 years of experience in the tech industry. Although he received his medical degree from Rajshahi Medical University, Dr. Sabbir decided to focus on his passion for technology and website development full-time.

In his role as a front-end software engineer, Dr. Sabbir has helped design and develop user-friendly websites and applications for clients in various industries, including healthcare. He is well-versed in a variety of programming languages and is always looking for new ways to improve the user experience.

55K+ Members

Join Our Facebook Group

53k+ Followers

Follow Our Facebook Page