HAProxy は 1 つのサーバー内で複数のサブドメインをサポートしますか?

HAProxy は 1 つのサーバー内で複数のサブドメインをサポートしますか?

現在、複数のサブドメインを持つ Apache 2 サーバーの構造を持っています。以下の例のとおりです。

<VirtualHost *:80>
 ServerName www.example.com
 ServerAlias example.com
 DocumentRoot /var/www/main
</VirtualHost>

<VirtualHost *:80>
 ServerName subdomain-1.example.com
 ServerAlias subdomain-1.example.com
 DocumentRoot /var/www/sbd1
</VirtualHost>

<VirtualHost *:80>
 ServerName subdomain-2.example.com
 ServerAlias subdomain-2.example.com
 DocumentRoot /var/www/sbd2
</VirtualHost>

このサーバーを複製し、HAProxy を使用して新しいサーバーを作成し、負荷分散を実行することを検討しています。

HAProxy は、すべてのリクエストを同じ IP を持つ子サーバーに向けることをサポートしていますか? それとも、サブドメインごとに特定の IP を持つ特定のサーバーが必要になりますか?

答え1

各サブドメインのバックエンドを構成する必要があります。または、ほとんどのリクエストが特定のサーバーに到達する場合は、デフォルトのバックエンドを使用する必要があります。複数のバックエンドを構成する場合、それらが同じ Web サーバーを指すことを妨げるものは何もありません。

答え2

残念ながら、これはあなたが本当に望んでいる/必要としているものではありません。HAproxy はプロキシとして機能する優れたツールですが、サンプルとして提供しているユースケースはプロキシではなく、通常の http サーバーに関連しています。Apache を置き換えたい場合は、たとえば nginx がオプションとして考えられます。


プロキシ- リクエストのチェックやコンテンツ提供のためのサブリクエストを行うアプリケーション

http サーバー- コンテンツを提供するアプリケーション


同じノード上でも、HAproxy をフロントエンドとして、nginx をバックエンドとして使用することも可能です。HAproxy の構成は次のようになります (要求どおり https なし)。

frontend http_front
    maxconn 1000
    mode http
    option http-server-close
    option forwardfor
    bind *:80

    acl top_domain hdr(host) -m str www.example.com
    acl top_domain hdr(host) -m str example.com

    acl subdom1 hdr(host) -m str www.subdomain-1.example.com
    acl subdom1 hdr(host) -m str subdomain-1.example.com

    acl subdom2 hdr(host) -m str www.subdomain-2.example.com
    acl subdom2 hdr(host) -m str subdomain-2.example.com


    http-request set-header X-Forwarded-Port %[dst_port]
    http-request add-header X-Forwarded-Proto http if !{ ssl_fc }

    use_backend local if subdom1
#   ...
    default_backend local

backend local
    fullconn 1000
    mode http
    timeout http-keep-alive 3000
    server local1 127.0.0.1:8080 check maxconn 100

異なるサーバー上で終了するバックエンドがさらに存在する可能性があります...私は単に例に従っています ;-)。

関連情報