When NGINX proxy server receives a bad response, then it returns 502 Bad Gateway error to client browser. Here’s how to fix 502 Bad Gateway error in NGINX.
What is a 502 Bad Gateway Error in Apache
You get 502 Bad Gateway Error in NGINX when it is acting as a reverse proxy and receives a bad response from one of the original back end servers. So NGINX returns 502 Bad Gateway error to client browser. There are various reasons why NGINX gives 502 Bad Gateway response that we will look at further. Sometimes, it may even be due to a temporary network issue that gets fixed automatically.
Bonus Read : How to Increase Request Timeout in NGINX
What Causes 502 Bad Gateway Error
Here are the different reasons why you get 502 Bad Gateway Error:
1. Server is down
If your back end server (not reverse proxy server) is overloaded with too many requests and goes down then NGINX will return 502 Bad gateway error. It can also happen if your server goes down due to faulty code, plugins and modules.
2. Server restarts frequently
If your back end server is not configured properly, then it might restart repeatedly and cause NGINX to give 502 Bad Gateway response.
3. Network Issues
This can also happen due to network issues such as DNS resolution issues, routing problems, or firewall blocking server.
Bonus Read : How to Increase File Upload Size in NGINX
How to Fix 502 Bad Gateway Error in NGINX
There are several ways to fix 502 Bad Gateway error in NGINX, both as web developer as well as website visitor. We will look at both cases one by one.
Here’s what you can do to fix 502 Bad Gateway Error in NGINX, if you are a website administrator or web developer:
- Use DNS testing tools to ensure that your domain name resolves correctly.
- Use site ping tools to check if your site is up and running for others. Sometimes, it may be down just for you, due to ISP or network issues.
- Monitor server load to ensure that it is not overloaded
- Inspect firewall logs to determine if there is a sudden increase in blocked requests
- Update plugins and modules to the latest versions
- Use network monitoring issues to identify network issues
- Identify and optimize slow running queries
Bonus Read : How to Hide NGINX Server Version from Header
Here’s what you can do to fix 502 Bad Gateway Error in NGINX, if you are a website visitor:
- Clear browser cache and reload web page.
- Use ping tools to check if your site is up and running for others.
- Disable browser plugins & extensions and try accessing the website
- Check if your ISP is blocking the website.
Hopefully, the above tips will help you fix 502 Bad Gateway Error in NGINX web server.