What is a 502 bad gateway error (and how can you fix it)?
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.
Table of contents
- What is a 502 Bad Gateway error?
- Causes of a 502 Bad Gateway error
- Impacts of 502 Bad Gateway errors on e-commerce websites
- Deal with 502 Bad gateway errors (for users)
- How to Fix 502 Bad gateway errors (for developers)
- How to make 502 Bad Gateway less annoying for your visitors?
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
Impacts of 502 Bad Gateway errors on e-commerce websites
In case that this error happens continually on your site, it will ruin the performance of your webpage seriously for both visitors and the search engines.
The search engines always prioritize their audiences. If a site returns 502 Bad Gateway errors regularly, it will be ranked lower and lower. Because the search engines will not let customers face a continually unavailable site.
Imagine that you are happy that you find a desired product in one online store and click on it right away, but…it serves you a dumb 502 Bad Gateway page.
If this error happens repeatedly with a number of your visitors and customers, they surely throw their patience away and neve return to your sites.
Deal with 502 Bad gateway errors (for users)
Reload the page When you see this error, which is maybe because the server is overloaded with an unexpected high amount of traffic or there is a normal issue on the server connectivity. If you wait one or two minutes, then refresh the page, you might see this error disappear.
Clear your browser cache
There is a case that a corrupted file staying in your browser might cause a 502 Bad Gateway. If you clear the cache or remove the cookies, it can help in resolving this error.
Switch to another browser
If you meet this error in one browser, you can try to try another one to check whether other browsers have this error or not. If the error occurs with all the browsers, then you know that the problem is not here.
Reset your Internet configuration
You can also try to restart your internet modem, wait for your computer to connect to the internet again, open the browser and check whether the page can be load or not.
How to Fix 502 Bad gateway errors (for developers)
Check the server connectivity
If your website server is under maintenance or down for any reason, your visitors will meet the 502 Gateway Error page.
If your server is actually down, you have to wait until it works again to solve the error.
If you don’t want to contact your server provider, you can run a ping test to check whether your server is reachable or not.
Check for any DNS modifications
If you have recently changed your host server or your website’s IP address, your domain’s DNS records changed as well. This could evoke a 502 Bad gateway error.
You have to wait until these DNS changes are fully completed or check if the IP in the records is set correctly without any typo.
What is DNS? DNS is the phonebook of the internet. When people access websites through domain names such as mageplaza.com, ,web browsers interact through Internet Protocol (IP) addresses.
Clear local DNS cache
If the DNS has changed and the cache has not been cleared, the 502 error can occur.
To do this, you open your cmd prompt for windows users, then open the command prompt on your windows PC and type inconfig / flushdns then press enter.
Check your logs
The server logs provide particular details about errors being thrown on the server. You should sift through them to uncover and respond to any error alarm.
Resolve faulty firewall configuration
As your firewall protects your website from any malicious traffic, it sometimes can deem a request from a content delivery network because of a faulty firewall configuration. When your firewall rejects the content delivery network, your visitors will be shown the 502 error page.
So, you should temporarily disable your firewall and see whether the issue still occurs or is resolved. If the error still persists, then check your configuration.
Find bugs on your website’s programming
There is a chance that your website’s code can have bugs making your server wrongly answer requests form a content delivery network.
Check your codes to detect bugs or take a development machine to do the checking. This will help you to solve the problem or see the exact moment where the issue was raised.
Disable CDN temporarily
Another reason could be that the server is targeted by a DDOS attack.
What is a DDOS attack? A DDOS (distributed denial-of-a-service) attack is a malicious action to disrupt normal traffic of a server, service or network by a flood of online traffic
To avoid this problem, you should use content delivery network providers to mitigate these DDOS attacks on the server.
Contact your hosting provider
If you cannot figure out the solution to your 502 Bad Gateway error, you might need to contact your hosting provider for assistance.
If the root of the error is on the hosting provider’s side, they will fix it eventually. However, in case the problem originated from your website, they will possibly help you to find the solution.
How to make 502 Bad Gateway less annoying for your visitors?
Have a friendly error page
502 Bad Gateway error is both an unavoidable and unexpected one, you cannot avoid them completely but you can make it less annoying. Here is an example:
Recommend some self-fixes if possible
Try to instruct your visitors to fix the error with above-mentioned ways. Such as tell them to “refresh the page” or “try another web browser” to tackle the issue initially. At least, your visitors know that you care about their disappointment.
Tell customers that you are working on the problem
On the 502 Bad Gateway error page, you should inform your visitors that you are trying to fix the error. At least, you give them “a hint” that they can come back later for when the fixing is done.
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!
not your workload
Simple, powerful tools to grow your business. Easy to use, quick to master and all at an affordable price.Get Started
People also searched for
- 502 bad gateway nginx
- what does 502 bad gateway mean
- what is 502 bad gateway
- 502 bad gateway cloudflare
- bad gateway 502
- error 502 bad gateway
- steam 502 bad gateway
- 502 bad gateway fix
- discord 502 bad gateway
- 502 bad gateway discord
- what is a 502 bad gateway
- aol 502 bad gateway
- how to fix 502 bad gateway
- 502 bad gateway nginx fix
- 502 - bad gateway
- 502 bad gateway wordpress
- ngrok 502 bad gateway
- aol mail 502 bad gateway
- chegg 502 bad gateway
- 502 bad gateway the server returned an invalid or incomplete response.
- bad gateway error 502
- 502 bad gateway phpstorm
- http 502 bad gateway
- 502 bad gateway we can't get the requested page ;(
- phpstorm 502 bad gateway
- wordpress 502 bad gateway
- aws 502 bad gateway
- nginx 502 bad gateway php
- linksys 502 bad gateway
- fix 502 bad gateway
- 2.2.x, 2.3.x, 2.4.x