Server Error (5xx)

HTTP 502 β€” 502 Bad Gateway

The server, while acting as a gateway or proxy, received an invalid response from the inbound server it accessed.

Common Causes & Diagnoses
  • β€’Backend Node.js / Python PM2 process crashed or is down.
  • β€’Nginx proxy_pass pointing to wrong internal port.
  • β€’Upstream server ran out of memory (OOM killed).
Spesifikasyon & Kategori
Status Code:502
Category:Server Error (5xx)
RFC Standard:RFC 9110 / HTTP/1.1 & HTTP/2
Multi-Language Code Implementations

How to Handle, Return & Test HTTP 502

Status: 502 502 Bad Gateway
server.js / handler.ts
// Express.js Server Response
app.get('/api/resource', (req, res) => {
  // Returning 502 502 Bad Gateway
  return res.status(502).json({
    error: '502 Bad Gateway',
    statusCode: 502,
    timestamp: new Date().toISOString()
  });
});

// Client-side fetch error check
const response = await fetch('/api/resource');
if (response.status === 502) {
  console.warn('Received HTTP 502 502 Bad Gateway');
}
πŸ’‘ Pro Tip: Ensure appropriate error handling middleware or proxy interceptors are enabled so client applications receive structured JSON responses for HTTP 502.
How to Fix / Practical Code Solutions

Check PM2 or Systemd Backend Service

Verify if backend application process is running.

pm2 status
pm2 logs backend
systemctl status nginx
Other Popular HTTP Status Codes
Frequently Asked Questions

Common Questions About HTTP 502 to RFC Standard

Everything you need to know regarding specifications, syntax, and security best practices.

The server, while acting as a gateway or proxy, received an invalid response from the inbound server it accessed. In Turkish: Ters proxy (Nginx, Cloudflare), arka plandaki uygulama sunucusundan geΓ§ersiz yanΔ±t aldΔ±.