nam3t
nam3t

Reputation: 9

Why my AWS Lightsail instance got "Health Check: Failed" when attach to a load balancer?

I created an AWS Lightsail instance and a Load Balancer also in AWS Lightsail. When I attached my instance to the load balancer, I got this status: Health Check: Failed. I don't know why? I go to my WordPress and everything works fine.

Updated: As I know, the LB only check my instance health on port 80, which is HTTP protocol. I have checked it and it always return HTTP/1.1 301 Moved Permanently. I have already add these in httpd-prefix.conf:

SetEnvIf x-forwarded-proto https HTTPS=on

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule . https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]

And these in wp-config.php:

if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
    $_SERVER['HTTPS']='on';

And these in bitnami.conf:

RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} !^localhost
  RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
  RewriteCond %{REQUEST_URI} !^/\.well-known
  RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]

And restart my apache but it still not works.

Upvotes: 0

Views: 3404

Answers (2)

Hailey Yoon
Hailey Yoon

Reputation: 557

I had the same issue with AWS lightsail instances using lightsail CDN. This is how I fixed the health failure problem:

  1. Click your lightsail instance

  2. Connect using SSH

  3. Navigate to /opt/bitnami/apps/wordpress/htdocs

  4. Create an empty HTML file by running the following command:

    touch health.html

  5. Reboot your instance

Upvotes: 0

nam3t
nam3t

Reputation: 9

So I found a work around solution on topic: https://community.bitnami.com/t/lightsail-load-balancer-failed/81546/13

Following that, I need to create a file health.txt customize my health check path to this file: http://{MY_IP_INSTANCE}/health.txt.

And add these to my bitnami.conf:

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{REQUEST_URI} !health.txt
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

Then restart my apache server.

Upvotes: 1

Related Questions