HTTP 502 Bad Gateway
Server Error5xx Response — Bad Gateway
What Does HTTP 502 Mean?
HTTP 502 Bad Gateway indicates that a server acting as a gateway or proxy received an invalid response from an upstream server. The proxy server could not get a valid response from the origin server.
HTTP 502 typically occurs in reverse proxy setups (Nginx, Cloudflare, AWS ALB) when the backend application server crashes, returns malformed responses, or closes the connection unexpectedly. It is one of the most common errors in load-balanced and microservice architectures.
Common causes include: application server crashes or restarts, backend server overload, network connectivity issues between proxy and backend, incompatible proxy and backend configurations, and DNS resolution failures for upstream servers.
Common Causes of 502 Bad Gateway
The proxy/gateway received an invalid response from the backend. Common causes: backend server crashed or restarting, application process died (PHP-FPM, Node.js, Python WSGI), backend returned malformed response, network issue between proxy and backend, and DNS resolution failure for upstream.
Check backend server logs and process status to diagnose the issue.
How to Fix 502 Bad Gateway
Check if the backend application is running. Restart application processes (PHP-FPM, Node.js, Python WSGI). Verify network connectivity between the proxy and backend. Check for DNS resolution issues. Increase proxy buffer sizes if responses are too large.
For Nginx: check nginx error.log for 'upstream prematurely closed connection' messages.
Related Status Codes
Frequently Asked Questions
What does HTTP 502 mean?
HTTP 502 Bad Gateway is a server error response. HTTP 502 Bad Gateway indicates that a server acting as a gateway or proxy received an invalid response from an upstream server. The proxy server could not get a valid response from the origin server.
Is HTTP 502 an error?
Yes, HTTP 502 is a server error. Server Error responses (ser) indicate the server failed to fulfill a valid request.
How do I fix HTTP 502?
Check if the backend application is running. Restart application processes (PHP-FPM, Node.js, Python WSGI). Verify network connectivity between the proxy and backend. Check for DNS resolution issues. Increase proxy buffer sizes if responses are too l
What causes HTTP 502 Bad Gateway?
The proxy/gateway received an invalid response from the backend. Common causes: backend server crashed or restarting, application process died (PHP-FPM, Node.js, Python WSGI), backend returned malformed response, network issue between proxy and backe
Is HTTP 502 permanent or temporary?
HTTP 502 is situational — it depends on the underlying cause. Fix the root cause to resolve it.
🔍 Check Your IP Address
While you're here, find out your public IP address, location, and ISP details instantly.
Check My IP →