Back to all status codes
502

Bad Gateway

The server acting as a gateway received an invalid response from an upstream server.

Common Causes

  • Upstream server down
  • Proxy misconfiguration
  • Network issues
  • Firewall blocking
  • Backend crash

Fix Solutions

Check upstream server

Verify the upstream server is running and accessible.

Review proxy config

Ensure proxy_pass URL is correct in Nginx/Apache configuration.

Increase timeouts

Increase proxy timeout values for slow upstream servers.

Code Examples

# Proxy configuration with timeouts
upstream backend {
    server 127.0.0.1:3000;
    keepalive 64;
}
location /api {
    proxy_pass http://backend;
    proxy_connect_timeout 60s;
    proxy_send_timeout 60s;
    proxy_read_timeout 60s;
}

Related Tools