user2570937
user2570937

Reputation: 852

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?

Upvotes: 6

Views: 50212

Answers (4)

Abid Shaikh
Abid Shaikh

Reputation: 11

For testing or to ensure the server is working properly, you can include a status code 404 among the success codes. This helps indicate to the load balancer that everything is okay, like a green signal and it'll put that server status as healthy.

source_codes

Upvotes: 0

Arun Kamalanathan
Arun Kamalanathan

Reputation: 8583

Since you have multiple named hosts in nginx. What you could try is setting the healthcheck on the / with 200 OK as the status code. it should return the default nginx page with status code 200 OK.

Another method is, you can add healthcheck url that doesn't exist such as /my-health-page and in the health check configuration set the expected health check status code to be 404. So what we are assuming here is, if the nginx is inspecting url and return 404 NOT FOUND,the Nginx is working. But this method wont be checking anything more than that.

Pros:

  • ALB is able to whether your instance is running
  • ALB can check whether nginx is running

Cons: The health check wont identify the cases for example php not working or mysql server is not reachable from the application etc

Upvotes: 0

user2570937
user2570937

Reputation: 852

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>

Upvotes: 2

JD D
JD D

Reputation: 8097

The ALB healthcheck is going to be accessing your healthcheck.php via the web interface and has no concept of where the files exist on the file system. This value needs to be the URI path after the hostname.

Configuring the healthcheck to be /var/www/html/generic/website.com/healthcheck.php is equivalent to telling AWS to check http://website.com//var/www/html/generic/website.com/healthcheck.php which is probably not your intention.

Assuming the actual path you want to check is more like http://website.com/healthcheck.php, update your healthcheck path to simply be /healthcheck.php and this should hopefully work for you.

Upvotes: 1

Related Questions