Web / NGINX Interview questions
How do you troubleshoot a 502 Bad Gateway error in NGINX?
A 502 means NGINX successfully received a request but got an invalid or no response from the upstream server it tried to proxy to - the problem is almost always on the backend side, not in NGINX itself.
- Check whether the backend application is actually running, via its process status or listening port.
- Check NGINX's error log, typically at
/var/log/nginx/error.log, for the specific reason - connection refused, timeout, or reset. - Verify the address and port in
proxy_passmatch where the backend is actually listening. - If the backend is slow, check whether it's exceeding
proxy_read_timeoutor similar timeout directives. - For containerized backends, confirm networking between the NGINX container/host and the backend container is actually reachable.
Because the root cause sits behind NGINX, fixing a 502 usually means restarting, debugging, or scaling the backend application rather than changing NGINX configuration - unless timeouts or the proxied address are misconfigured.
More Related questions...