What do ALB 502, 503 and 504 errors mean?
IntermediateConceptEC2, Auto Scaling and Load Balancing
Answer
- 502 Bad Gateway: the target closed the connection, sent a malformed response, or its keep-alive timeout is shorter than the ALB idle timeout (60 s).
- 503 Service Unavailable: no healthy targets registered, or the target group is empty.
- 504 Gateway Timeout: the target did not respond within the idle timeout, or connection to it timed out (often an SG or NACL issue).
Fix the common 502 by setting the application keep-alive timeout higher than the ALB idle timeout (for example Nginx keepalive_timeout 75s).