What is a 502 bad gateway error (and how can you fix it)?
Summer Nguyen | 11-11-2024
Do you frequently face the 502 Bad Gateway errors? Whether you are a user, a developer or a store owner, you still want to figure out how to fix this error, Don’t you?
In this article, Mageplaza will walk you through the process of identifying causes and fixing this error.
Terms to know before jumping in the article:
-
Network: a network is a group of multiple devices that communicate with each other. The group can consist of a small number of the two computers or the larger number such as billions of devices.
-
Gateway: a gateway is actually a hardware that acts as a “gate” between two networks. These gateways will control the traffic and enable it to flow in and out of the network.
-
Server: a server is a computer that provides data for other computers. For example, you are sitting in front of your laptop and type in the search box “apple.com”, so your computer is now called a client. This client makes a request to a server to “provide” it the data of Apple’s website.
-
Firewall: a firewall is a software network defense that monitors and controls incoming and outgoing traffic between two networks based on predetermined rules.
What Is A 502 Bad Gateway Error?
502 Bad Gateway is a HyperText Transfer Protocol (HTTP) status code occurring when a gateway receives an inadequate response from the other servers.
Just to make it clear, 502 Bad Gateway is an indicator showing that there is an issue in a website’s server communication. Also, this error does not actually tell you the exact issue, it just serves an error web page to website’s visitors.
If you have ever seen these errors, they are also 502 Bad Gateway errors:
- HTTP Error 502- Bad Gateway
- 502 Proxy Error
- 502 Bad Gateway
- 502 Service Temporarily Overloaded
- HTTP 502
- 502 Bad Gateway NGINX
- Error 502
Causes of A 502 Bad Gateway Error
You probably have met this error several times. There are a number of reasons that might lead to a 502 error. Here are the most common causes:
- Server overload: when an unexpectedly high amount of traffic accesses the site and the server can not “server” all of them because it has exceeded the operational memory capacity
- Request restricted by a firewall: when the request is blocked by a firewall
- Code errors: sometimes an error in a website’s code may make the wrong requests that cannot be answered correctly, making this error to show up
- Network errors: DNS issues, routing problems, and ISP related issues can also lead to a 502 Bad Gateway error
- Server timeouts: when a server takes too long to complete the request
- Browser error: occasionally, browser extension can cause website displaying error and provoke the 502 Bad Gateway error
Variations of 502 Bad Gateway Error
Since there are a lot of web servers, browsers, and operating systems, 502 Bad Gateway can also be presented in different ways. However, all of them share the same meaning. Let’s explore the variations of this error!
- “Error 502”
- “502 Bad Gateway”
- “502 Proxy Error”
- “HTTP Error 502 – Bad Gateway”
- “502 Service Temporarily Overloaded”
- Blank white screen with no information on it
- “502 Server Error: The server encountered a temporary error and could not complete your request”
- “HTTP 502”
- Temporary Error (502)
-
- That’s an error
- 502 bad gateway Cloudflare
- Bad Gateway: The proxy server received an invalid response from an upstream server
On other services, like Twitter (now X), you may find a completely different message displaying. For example, it can be “Twitter is over capacity.”
For Google, here’s how it displays the 502 Bad Gateway error.
Impacts of 502 Bad Gateway errors on e-commerce websites
1. Poor User Experience
The most serious impact of the 502 Bad Gateway error is that it makes customers unhappy. Encountering such a problem can frustrate the shoppers and disrupt their browsing journey, leading to loosing potential clients. This might also be a bad impression.
2. Reduce Website Traffic
Carrying annoying feelings, chances are they won’t come back in the future. This significantly damages your website traffic. It’s the same with walking into a store during normal business hours, and the store is closed, or the employee can’t serve. The most common reaction in this situation would be to leave for other stores.
3. Impact on SEO Rankings
If your store frequently encounter 502 Bad Gateway error, it will harm your website rankings on search engines. Why? Because one of the most essential things for search engines to consider a site good is user experience, and obviously, letting your visitors face an error several times will be evaluated as unreliable or poor-maintained.
How to Solve 502 Bad Gateway Error
Normally, the 502 Bad Gateway error is not permanent. You can wait about 30s for it to disappear or try the following methods to troubleshoot it faster.
1. Refresh the site
This problem usually happens due to traffic spikes, so refresh it is a quick solution.
-
Refresh the page on Window:
- Method 1: Press F5
- Method 2: CTRL + F5
-
Refresh the page on Mac: Press CMD + R
2. Check the site status
If the 502 error code still doesn’t disappear, the website’s server may be currently experiencing downtime. You can use site-checking tools to find out your site status. Just paste your store URL into these tools, and they will do the rest.
Suggestion:
3. Clear browser cache
Another method to solve this issue is clearing your browser cache, which may carry out-of-date or corrupted files. This action will remove those unnecessary files.
Reminder: Don’t forget that important browser data (like setting preferences and bookmarks) can also be removed with cached files. So, export your data before clearing the cache.
4. Try in the Incognito Mode
Open the website in Incognito mode to see if the issue relates to the browser. Click the three dots in your browser, then select “New Incognito Window.”
Or press CTRL + Shift + N and paste the site URL in your Incognito tab.
If it works in Incognito mode, your browser extensions could be causing the problem. Disable them one by one, especially ad-blockers, and try again. If it still doesn’t work, try a different browser.
5. Flush the DNS Cache
DNS issues like wrong IP addresses can cause 502 Bad Gateway, too. Flushing your DNS cache is similar to clearing your browser’s cache. You can also temporarily change your DNS servers to something like Google Public DNS.
6. Test on Another Device
If nothing has worked so far, try accessing the site on another device or network. Restarting your computer or router can also help identify whether it’s a network problem.
7. Check Error Logs
Pay attention to the time when this error happened. Is it before or after you made some changes to your site? If it’s after, the reason may come from the server.
You should check the website’s error log for more information. If you are using WordPress, try enabling the error log by adding the below lines to your wp-config.php file:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
Result: The errors will appear in the wp-contents/debug.log
file.
8. Check plugins and themes
Plugins or themes can also be the reasons for this error. Sometimes, poorly coded themes and modules conflict with each other, so the site can’t work properly.
In this case, you should install a caching or security plugin. Additionally, you can disable all your plugins and re-activate each of them while refreshing your site. This method will let you know exactly which one is causing the error. It’s the latest plugin that you re-activate before the 502 error happens again.
9. Check the content delivery network
The next factors causing 502 Bad Gateway errors are CDN (content delivery network) and DDoS migration services.
First, you need to understand how it works. The CDN adds an additional layer between the server and browser in order to deliver web content more effectively. This layer, however, becomes a problem when it can’t connect with your site’s original server. As a result, 502 error happens.
Now, let’s examine a notable case - Cloudflare, having 502 Bad Gateway in 2 different variations.
The image above shows that the problem is on Cloudflare’s side, not yours. As a result, you can’t fix it yourself but need to contact their customer support team for assistance. To fix it, you’ll need to reach out to their customer support team. Check the Cloudflare System Status page before reaching out to them; that would be great.
Or, you can disable Cloudflare, but the process might take a couple of hours.
When you find the Cloudflare error appeared like above, it means the issue is no longer in Cloudflare’s side, but it’s on your web hosting provider. To solve it, talk to your web host team and ask for their help.
10. Increase PHP max_execution_time and max_input_time
A 502 error can also happen if a PHP process runs longer than allowed by the max_execution_time or max_input_time settings, which are usually set by default at 300s. To fix this, you can ask your hosting provider to check and increase these values.
FAQs
Q1. Is the 502 Bad Gateway error permanent?
No, it’s usually temporary and can be resolved by refreshing the page or fixing issues like server errors or cache problems.
Q2. Does the 502 Bad Gateway error mean my site is hacked?
No, this error is usually due to server communication issues, not hacking. While server errors can sometimes result from malicious activity, a 502 error by itself doesn’t indicate a hack.
Q3. Can a 502 Bad Gateway error affect SEO?
Yes, if it persists, it can hurt your SEO. Search engines like Google might lower your site’s ranking if users can’t access it due to repeated server errors. Fixing it quickly will minimize any impact on SEO.
Conclusion
A 502 Bad Gateway error is not something to be panic about. It’s just an error evoked from a communication problem between servers. Mageplaza hopes that you can fix your error by trying these solutions. If you have any new solution, quickly tell us in the comment box below!