5xx Server ErrorCommonly usedRFC 9110

502Bad Gateway

Upstream server returned an invalid response.

What it means

The server, while acting as a gateway or proxy, received an invalid response from an upstream server. Usually means a downstream service (API, database, microservice) is down or returning errors.

When to use it

  • Upstream API or microservice is returning errors
  • Load balancer cannot reach the application server
  • Reverse proxy (nginx) cannot connect to Node.js app

Common causes

  • Application server crashed or is restarting
  • nginx cannot reach Node.js (wrong port)
  • Upstream microservice is down
  • Network issue between services

Code Examples

nginx configuration
nginx
# 502 often means nginx can't reach your app
# Check your proxy_pass matches your app port:
server {
  location / {
    proxy_pass http://localhost:3000; # Match your app port
    proxy_read_timeout 60s;
  }
}

Quick Facts

Code502
CategoryServer Error
SpecRFC 9110
CommonYes
← Back to all status codes