LoginSignup
3
3

More than 5 years have passed since last update.

HAProxy で VirtualHost が動かない

Posted at

HAProxy で httpd へのアクセスをプロクシしていたら名前ベースの VirtualHost が動かない。
デフォルトの VirtualHost が表示されてしまう。

解決方法

HAProxy のヘルスチェックが以下のようになっているなら

option httpchk HEAD / HTTP/1.0

以下で直った。 ( example.com は VirtualHost 名 )

option httpchk HEAD / HTTP/1.1\r\nHost:\ example.com

原因

ヘルスチェックの HEAD リクエストに Host ヘッダが無いため、
httpd は名前ベースのヴァーチャルホストを選べない。
選べないのでデフォルトのヴァーチャルホストが選択されるが、そちらのホストは動いていなかった。

今回は偶然デフォルトのヴァーチャルホストがエラーのステータスを返していたため判明したが、もし 200 などを返していた場合は、何の問題もないように見えただろう。

そして、目的のホストが落ちているのに HAProxy 上ではアクティブなままなのでたいへん困ったかもしれない。

対策

HAProxy の httpchk のオプションで、リクエストに Host ヘッダを追加した。
Hostヘッダが必須なのは HTTP/1.1 なので 一応 1.1 にした。

option httpchk [<method>] [<uri>] [<version>]

参考

Checking a HTTP service

It is possible to send HTTP headers after the string by concatenating them using rn and backslashes spaces. This is useful to send Host headers when probing a virtual host

補足

apache がヴァーチャルホストについて、どのように把握しているかは httpd -S で表示される。

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