My ELB keeps taking my instances out of service, because the HTTP health check is failing.
We have a DNS wildcard, and redirect everything to www:
vhost.conf:
ServerName www.example.com
ServerAlias *.example.com
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^ http://www.example.com/$1 [R=301,L]
This works fine for actual browsers, but the HTTP health check to / fails, presumably because it's getting a 302.
Is the best option to use a TCP health check, or is there a way to get HTTP to work?
This question has been asked on the AWS forums and the answer was to set up a default vhost that handles traffic on the bare IP address and doesn't do any redirects. This will mean that normal users who hit your IP address will not be redirected either.
You could alternatively specify the path part of the URL that you want the ELB to request and ignore that path by adding another RewriteCond:
Normal users who hit that URL will not be redirected.
You could also use the same technique to detect the User-Agent of the ELB.
Normal users who spoof their User-Agent will not be redirected.
Or the internal IP address of the ELB.
For this option to work, you will require either
mod_rpaf
(for Apache 2.2) ormod_remoteip
(for Apache 2.4) to modify theREMOTE_ADDR
variable to contain the correct part of the contents of theX-Forwarded-For
header. As long as you set that up correctly, it shouldn't be possible for a normal user to avoid the redirect response.Adding virtual hosts is not a good idea, since one has to restart httpd service for virtual hosts to get reflected. There is an alternative way of doing this
separate all four parts of the dns name like follows
elb_dns_name: elb-name.subnet_zone.elb.amazonaws.com
For all the remaining urls have internal rewrite rules
directory_scructure: code_folder/website
RewriteEngine On
RewriteCond %{HTTP_HOST} !$ [NC]
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteRule ^(.*)$ /$1 [L,QSA]
This worked very well for me. Please suggest if there are better methods cheers!