Pre Black Friday Sale. 20% OFF on all products. Coupon code: fme20off

How to Fix Magento 502 Bad Gateway Error?

How to Fix Magento 502 Bad Gateway Error?

Although Magento is one of the most widely used eCommerce platforms, the learning curve is a bit steep. You may frequently run into issues that require just a few clicks to fix. Since you may not have the technical know-how, fixing them may require Magento experts. Speaking of errors, one of the most common errors you are likely to encounter is the 502 Bad Gateway. In this article, we will discuss everything there’s to know about this error including what causes it and how to fix it.

What is Magento 502 Bad Gateway Error?

The Magento 502 bad gateway error is an HTTP status code that indicates that a server has received an invalid response (or a response it can’t understand) from another server. The problem with this error is that it does not tell exactly what the issue is leaving you wondering what could have caused it. When this happens, it just displays the error in your browser as shown below.

502 bad gateway error

Please note that 502 is an umbrella term which includes several other types of errors, including HTTP Error 502- Bad Gateway, 502 Proxy Error, 502 Service Temporarily Overloaded, and 502 Bad Gateway NGINX. Thus, as long as you see 502 in the error, you can categorise it as a 502 Bad Gateway.

Possible Causes of the Magento 502 Bad Gateway Error

A number of reasons can lead to a 502 bad gateway error in Magento 2. The following are the most common.
  • Server overload
  • When the website experiences a sudden increase in traffic, it may overwhelm the server, causing problems in website loading.

  • Firewal
  • In certain cases, the firewall may be restricting access to the website.

  • Network Error
  • DNS issues and other similar ones can cause the 502 bad gateway error to show up.

  • PHP request timeout
  • When PHP requests longer than the required time to execute.

  • Server Offline
  • If the server is offline, it will display a 502 error.

  • Browser Issues
  • Certain extensions in the browser may prevent the website from loading, leading to a 502 error.

What Impact Does the 502 Error Have on your Magento Store?

Don’t ignore the 502 error in any case. Investigate the issue promptly as it has a significant impact on various aspects of the store. Let’s see.
  • Search Engine Optimization(SEO)
  • When your site or a specific page continuously returns a 502 error, search engines will consider that the page or site is not available. It will start pushing the page lower and lower in the rankings. Eventually, the page may be deindexed altogether.

  • Sales
  • If your Magento 2 store does not load, how will it generate sales? Thus, there’s a direct link between this error and your store’s performance.

  • Customer Satisfaction
  • Similarly, a recurring 502 bad gateway error will impact the customer satisfaction rate. Even your loyal customers may be reluctant to visit your store since they are likely to experience errors.

  • Brand Reputation
  • With recurring website problems and lower customer satisfaction rate, your store’s reputation will take a hit. The last thing you want is the target audience referring your website as something that never loads.

    Overall, ignoring the 502 Bad Gateway Error is not an option. So, let’s focus on how to fix it.

How To Fix 502 Bad Gateway Magento 2 Error? (For Front-End Users)

  • Refresh the Page
  • In most cases, simply reloading the page will resolve the issue. Wait for a few seconds before doing so. If that doesn’t work, move to the next step.

  • Clear Browser Cache
  • There is a highly probability that a cache file stored on your computer is causing the problem. In that case, you need to clear the cache. Once you do, close the browser and open it again. If that doesn’t resolve the issue, check the following step.

  • Reset the Browser
  • It may be that you changed the browser settings (knowingly or unknowingly). If you can revert the settings, that’s perfect. If not, you will need to reset the browser settings to default. In most cases, this addresses the 502 bad gateway error in Magento 2.

  • Change the Browser
  • If you are using Microsoft Edge, try switching to Chrome or any other browser.

  • Restart the Computer
  • If nothing works, try restarting the computer and see if the website loads properly afterwards.

  • Reset the Internet Settings
  • If none of the above solutions work, try resetting the internet settings. Reconnect to the internet to see if the issue is resolved.

    If the above steps don’t work, it indicates problems at the back-end.

How To Fix 502 Bad Gateway Magento 2 Error? (For Back-End Users)

  • Check Server Connectivity
  • Before undertaking any fix, check if the server connectivity is working properly. Your hosting provider may not have informed you about server downtime for routine maintenance. Run a ping test to check if the server is accessible or contact the hosting provider directly.

  • Increase Server Capacity
  • A server gets overloaded when unusually high amount of traffic occurs exceeding the allocated server resources. This causes pages to load slow and eventually leads to the 502 error. To counter this issue, you can increase your server resources to sustain high traffic.

  • Restrict IP Address and Use CDN
  • Another reason for servers to get overloaded is the DoS/DDoS attack from specific IPs. You can resolve this by blocking these IP addresses in your .htaccess file. Secondly, use content delivery networks (CDN) as it helps mitigate the DDOS attacks.

  • Limit Cron Jobs
  • Frequent execution of cron jobs also loads the server. Try to prolong the interval by at least 15 minutes to avoid this issue.

  • Check PHP Script
  • If a PHP script takes longer than 30 seconds to execute, it returns Fatal Error: Maximum Execution Time Exceeded. For this, go to php.ini (usually located in /etc/php/7.2/apache2/php.ini) and modify the value of max_execution_time to a greater value. For example, max_execution_time = 300.

  • Check Plugins/Themes
  • If the issue still persists after trying all the above methods, it’s most likely due to one of your installed plugins/themes and it’s time to check them one by one. It can take time to identify the troublemaker but once it’s identified it will most certainly resolve not only this issue but many other potential issues. Start by deactivating individual plugins and see if it fixes the issue. If not, activate it again and go to the next one and so on until you find the offending one.

  • Check for Programming Errors
  • There’s a high probability that there are errors in the website’s code that is causing the problems. Check the website’s code thoroughly or use tools for this purpose. If you cannot detect the issue, use our developers. They will diagnose the issue and recommend the most appropriate fix.

Make the 502 Bad Gateway Error More Engaging

Don’t display the default 502 bad gateway error page. The last thing you want your audience to see is this annoying page. Thus, make it more engaging to lessen its impact. What you can do is list instructions for the users on how to fix. For instance, tell them to try refreshing the page or clear the browsing cache. Also, mention that you are trying to resolve the issue promptly and the site will be back live shortly. A simple message shows your customers that you care about them.

Conclusion

This concludes our article on how to resolve the Magento 2 502 bad gateway error. If you keep ignoring the issue, it will have a significant impact on your sales, online visibility, and brand reputation. Thus, as soon as you start experiencing this error, start working on the fix.

This blog was created with FME's SEO-friendly blog