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.
[wpm_post_image id=”1″]
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. []
- Open your FTP client and connect to your website using your login credentials.
- Navigate to the directory where your WordPress site is installed. This is typically the “public_html” or “www” folder.
- Within the WordPress installation directory, navigate to the “wp-content” folder.
- Locate the “plugins” folder. This is where all of your installed plugins are stored.
- Select all the folders in the plugin folder, and rename them by adding “-old” to the end of the folder name.
- 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
[wpm_post_image id=”2″]
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.
- Open your FTP client and connect to your website using your login credentials.
- Navigate to the directory where your WordPress site is installed. This is typically the “public_html” or “www” folder.
- 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.
- Once you have located the file, you can download it to your local computer to view its contents.
- 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:
- Log in to the WordPress dashboard of your website.
- Go to the “Updates” section, located in the sidebar.
- 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.
- Click the “Update Themes” or “Update Plugins” button to begin the update process.
- Once the updates are complete, you will see a message confirming that the updates have been successfully installed.
- 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:
- Log in to the WordPress dashboard of your website.
- Go to the “Plugins” section, located in the sidebar.
- Locate the plugin or service that you are using for your CDN or firewall.
- Click on the “Settings” or “Options” link for that plugin or service.
- 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.
- Save your changes and test your website to ensure that the CDN or firewall is no longer active.
- 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
[wpm_post_image id=”3″]
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:
- Click the three dots in the top-right corner of the browser window.
- Select “More tools” and then “Clear browsing data.”
- In the dialog box that appears, select “Cached images and files” and any other data you wish to clear.
- Select “Clear data” to finish.
Mozilla Firefox:
- Click the menu button (three horizontal lines) in the top-right corner of the browser window.
- Select “Options.”
- In the left sidebar, select “Privacy & Security.”
- Under “Cookies and Site Data,” click “Clear Data.”
- In the dialog box that appears, make sure “Cached Web Content” is selected, and then click “Clear.”
Microsoft Edge:
- Click the three dots in the top-right corner of the browser window.
- Select “Settings.”
- Under “Clear browsing data,” select “Choose what to clear.”
- Check the box next to “Cached data and files” and any other data you wish to clear.
- Select “Clear now” to finish.
Safari:
- Click “Safari” in the top menu bar of your browser.
- Select “Preferences.”
- Select the “Advanced” tab.
- Check the box next to the “Show Develop menu in the menu bar.”
- Click the “Develop” menu in the top menu bar.
- 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.