The 502 Bad Gateway error is an HTTP status code indicating that a server acting as a gateway or proxy received an invalid response from an upstream server. It commonly appears in web applications using reverse proxies, load balancers, or microservice architectures.
In HTTP communication, a gateway (like Nginx or Apache) forwards client requests to backend services. If the backend crashes, times out, or returns malformed data, the gateway responds with:
Status Code: 502
Meaning: Bad Gateway
// Nginx configuration example that may trigger 502 if backend is down
server {
listen 80;
location / {
proxy_pass http://127.0.0.1:3000;
}
}
If the Node.js app on port 3000 is stopped or crashes, Nginx cannot get a valid response and shows 502 Bad Gateway to the user.
Toggle the server status and send a request to see the Gateway's response.