Why is my Lightsail load balancer failing the health check even though the website is running correctly?
I'm using an Amazon Lightsail load balancer for my Amazon Lightsail instance with a Bitnami stack. Why is the load balancer health check failing even though the website is running correctly? How can I prevent the load balancer health check from failing?
"I'm using an Amazon Lightsail load balancer for my Amazon Lightsail instance with a Bitnami stack. Why is the load balancer health check failing even though the website is running correctly? How can I prevent the load balancer health check from failing?Short descriptionLightsail load balancer performs the health check by checking the response of the URL http://ipaddress:80/healthcheckpath. The health check passes if the response status code is 200 OK. This response check isn't customizable in 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 leads to health check failure.The same issue can occur on WordPress Multisite instances because these instances redirect the URL http://ipaddress:80/healthcheckpath to http://ipaddress.nip.io/healthcheckpath by default.ResolutionNote: The file paths in the following resolution steps might change depending on whether the Bitnami stack uses native Linux system packages (Approach A), or if it's 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 used to resolve this issue differ depending on the following:Redirection is set up using WordPress application plugins, such as Really Simple SSL.Redirection is set up using web server redirect rules.You're using a WordPress Multisite stack instance.Redirection is set up using WordPress application pluginsCreate an HTML file in the document root of your website. Then modify the load balancer health check configuration to add that file as the health check file. You must use this method because application level redirections don't normally affect HTML files that aren't originally part of your application.1.    Connect to your Lightsail instance.2.    Navigate to the Document root location of your website where you have stored your website files.In Bitnami stack under Approach A, the document root location is /opt/bitnami/APPNAME/ (for example, /opt/bitnami/wordpress).In Bitnami stack under Approach B, the document root location is /opt/bitnami/apps/APPNAME/htdocs (or example, /opt/bitnami/apps/wordpress/htdocs).In LAMP Bitnami stack, the document root location is /opt/bitnami/apache2/htdocs.3.    Create an empty HTML file either by uploading it or by running the following command:touch health.html4.    Go to the Lightsail home page, and then choose Networking.5.    Choose your load balancer.6.    On the Target instances tab, choose Customize health checking.7.    Type the path health.html and then choose Save.8.    Make sure that http://ipaddress:80/health.html returns the 200OK response using an HTTP Header Checker.9.    Wait for a few minutes, and then verify that the health check passes.Redirection is set up using web server redirect rulesAdd an exception rule for the health check file in the webserver redirect rules so that only the original website files redirect, but not the health check file.1.    Follow the steps 1 through 7 in the Redirection is set up using WordPress application plugins section.2.    Open the web server file where you added HTTPS redirection rules and then add the following line just before the line that starts with RewriteRule:RewriteCond expr "! %{REQUEST_URI} -strmatch '*health.html’ "The following are example redirect rules:RewriteEngine OnRewriteCond %{HTTPS} offRewriteCond expr "! %{REQUEST_URI} -strmatch '*health.html’ "RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}Make the preceding change to the rules in the following locations:Bitnami stack under Approach A: /opt/bitnami/apache2/conf/bitnami/bitnami.conf and also any file ending with the prefix -vhost.conf in the /opt/bitnami/apache2/conf/vhosts/ directory.Bitnami stack under Approach B: /opt/bitnami/apache2/conf/bitnami/bitnami.conf.3.    Restart the web service.sudo /opt/bitnami/ctlscript.sh restart4.    Make sure that http://ipaddress:80/health.html returns the 200OK  response using this HTTP Header Checker.5.    Wait for a few minutes, and then verify that the health check passes.You're using a WordPress Multisite stack instanceWordPress Multisite redirects the URL http://ipaddress:80/healthcheckpath to http://ipaddress.nip.io/healthcheckpath by default. To fix this issue, do the following:1.    Follow the steps 1 through 7 in the Redirection is set up using WordPress application plugins section.2.    Open the file /opt/bitnami/apache2/conf/vhosts/wordpress-vhost.conf and add the following line under the section # 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 redirectionRewriteEngine OnRewriteCond %{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 redirection3.    Restart the web service.sudo /opt/bitnami/ctlscript.sh restart4.    Make sure that http://ipaddress:80/health.html returns the 200OK response using this HTTP Header Checker.5.    Wait for a few minutes, and then verify that the health check passes.Follow"