LoginSignup
3
1

More than 5 years have passed since last update.

ELB を経由すると keepalive ヘッダーが勝手に付与される

Last updated at Posted at 2017-04-19

AWS Elastic Load Balance 配下にぶら下がっている EC2 インスタンスのベンチマークを、keepalive on/off それぞれの状態で取ろうとしたのですが、「どうしても keepalive を off にできない」という状況にハマりました。

後学のためにメモ。

nginx で keepalive を off にする方法

nginx.conf に以下のような設定を書きます。

/etc/nginx/nginx.conf
http{
  keepalive_timeout 0;
  # (何も書かない場合はデフォルト値の 75 になる)
}

設定後は nginx -s reload を忘れずに。

keepalive の有効/無効の確認

この状態で、以下のように ELB 経由でアクセスすると、あたかも keepalive が有効のように見えてしまいます。

$ curl -I http://foo.bar/

HTTP/1.1 200 OK
Server: nginx
Date: Wed, 19 Apr 2017 05:19:08 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 105370
Connection: keep-alive    # <- nginx の設定に関わらず必ず付与される
...

一方、プライベート側から nginx に直接アクセスすれば、ちゃんと keepalive は無効化されています。

$ curl -I http://10.2.8.97/

HTTP/1.1 200 OK
Server: nginx
Date: Wed, 19 Apr 2017 05:19:08 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 105370
Connection: close    # <- keepalive が無効になっている
...

まとめ

keepalive が無効化されていることを確認したければ、ELB を経由せずに直接 nginx を叩きましょう。

補足: ELB 側で keepalive off にできないか?

できない ようです。

Classic Load Balancer のアイドル接続のタイムアウトを設定する - Elastic Load Balancing

[Configure Connection Settings] ページに、[Idle timeout] の値を入力します。アイドルタイムアウトの範囲は 1~3,600 秒です。

(0 には指定できない)

3
1
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
3
1