Search code examples
amazon-web-servicesamazon-ec2elastic-load-balancer

How to create a target page at EC2 instance for Load balancer's health check


I set up load balancer for my EC2 instances.

All the security groups set up between load balancer and instances look fine.

The current problem is that instances status in load balancer are OutofService.

For that I think I don't have a target page for the Health Check on my instance.

What is a target page? In my instance, inside /var/www/html folder I have index.php only directing to one html page (home page) inside another folder.

So for health check, assumed that I need to have index.html (target page) inside /var/www/html.

My questions are:

  • Do I need to create target page index.html inside the /var/www/html folder?
  • What should be inside that index.html file?

Solution

  • The load balancer just requires that you have a page that "returns" an HTTP 200. So, as an example, you could have a page in /var/www/html named "heartbeat.php" that looks like:

    <html>
     <head>
      <title>ELB Heartbeat</title>
     </head>
     <body>
     <?php echo '<p>OK</p>'; ?> 
     </body>
    </html>
    

    What this is ultimately doing is giving the Elastic Load Balancer an HTTP 200 response and a tiny packet that indicates that everything is ok.

    Later, when you've gotten more usage your "heartbeat" page may want to do more - check a connection to a database and so on. That, of course, depends on your application. But for now a simple page like this will do.

    You will need to configure the Elastic Load Balancer with the URL of your heartbeat page. It will be something like http://www.yoursite.tld/heartbeat.php