Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

AWS Load Balancer ERR_TOO_MANY_REDIRECTS

Writer Andrew Henderson

I've been dipping into AWS for the 1st time am bit stuck with a problem trying to set up a load balancer (ELB).

So far I have used ECS to create 2 EC2 instances that are running a container each with an app listening on port 3000.

For each of the instances I am able to browse to their IPv4 Public IPs specifying port 3000 and get to the containerised app. I am able to log in and use the app as expected.

So I thought the right thing to do next is set-up an ELB which would not only balance the load(!) but also handle port forwarding.

The ELB has a port 80 Listener, and I have a Target Group in which I have registered my ECS instances on port 3000.

I have then popped the ELBs DNS name (i.e. my-load-balancer-123456789.eu-west-1.elb.amazonaws.com) into my browser and was presented with the logon page of my app.

All good until I actually log on. I am then presented with the error message:

ERR_TOO_MANY_REDIRECTS: my-load-balancer-123456789.eu-west-1.elb.amazonaws.com redirected you too many times.

I have 2 questions

1: Why is the redirect loop happening?

2: Are there any diagnostic tools that I should know about which would help me with problems like this in the future?

Update: I have tried clearing all my browser cookies btw.

Any help appreciated.

3

2 Answers

This issue is pretty common when you have redirects being done by the server itself. AWS has a guide for how to prevent these issues.

The following leads to an infinite loop of redirection between the load balancer and the backend web server:

  • The rewrite rule on the web server for directing HTTP requests to HTTPS forces requests to use port 443 for HTTPS traffic on the load balancer.
  • The load balancer still sends requests to the backend web server on port 80.
  • The backend web server redirects requests to port 443 on the load balancer.

The error ERR_TOO_MANY_REDIRECTS is returned, and the requests are never served.

To resolve this, change your web server’s rewrite rule using the X-Forwarded-Proto header of the HTTP request to apply only if the client protocol is HTTP. Ignore the rewrite rule for all other protocols used by the client.

Note: If you're using Application Load Balancers, use redirect actions to redirect traffic instead.

1

I ran into the same issue and this is what solved it for me:

  1. I configured both ports 80 and 443 as listeners on the Load balancer - The latter required the use of the Amazon certificate manager () which started managing certificates for my servers.
  2. I retained the following redirect rule for port 80 on the server - "Redirect / "
  3. I changed the SSL settings from "SSLEngine on" to "SSLEngine off"

The final point is extremely important so you do not get stuck in the infinite loop that Jeremy mentioned above.

I hope this helps someone as I have been stuck with this for weeks with a stateful app a company I am consulting for waiting to go live.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy