HTTP 502 Bad Gateway — What It Means & How to Fix It
About HTTP 502 Bad Gateway
The HTTP 502 Bad Gateway status code indicates a server acting as a gateway or proxy received an invalid response from an upstream server. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.
Here are the key things to understand: This error occurs in multi-server architectures where a proxy or load balancer forwards requests.. The gateway or proxy server itself is working, but the upstream server is not responding correctly.. Common with nginx, Apache reverse proxies, CDNs, and load balancers.. The upstream server may be down, overloaded, or returning malformed responses.. It is often a transient error that resolves on its own.. Understanding these fundamentals will help you diagnose and resolve this issue more effectively.
The most common reasons this occurs include: The upstream server is down or not responding.. The upstream server returned a malformed or invalid response.. Network issues between the proxy and the upstream server.. The upstream server is overloaded and cannot handle the request.. Identifying the root cause is the first step toward finding the right solution.
To resolve this, follow these recommended steps: Retry the request after a short wait as it is often transient.. Check if the upstream server is running and healthy.. Review proxy and load balancer logs for detailed error information.. Verify network connectivity between the proxy and upstream server.. Check upstream server resource utilization (CPU, memory, connections).. If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.
This article is part of our HTTP Status Codes collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.
Quick Answer
What does HTTP 502 Bad Gateway mean?
It means a server acting as a proxy or gateway received an invalid response from the upstream server it was forwarding the request to.
Overview
The HTTP 502 Bad Gateway status code indicates a server acting as a gateway or proxy received an invalid response from an upstream server.
Key Details
- This error occurs in multi-server architectures where a proxy or load balancer forwards requests.
- The gateway or proxy server itself is working, but the upstream server is not responding correctly.
- Common with nginx, Apache reverse proxies, CDNs, and load balancers.
- The upstream server may be down, overloaded, or returning malformed responses.
- It is often a transient error that resolves on its own.
Common Causes
- The upstream server is down or not responding.
- The upstream server returned a malformed or invalid response.
- Network issues between the proxy and the upstream server.
- The upstream server is overloaded and cannot handle the request.
Steps
- 1Retry the request after a short wait as it is often transient.
- 2Check if the upstream server is running and healthy.
- 3Review proxy and load balancer logs for detailed error information.
- 4Verify network connectivity between the proxy and upstream server.
- 5Check upstream server resource utilization (CPU, memory, connections).