amazon-web-servicesapacheamazon-ec2amazon-elbaws-alb

AWS ALB Health Check 404


I have an ALB with 2 targets in the target group. However my health check aren't working properly. Both are showing

"Health checks failed with these codes: [404]"

My settings for the health check path are:

/var/www/html/generic/website.com/healthcheck.php

and if I do a nano /var/www/html/generic/website.com/healthcheck.php on the ec2 instance it shows this which should be all the health check needs I think.

<?php
header("Status: 200");
?>

I double checked the AZ and the ALB is in the same one and subnets as the 2 instances. Also when I check my apache logs this is what I see:

"GET /var/www/html/generic/website.com/healthcheck.php HTTP/1.1" 404 196 "-" "ELB-HealthChecker/2.0"

What am I doing wrong that is making the healthcheck fail?


Solution

  • Seems you can't use a namebased vhost for a healthcheck. So in my vhost file I added the following code. What it does is if someone goes straight to your ip it will give them a 404 but if they go to your ip/healthcheck then it will show a 200 which is what ALB needs. Then in your path just put /healthcheck.

    <VirtualHost *:80>
      ServerName default
      RewriteRule "/healthcheck" - [R=200]
      Redirect 404 /
    </VirtualHost>
    <VirtualHost _default_:80>
      RewriteRule "/healthcheck" - [R=200]
      Redirect 404 /
    </VirtualHost>