Why did I receive an HTTP 5xx error when connecting to web servers running on EC2 instances configured to use Classic Load Balancing?
Last updated: 2022-06-17
I received an HTTP 502, 503, or 504 errors when I tried to connect to web servers running on EC2 instances configured to use Classic Load Balancing. How can I troubleshoot and resolve 5xx errors?
HTTP 502 (Bad Gateway)
You might receive an HTTP 502 error if either the web server or associated backend application servers running on EC2 instances return a message that can't parsed by Classic Load Balancer (CLB).
HTTP 503 (Service Unavailable)
HTTP 503 errors can occur for several reasons, including:
- The surge queue is full. Check that your instances have enough capacity to handle the request rate by reviewing the SpilloverCount metric.
- There are no healthy instances. Make sure that you have healthy instances in every Availability Zone that your load balancer responds. To do this, review the HealthyHostCount metric. For more information, see Troubleshoot a Classic Load Balancer: Health checks.
- You haven't registered at least one instance in every AZ that your load balancer responds in. If you can't confirm that an instance is registered in each AZ, then turn on cross-zone load balancing.
- Connection draining is not turned on for the Classic Load Balancer that your web server instances are registered with.
For help resolving this error, see How do I troubleshoot HTTP 503 errors returned while using Classic Load Balancer?
HTTP 504 (Gateway Timeout)
HTTP 504 errors occur for the following reasons:
- Web server instances or backend application server instances are busy and can't respond to requests within the configured Elastic Load Balancing (ELB) idle timeout limit. For more information, see Troubleshoot high latency on my ELB Classic Load Balancer.
- Web server instances or backend application server instances terminate connections before the load balancer does. This results in premature connection terminations.
- Web server instances or backend application server instances have crashed or restarted server processes when requests are in-flight. This results in the server breaking all connections.
- Apache web server instances have the AcceptFilter http/https option turned on. This instructs Apache to implement TCP_DEFER_ACCEPT on the connections.
- Apache web server instances have the event MPM turned on but have not optimally configured the prefork and worker MPMs. The default ELB idle timeout limit of 60 seconds. For more information, see What are the optimal settings for using Apache or NGINX as a backend server for ELB?
For help resolving this error, see How do I troubleshoot HTTP 504 errors returned while using a Classic Load Balancer?