The 502 Bad Gateway Error and How To Resolve It | Hostdedi
You’ll face plenty of errors with your WordPress website, but none as common as the 502 error. Surprisingly, even big tech companies like Google, Facebook, and Twitter sometimes face it.
A 502 Bad Gateway Error can take webpages on your site offline for extended periods. This confusing problem could hurt your search engine optimization (SEO) efforts and negatively impact your rankings.
With that in mind, how do you resolve a 502 error on your WordPress website?
Although it’s easy to identify a 502 error, troubleshooting it is not that simple unless you understand what caused it. Read more to discover:
What Is Error 502?
A 502 HTTP status code is a response code that shows your server received an invalid response from an upstream server. Your native Microsoft and Mac browsers, including different browsers like Google Chrome, Firefox, and Safari, will display this error in several ways.
Here are five common examples:
- “502 Bad Gateway”
- “502 service temporarily overloaded”
- “HTTP Error 502 – Bad Gateway”
- “502 Proxy Error”
- “502 bad gateway Cloudflare”
Sometimes, this error may also appear as a blank white screen without an error code displayed. However, the essential thing to look out for is the error code itself, not the text variations around it.
The error code helps you identify and troubleshoot any problems with your website.
Causes of Error 502
Here are some causes for an Error 502 on your WordPress website:
Sometimes, web servers fail, leading to downtime. It can affect single or multiple websites within one server.
These are often unplanned, and your hosting provider may be unaware of them. Other times, you may have a bad modem, router, or networking equipment. That means your commands won’t reach the server.
If your website receives massive traffic, this can overload your server and cause it to throw a 502 bad gateway error. That often happens to websites on shared servers.
If you migrate your website from one host to another, propagating your domains to a new host may take time. Before your domain resolves to your new DNS servers, your website may display a 502 error.
Your firewall configuration could cause your website to throw a 502 error. Although not common, that may happen if you configure your firewall improperly. That also happens if your third-party content delivery network (CDN) goes offline.
Corrupted Files and Code
If your active themes and plugins contain corrupt PHP scripts, they can cause your site to break. Also, nulled themes and plugins with malicious code can cause your website to throw an HTTP error 502.
If your database has errors, your website may have problems accessing essential data. Any requests you make for information may return an invalid response error in this case.
How To Fix the 502 Bad Gateway Error on Your WordPress Website
Because of the ambiguous nature of a 502 bad gateway error, you may not have a solution right away. Still, here are some potential actions you can take to resolve this problem:
Check for Server Connection Issues
One major cause of the 502 bad gateway error is server downtime or connection issues. These tend to stem from:
Maintenance and Upgrades
Your hosting provider may take your server down as part of a systemwide upgrade. Whenever this happens, it affects many users at once.
If you’re facing downtime because of server-side maintenance, wait until your host completes that process.
Most hosting providers expedite the process to reduce your risk of loss. They also notify you of upcoming service interruptions by email. Stay up to date with your emails and messages to prepare for downtime beforehand.
Another reason your server may have an internal server error is a server overload. This problem is quite common with shared hosting. If you’re on a shared plan, an uncontrolled process or plugin may use up all your server resources.
If the overload is temporary, the problem usually resolves itself. But if the overload persists, your hosting provider may suspend the problematic user account. Doing so restores the server’s health and prevents other websites from experiencing downtime.
Should your host suspend your account, customer support will contact you with instructions to resolve issues on your website backend. Once you resolve these client-side issues, your host will restore your account.
Check Your Themes and Plugins
Third-party themes and plugins can cause your site to throw a temporary error. Errors are commonly triggered by:
If you’re using third-party plugins to enhance the functionality of your WordPress site, make sure they stay up to date. Also, ensure that any dependent themes and the WordPress core are up-to-date.
Most times, updates patch vulnerabilities in your core, themes, and plugins. They also enhance and improve all the current features and functionality you enjoy. Failing to update your WordPress assets can cause downtime for your website.
However, complex update issues can also arise after updating plugins.
Developers often enhance their plugins and themes with new features and functionality, meaning updates can also break your site.
To verify if a plugin is causing problems, deactivate it. Here’s how:
1. Access your WordPress backend.
2. From the Dashboard Menu, select Plugins.
3. From the Bulk Actions dropdown menu, select Deactivate.
If the deactivated plugin was responsible for the 502 bad gateway error, following the above steps should restore access to your webpage or site. If not, you can continue to search for the problematic plugin by process of elimination.
To do that, activate one plugin at a time while refreshing your website after each reactivation. If you reactivate a plugin and receive a 502 bad gateway error, it means you found the culprit. From here, keep that plugin deactivated and contact its developers for a solution.
If two plugins perform the same function, they may clash and cause 502 bad gateway errors. One plugin may attempt to override others, causing other plugins to break. Also, it may cause your custom theme or WordPress core to malfunction.
Here are several ways to resolve this problem:
- To resolve plugin conflicts, you can use the elimination process above to identify and disable them.
- Also, check for error messages on your plugin page or WordPress dashboard. If one core plugin deactivates another, a warning banner appears at the top of your dashboard with recommended fixes.
- Avoid installing over one plugin with similar functionality. Since these plugins compete, they may use up resources or break your website altogether.
- Update a plugin at a time to identify potentially problematic plugins ahead of time.
- Uninstall all unnecessary themes and plugins from your WordPress website.
Nulled Themes and Plugins
Nulled themes and plugins are premium WordPress assets changed or hacked to work without license key activation. Some usually contain malicious code that may harm your website or collect data without your permission.
Most nulled plugins are free or sold at much lower prices and won’t come directly from the developer.
Because of the security threats posed by some nulled WordPress themes and plugins, your website may break and display a 502 bad gateway error. Most nulled assets don’t support updates. Updates override any hacked or modified code and reset the plugin.
If you’re using any nulled themes or plugins, deactivate them. Doing this resolves any server connection issues your website may be facing. If you prefer to continue using these assets, please buy them from their rightful owners.
That gives you access to support services and automatic updates.
Check Your Website Error Logs
You can take advantage of the WordPress debugging system to discover and resolve error messages. Once you access these logs, you can find out what caused your website to fail and throw a 502 bad gateway error.
To access your error logs:
- Use an FTP file manager. You can also use the file manager option inside your Web hosting control panel.
- Navigate to the /wp-content/ folder.
- Select and download the debug.log file.
Once downloaded, open it and read through it for any recent error messages that may explain the 502 bad gateway error. Once you find a specific error, note down its details. The information can help you find a solution across WordPress forums and communities.
If your domain name cannot resolve to the correct IP address, your DNS server will not respond. That throws a 502 bad gateway error. You’ll often face this challenge if you’ve migrated to a new hosting service. If that’s the case, your domain may not have fully propagated to your new host.
Full propagation usually takes between an hour and 24 hours, so you’ll have to be patient.
If that doesn’t work, you can also temporarily change your DNS servers. Although your internet Service Provider (ISP) automatically allocates DNS servers, you can still use a public DNS server. Google public DNS servers are a great example, and some users prefer them long-term.
You can also clear your server error by clearing out your DNS cache. Cleaning your browser cache also helps.
Your WordPress firewall is your first line of defense from distributed denial of service (DDoS) attacks, malware, and hacks. If your firewall is configured incorrectly, it may interpret traffic from your content delivery network (CDN) as an attack and block it. Such a block can cause your website to throw a 502 bad gateway error.
To troubleshoot this issue:
- You can disable your firewall temporarily.
- If you’re using a third-party CDN, contact them for further help.
Contact Your Host
If all else fails, or you’d rather leave it to an expert, you can give your hosting provider a call. A customer service agent will log your issues, and an expert will address them.
Sometimes, a 502 bad gateway error stems from issues with your hosting partner. If so, they’ll resolve the issue promptly. If the issue is unique to your website, the customer support agent will walk you through a solution.
How To Prevent Future 502 Bad Gateway Errors on your Website
Here are some actions you can take to reduce the risk of future 502 bad gateway errors on your website:
Ensure Your WordPress Core, Themes, and Plugins are Up to Date
Always keep your themes, plugins, and WordPress core up to date. Doing so ensures you keep your website healthy and helps patch vulnerabilities. If your digital assets stay updated, you won’t experience avoidable website breakdowns or error codes.
Always Check Your Site’s Health
Whenever you access your WordPress backend, make sure you check for the health status of your website. This feature gives you information about the configuration of your website and recommends actions you should take to keep your site secure.
By following the recommendations made by the Site Health feature, you’ll keep your site running seamlessly, free of errors.
Never Directly Edit Theme or Plugin Files
Unless you’re an experienced developer or have a clear idea of what you’re doing, never directly edit your theme or plugin files. Adding untested code to your website’s PHP files can break your website entirely, and you may lose access to your backend in certain cases.
Let an Expert Manage Your Website
You can avoid the hassle of fixing errors and other website problems by letting WordPress experts manage your website. Some experts even offer hosting plans to give you a reliable way to avoid hosting-side issues.
Final Thoughts: The 502 Bad Gateway Error and How To Resolve It
Solving a 502 bad gateway error on your website is essential. The longer you stay offline, the more it costs you and your business. If you face this challenge, ensure you solve it fast to minimize the impact.
You can use any of these solutions above to resolve your WordPress website issues. If you still feel stuck, contact your website host and request assistance.
If you would rather have someone else handle the technical aspects of your website as you focus on growing your business, check out Hostdedi’s Fully Managed WordPress Hosting plans today and choose a plan that fits your needs.
This blog was originally published in November 2020. It has since been updated for accuracy and comprehensiveness.