HaProxy は内部 URL にリダイレクトします

HaProxy は内部 URL にリダイレクトします

バックエンド サーバーが 2 台ある構成で、HTTP 上の内部 URL を使用して各サーバーに 301 をリダイレクトする必要があります。この構成ではレポート サーバーに SSL をインストールできないため、SSL を使用するのは困難です。また、レポートを表示するときにレポート ビューアーに内部的な問題があるため、仮想ドメインと共有 IP を使用してトラフィックをリダイレクトすることもできません。トラフィックをバックエンド サーバーにリダイレクトするだけで、できれば内部 URL を使用しますが、IP も問題ありません。

現時点では、特定のホストに対してそれを実行する方法はわかっていますが、現在のサーバーに対してそれを実行する方法はわかりません。

構成: バックエンドのアクティブ/パッシブ構成。

  1. HA-Proxy バージョン 2.0.29-0ubuntu1

  2. Ubuntu 20.04.5 LTS

  3. キープアライブ v2.0.19

    frontend raporty
         bind 192.168.0..108:80
         bind 192.168.0.108:443 ssl crt /etc/ssl/certs/haproxy.pem
         default_backend reportserver
         option forwardfor
    
    backend reportserver
         mode http
         balance roundrobin
         option httpchk uri /reports
         http-check  expect status 401
         http-response set-header X-Server %s
         http-request redirect  code 301  location http://sql02.domain.local%[capture.req.uri]
         server   sql01  192.168.0.11:80 check check fall 5
         server   sql02  192.168.0.111:80 check check fall 5
         http-response set-header X-Server %s
    

答え1

これは、ACL と srv_is_up パラメータを使用して管理されました。

frontend raporty
        bind 192.168.0.108:80
        bind 192.168.0.108:443 ssl crt  /etc/ssl/certs/haproxy.pem
        http-response set-header X-Server %s
        http-response set-header Host %s
        default_backend reportserver
        option forwardfor



backend reportserver
        mode http
        balance roundrobin
        option httpchk uri /reports
        http-check  expect status 401
        acl asql01 srv_is_up(reportserver/sql01)
        acl asql02 srv_is_up(reportserver/sql02)
        http-request set-header Host %s
        http-response set-header Host %s
        http-request redirect  code 301 location http://sql01.domain.local%[capture.req.uri]  if asql01
        http-request redirect  code 301 location http://sql02.domain.local%[capture.req.uri]  if asql02
        server   sql01  sql01.domain.local:80 check check fall 5
        server   sql02  sql02.domain.local:80 check check fall 5
        http-response set-header X-Server %s

関連情報