Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force https on amazon elastic beanstalk without failing the health check [duplicate]

I have configured my Elastic Beanstalk environment to redirect all pages to https, redirection works, however, the instance fails the health check and gets terminated, any ideas how to configure the rewrite rules?

My configuration:

NameVirtualHost *:80

<VirtualHost *:80>
.
.
.

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule !/_hostmanager/healthcheck https://%{SERVER_NAME}%{REQUEST_URI} [L,R] 
</VirtualHost>
like image 457
user867340 Avatar asked Jul 28 '11 11:07

user867340


2 Answers

There's multiple hostmananger URLs that Elastic Beanstalk needs to access besides the health check. Grepping /var/log/httpd/elasticbeanstalk-access_log, I see requests to /_hostmanager/tasks and /_hostmanager/healthcheck.

Here are the rules that I added to /etc/httpd/sites/elasticbeanstalk on my EC2 instances:

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{REQUEST_URI} !^/status$ 
RewriteCond %{REQUEST_URI} !^/version$ 
RewriteCond %{REQUEST_URI} !^/_hostmanager/ 
RewriteRule . https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

Note that I'm also allowing non-https traffic to my /status and /version pages. I'm actually using /status as the actual healthcheck lookup URL, so having that traffic skip the rewrite will avoid the redirect and make the status lookup faster (I'm assuming).

like image 171
Joel Rosenberg Avatar answered Oct 06 '22 01:10

Joel Rosenberg


I think that some of the other answers on here may not be based on whatever the arbitrary User-Agent AWS is currently setting. When I watch the Apache logs, I see this User-Agent:

ELB-HealthChecker/1.0

As of writing this, the following mod_rewrite rule is working for me:

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_USER_AGENT} !^ELB-HealthChecker.* 
RewriteRule . https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
like image 38
vcardillo Avatar answered Oct 06 '22 01:10

vcardillo