How to Fix the 502 Bad Gateway Error

How to Fix the 502 Bad Gateway Error

A 502 Bad Gateway Error is a common HTTP status code you can easily troubleshoot.

In this guide, we’ll outline ten practical steps to diagnose and fix a 502 Bad Gateway Error for both client-side and server-side issues. We’ll explore various potential causes, ensuring you have a comprehensive understanding of what might be going wrong.

Download comprehensive HTTP status codes cheat sheet

A 502 Bad Gateway Error is an HTTP status code showing a communication problem between the two servers on the internet, where the proxy server or gateway server receives an invalid response from the upstream server. In most cases, resolving the 502 error is easy and quick.

Error code502 Bad Gateway Error
Error typeServer-side error
Error variationsTemporary Error (502)
HTTP Error 502 Bad Gateway
502 Proxy Error
Bad 502 Gateway
502 Service Temporarily Overloaded
A blank white screen
Error causesUpstream server issues
Proxy server received an invalid response
Network communication errors between servers
Server overload due to high traffic
Faulty browser cache or extensions
Incorrect DNS settings
Misconfigured firewall or CDN issues
Infographic detailing the 502 bad gateway error

What Causes a 502 Bad Gateway Error

A 502 Bad Gateway error message arises from a communication failure between web servers. It occurs when a server acting as an intermediary receives a response from another server that it can’t understand or process. Mainly, there are four 502 Bad Gateway causes:

  • Meaningless response – the other web server sent back wrong or incomplete data.
  • Incorrect format – the response is in the wrong language or technical format for the intermediary server to interpret.
  • Server overload – the other server is too busy and unable to respond properly.
  • Network problems – glitches in the connection between the servers.

These issues prevent the intermediary server from fulfilling your request, resulting in a 502 error.

502 Bad Gateway Error Variations

A 502 error can appear on any device or service, but the exact message might differ. Here are some variations of this HTTP status code you might see:

  • Simple – Temporary Error (502), 502 Error.
  • Descriptive – HTTP Error 502 Bad Gateway, 502 Server Error, with an explanation.
  • Technical – 502 – Web server received an invalid response, HTTP 502, 502 Proxy Error.
  • Overload – 502 Service Temporarily Overloaded.
  • Server-specific – 502 Bad Gateway Nginx, depending on server software.
  • Blank screen– some websites show a plain white screen.

Some website owners create unique error pages with additional information. For instance, Chrome offers troubleshooting tips and suggests retrying.

Chrome 502 error page

GitLab explains the communication issue and provides solutions.

Gitlab 502 error page

X (previously Twitter), on the other hand, displays a friendly message with an illustration.

Twitter/X 502 error page

Improve Your User Experience With Customized Error Pages

We recommend customizing your pages with error codes. This way, you can improve your user experience by providing helpful content for your visitors.

How to Fix the 502 Bad Gateway Error

In most cases, the 502 Bad Gateway error is temporary – you just have to wait for around 30 seconds for it to disappear. To troubleshoot further, try the following:

1. Refresh the Page

Usually, a 502 Bad Gateway Error is temporary, stemming from a sudden traffic surge. A quick refresh can resolve the issue.

On Windows, press F5 or CTRL + F5. On Mac, use CMD + R.

2. Check the Site Status

If the 502 error code is still showing up, it is possible the website’s server might be currently experiencing downtime.

Luckily, there are many tools to examine if the site is down, including Down for Everyone or Just Me and IsItDown. Simply input your URL and check the status of the website.

3. Clear Your Browser Cache

If the invalid response error persists, there is a chance that your browser cache has saved outdated and corrupted files. In this case, clearing the browser cache can offer a 502 Bad Gateway fix.

Keep in mind that removing cached files might result in losing important browser data, including bookmarks and setting preferences. To prevent this, simply export your data from the browser and import it back after.

4. Try in the Incognito Mode

Access the website in Incognito mode to determine whether the 502 gateway timeout appears due to a browser-related issue. To open an Incognito window, click on the three-dots button on your browser screen and choose New Incognito Window.

New incognito window option highlighted in Chrome

If the error doesn’t occur in Incognito mode, your browser extension is likely causing the problem.

Try to disable your add-ons or extensions one by one. When you delete the extension causing the error, you should be able to access the website. From our experience, an ad-blocker extension is usually the culprit.

If disabling browser extensions doesn’t help, try a different browser. For example, if you’re currently on Google Chrome, try using Mozilla Firefox.

If the page works on the new browser, your previous browser might be causing the error. To solve the problem, try deleting and reinstalling your faulty browser.

5. Flush the DNS Cache

Other common causes of 502 Bad Gateway are DNS problems, such as incorrect IP addresses and unresponsive DNS servers.

In this case, flushing your DNS cache can be the answer. This method works similarly to clearing your browser’s cache. It will remove faulty files from your DNS server.

Consider also temporarily changing your DNS servers. By default, your ISP assigns your DNS servers. However, you can always change it to a third-party server, such as Google Public DNS.

6. Test on Another Device

If none of the above 502 error fixes work, test your internet connection on another computer or a mobile device, ideally connected to a different network.

Additionally, try restarting your computer and router. Doing so shows whether the error is related to your networking equipment or if the problem lies elsewhere.

7. Check Error Logs

If you encounter a website 502 error after a change or an update, you might be dealing with a web server error. The best approach to solving this issue is to check your website error log.

Usually, your hosting service lets you access your website error log files through an admin dashboard. You can also enable error logging on your WordPress website by adding the following lines in wp-config.php:

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

All of the generated errors will appear in the wp-contents/debug.log file, allowing you to detect which ones are causing a 502 Bad Gateway error.

8. Check Plugins and Themes

Sometimes, faulty plugins or themes can cause the error.

This is because poorly coded plugins and themes can conflict with each other. When this happens, your server will stop every script and query on your website, making it inaccessible.

For some websites, the issue usually comes from caching or security plugins. There is a good chance that these plugins block communication between servers, causing the error to persist.

If you don’t have a caching or security plugin installed but still encounter the HTTP 502 error, it’s best to disable your plugins and re-activate them one by one. To do so, go to Plugins and simply click Deactivate from the Bulk Actions menu.

Plugins menu in WordPress with deactivate section highlighted

Then, activate each plugin while refreshing your WordPress site after each one. Once the 502 error pops up again, you have found the problem plugin.

However, if you can’t access your WordPress dashboard, you can try disabling them from your hosting panel or FTP program. Navigate to the wp-content directory and rename the plugins directory, for example, plugins-disable.

If you use Hostinger, access your hPanel and click on Files. From there, go to File Manager → public_html → wp-content.

Plugin rename pop up close up in File Manager

Once your site starts working after all plugins are disabled, you may rename the folder back to plugins. Then, try enabling the plugins one by one to determine which one caused the error in the first place.

If the website still doesn’t work, follow the same steps with your WordPress themes.

9. Check Your Content Delivery Network (CDN)

Another cause of the 502 Bad Gateway errors can be issues with your content delivery network (CDN) or DDoS mitigation services.

A CDN adds an extra layer between your server and browser to deliver web content efficiently. However, this layer can run into an issue when connecting with your origin server, resulting in 502 Errors.

One notable example is Cloudflare, where the 502 Bad Gateway can occur in two different variations depending on the issue.

Cloudflare bad gateway error

The screen above indicates that the issue is on Cloudflare’s side. To fix it, you’ll need to reach out to their customer support team. Remember to check the Cloudflare System Status page before doing so.

Alternatively, you can disable Cloudflare. However, keep in mind that your DNS propagation may take a couple of hours.

502 error resulting from web hosting side

If you see the Cloudflare error shown above, it means that the issue lies with your current web hosting provider. In this case, try to contact your web host support team and ask for assistance.

10. Increase PHP max_execution_time and max_input_time

PHP timeout happens whenever a PHP process loads for more than the specified max_execution_time or max_input_time. These are the values set in your PHP configurations on your web server. Usually, the values are set to 300 seconds by default.

A timeout can happen during the migration process and trigger a 502 Bad Gateway error. To fix this issue, you can contact customer support of your hosting provider to check what your values are set at and if you can increase them.

Hostinger web hosting banner

How to Fix 502 Bad Gateway Error – Video Tutorial

If you prefer to follow along with a video tutorial, check out this Hostinger Academy guide on how to solve this generic error:

Subscribe For more educational videos! Hostinger Academy

Conclusion

Encountering a 502 Bad Gateway Error can be annoying, yet it’s a common issue that stems from a communication error between servers.

There are many reasons for this error, including server misconfiguration, overloads, software bugs, and network issues.

To resolve a 502 network error, refresh the page, check server configurations, ensure network stability, flush the DNS cache, or check for widespread downtime.

502 Bad Gateway FAQ

Find answers to some of the most common questions on the 502 Bad Gateway error below.

Is 502 Bad Gateway Permanent?

No, the 502 Bad Gateway error is usually temporary. It can occur due to temporary issues, such as errors in server-side code or DNS problems. You can usually solve the issue by refreshing the page or waiting a few minutes. Even though it’s a server-side error, the 502 Bad Gateway message might appear due to client-side factors like cache or DNS settings.

Is 502 Bad Gateway a Hack?

A 502 Bad Gateway error doesn’t typically indicate a hack. It’s more often a sign of server communication issues, such as when a proxy server receives an invalid response from an upstream server. While it’s possible for malicious activity to lead to server errors, a 502 error on its own does not suggest hacking or security breaches.

Does 502 Bad Gateway Error Affect SEO?

Yes, a 502 Bad Gateway error can affect search engine optimization (SEO) if it persists for a long time. Search engines like Google aim to provide users with a good experience, and inaccessible pages due to server errors can negatively impact a site’s ranking. It’s crucial to resolve these errors promptly to minimize any potential SEO impact.

Author
The author

Nabilla R.

Nabilla is a website hosting and development enthusiast. She loves to share her knowledge with others in order to help them grow their online presence. When she's not busy writing, Nabilla enjoys exploring nature and going on adventures. She is passionate about helping people achieve their online goals.

Author
The Co-author

Matleena Salminen

Matleena is a seasoned Content Writer with 5 years of content marketing experience. She has a particular interest in emerging digital marketing trends, website building, and AI. In her free time, Matleena enjoys cups of good coffee, tends to her balcony garden, and studies Japanese. Follow her on LinkedIn