LoginSignup
10

More than 5 years have passed since last update.

AWS ALBでnginxのヘルスチェックを設定する

Last updated at Posted at 2017-02-16

ヘルスチェックで普通はempty_gifを使って、1x1pxの透明gif返しますが、これでも多少の通信が発生してしまうので

  • 1x1pxの透明gifの場合
nginx.conf
    location /health {
        access_log off;
        empty_gif;
        break;
    }

HTTPステータス 204 no contentを使ってhttpのbodyを返さないようにする

  • HTTPステータス 204の場合
nginx.conf
    location /health {
        access_log off;
        return 204;
        break;
    }

但し、AWSのALBの設定でターゲットグループ>ヘルスチェック>成功コードを 『204』 に設定する必要があります。

これは、googleさんが、広告のトラッキングでjavascriptでimgタグを作ってトラッキングしている部分で、普通は1x1pxの透明gifを返しているところをHTTPステータス 204で返していたのを見て真似してみました。

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
10