AWS ALB Health Check 404
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>
Related videos on Youtube
user2570937
Updated on June 04, 2022Comments
-
user2570937 almost 2 years
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?
-
PHPNoob over 3 yearsWhat port do you have your health checks pinging? Check your security groups on the ALB and EC2 for the open port you are pinging in the health check.
-
user2570937 over 3 yearsi am pinging 80 which is my webserver so i know that is open
-
-
user2570937 over 3 yearshow does it know which website to check since i'm using vhosts?
-
JD D over 3 yearsit forwards traffic to your ec2 instance on the port specified and your web service on that instance should be configured to serve up your website from requests on that port. The mapping of HTTP URI to what is returned is the job of your web server (i.e. apache, nginx, php)
-
user2570937 over 3 yearsyes it is configured however I have about 20 websites being hosted on that instance. You said the ALB knows to check website.com. how does it know to check that url if all i'm putting in the path is healthcheck.php?
-
JD D over 3 yearstypically if you have many things hosted on the same server the differentiator is the port... is each of your web sites configured to use different ports? If not, are the websites differentiated via path? If they are differentiated via path and the root folder is just the default one (
var/www/html
) then the correct value for healthcheck would be something like/generic/website.com/healthcheck.php
-
user2570937 over 3 yearsyes, I'm using name based virtual hosts so everything is on the same port. I just changed the path to /generic/website.com/healthcheck.php and i'm still getting a 404
-
user2570937 over 3 yearsthis is what my apache access log is showing [19/Aug/2020:15:56:41 -0700] "GET /generic/website.com/healthcheck.php HTTP/1.1" 404 196 "-" "ELB-HealthChecker/2.0"
-
JD D over 3 yearswhat you are getting in the access logs makes sense... do you have an example of a path that works? for example, if you wanted to get a response from the localhost, what path would you use? For example if you are sshed onto the machine and do
curl http://localhost:80/??/healthcheck.php
, what is the value of??
? If you have the answer to that, that will be the same path you put into the healthcheck