Why is my Lightsail load balancer failing the health check even though the website is running correctly?

4 minute read
0

I'm using an Amazon Lightsail load balancer for my Lightsail instance with a Bitnami stack. The load balancer health check is failing even though the website is running correctly.

Short description

To perform a health check, the Lightsail load balancer checks the response of the URL http://ipaddress:80/healthcheckpath. If the status code is 200 OK, then the health check passes. You can't customize this response check in the Lightsail load balancer. If your instance enforces HTTPS redirection, then http://ipaddress:80/healthcheckpath returns the 301 or 302 response status code instead of 200 OK. This results in a health check failure.

The same issue can occur on WordPress Multisite instances because these instances redirect http://ipaddress:80/healthcheckpath to http://ipaddress.nip.io/healthcheckpath by default.

Resolution

Note: The file path depends on whether the Bitnami stack uses native Linux system packages (Approach A) or a self-contained installation (Approach B).

To identify your Bitnami installation type, run the following command:

test ! -f "/opt/bitnami/common/bin/openssl" && echo "Approach A: Using system packages." || echo "Approach B: Self-contained installation."

The steps that you use to resolve this issue depend on the following:

  • You used WordPress application plugins, such as Really Simple SSL, to set up redirection.
  • You used web server redirect rules to set up redirection.
  • You're using a WordPress Multisite stack instance.

You used WordPress application plugins to set up redirection

Create an HTML file in the document root of your website. Then, modify the load balancer health check configuration to add the HTML file as the health check file. Because application-level redirections affect only HTML files that are part of your original application, you must add the HMTL file as the health check file.

  1. Connect to your Lightsail instance.

  2. Navigate to the document root location of your website where you store your website files:
    In the Bitnami stack under Approach A, the document root location is /opt/bitnami/APPNAME/ (for example, /opt/bitnami/wordpress).
    In the Bitnami stack under Approach B, the document root location is /opt/bitnami/apps/APPNAME/htdocs (for example, /opt/bitnami/apps/wordpress/htdocs).
    In the LAMP Bitnami stack, the document root location is /opt/bitnami/apache2/htdocs.

  3. Either upload an empty HTML file, or run the following command to create the empty HTML file:

    touch health.html
  4. Open the Lightsail console.

  5. Choose Networking.

  6. Select your load balancer.

  7. On the Target instances tab, choose Customize health checking.

  8. Enter the path health.html, and then choose Save.

  9. Make sure that http://ipaddress:80/health.html returns the 200 OK response. Use the HTTP Header Checker on the KeyCDN website.

  10. Wait a few minutes, and then verify that the health check passes.

You used web server redirect rules to set up redirection

Add an exception rule in the web server redirect rules so that only the original website files redirect, but not the health check file.

  1. Complete steps 1-7 in the You used WordPress application plugins to set up redirection section.

  2. Open the web server file where you added HTTPS redirection rules, and then add the following line before the line that starts with RewriteRule:

    RewriteCond expr "! %{REQUEST_URI} -strmatch '*health.html’ "

    The following are example redirect rules:

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteCond expr "! %{REQUEST_URI} -strmatch '*health.html’ "
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}

    Add the preceding line to the rules in the following locations:
    The Bitnami stack under Approach A: /opt/bitnami/apache2/conf/bitnami/bitnami.conf and any file that ends with -vhost.conf in the /opt/bitnami/apache2/conf/vhosts/ directory.
    The Bitnami stack under Approach B: /opt/bitnami/apache2/conf/bitnami/bitnami.conf.

  3. Restart the web service:

    sudo /opt/bitnami/ctlscript.sh restart
  4. Make sure that http://ipaddress:80/health.html returns the 200 OK  response. Use this HTTP Header Checker on the KeyCDN website.

  5. Wait a few minutes, and then verify that the health check passes.

You're using a WordPress Multisite stack instance

To resolve this issue, complete the following steps:

  1. Complete steps 1-7 in the You used WordPress application plugins to set up redirection section.

  2. Open the /opt/bitnami/apache2/conf/vhosts/wordpress-vhost.conf file, and then add the following line under # BEGIN nip.io redirection:

    RewriteCond expr "! %{REQUEST_URI} -strmatch '*health.html' "

    The following is an example of rules with the line added:

    # BEGIN nip.io redirection
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})(:[0-9]{1,5})?$
    RewriteCond expr "! %{REQUEST_URI} -strmatch '*health.html'"
    RewriteRule ^/?(.*) %{REQUEST_SCHEME}://%1.nip.io%2/$1 [L,R=302,NE]
    # END nip.io redirection
  3. Restart the web service:

    sudo /opt/bitnami/ctlscript.sh restart
  4. Make sure that http://ipaddress:80/health.html returns the 200 OK response. Use this HTTP Header Checker on the KeyCDN website.

  5. Wait a few minutes, and then verify that the health check passes.

AWS OFFICIAL
AWS OFFICIALUpdated 2 months ago