LoginSignup
15
11

More than 3 years have passed since last update.

yum install httpdだけだとAWS ALBでHealth check failed with these codes: [403]

Last updated at Posted at 2020-08-13

表題だけで初心者がやらかすアレと言われそうなアレですが、やらかしたのでメモ。

  1. EC2インスタンス起動時にユーザーデータで yum install httpd -y
  2. 起動したインスタンスのIPアドレスにhttp接続してApacheのテストページが表示されることを確認
  3. Application Load Balanverを作成し、ターゲットグループを作り、このEC2インスタンスを追加
  4. 少し待ってターゲットのステータスを見ると unhealthy

原因は単純で、Status Detailに Health check failed with these codes: [403] とある通り、Apacheが403 Forbiddenエラーを返してるから。

image.png

Apacheのテストページが表示されている状態は、そもそもこの403: Forbeddenエラー状態で、実際に /var/log/httpd/access_log には「ELBのヘルスチェックが GET / してきたので403返しておきました」というようなログが残っている。

"GET / HTTP/1.1" 403 3630 "-" "ELB-HealthChecker/2.0"

また /var/log/httpd/error_logには次のようなエラーが記録されている。

[autoindex:error] [略] [略] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.html) found, and server-generated directory index forbidden by Options directive

対処はヘルスチェックを成功させたいだけなら /var/www/html/index.html を作るのが無難で安全だと思われる。ユーザーデータに例えば以下のような1行を加える。

echo "<html><head><title>Test Page</title></head><body>Wellcome to `uname -n`.</body></html>" > /var/www/html/index.html
15
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
11