AWS Elasticbeanstalk single instance Force SSL Redirect loop

Viewed 3964

I'm having issues by forcing ssl. I'm using codeigniter and deployed it in AWS single instance with elasticbeanstalk. My htaccess rules below:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule !/status https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

But browser gets in a redirect loop. Whatever i tried didnt solve this problem.

5 Answers

I believe (give your exception for /status) that you are using the "Load-balancing, Autoscaling Environment" which means you have an Elastic Load Balancer in the middle.

If you setup your environment with Elastic Load Balancing, than what may be happening is if the Elastic Load Balancer (ELB) is using (serving) secure content (HTTPS).

However, if the traffic between the ELB and the EC2 Instances is unsecure, your code will always detect an unsecure connection because the EC2 client is actually the ELB, not the end user (think of the ELB as a proxy).

Side note, I'm not sure how the SERVER_NAME variable will work with an ELB in the middle.

That said, if your intention was for a single-instance, non-load balanced environment, you can "turn off" the load balancer (possible since July 2013). (see ref #3)

Reference: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.managing.elb.html http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features-managing-env-types.html Elastic Beanstalk without Elastic Load Balancer

Related