HAProxy重定向端口和掩码URL

问题描述 投票:0回答:1

我有几个可通过以下URL直接访问的Web服务器:

https://abcd.example.com:8445/desktop/container/landing.jsp?locale=en_UShttps://wxyz.example.com:8445/desktop/container/landing.jsp?locale=en_US

我需要使用HAProxy在两者之间进行负载平衡,并在访问前端时使用以下URL:

http://1234.example.com/desktop/container/landing.jsp?locale=en_US要么https://1234.example.com:8445/desktop/container/landing.jsp?locale=en_US

因此,除了以上两个条件之外的其他要求:

  1. 如果初始流量是端口80,则转换为端口8445
  2. 屏蔽URL,以便在浏览器上重定向到https并将端口重定向到8445时,主机保持完整,例如:https://1234.example.com:8445/desktop/container/landing.jsp?locale=en_US

到目前为止是我的配置:

frontend WebApp_frontend
    mode http
    bind 10.4.34.11:80
    acl is80 dst_port 80
    http-request set-uri https://%[req.hdr(Host)]:8445%[path]?%[query] if is80
    default_backend WebApp-backend

backend WebApp_backend
    description WebApp
    balance roundrobin
    mode http
    server webserver1 10.2.89.222:8445 check inter 5s fall 3 rise 5 downinter 1m ssl verify none
    server webserver2 10.4.89.223:8445 check inter 5s fall 3 rise 5 downinter 1m ssl verify none

我现在面临的问题是,当您访问前端时,HAProxy会将您重定向到任何Web服务器,并迫使您的客户端直接访问Web服务器,而不是通过HAProxy。我需要通过HAProxy保持连接。

haproxy
1个回答
0
投票

如果您的应用程序正在做的所有事情都是重定向到HTTP,那么您可能应该直接在HAProxy中处理它。您可能还想研究您的应用程序是否支持X-Forwarded-Proto和X-Forwarded-Host。

[另一个选项是,您可以让HAProxy重写从后端应用程序到您选择的主机名的重定向。使用HAProxy 2.1,您将执行以下操作:

http-response replace-header location https?://[^:/]*(:?[0-9]+/.*)  https://1234.example.com\1 if { status 301:302 }
© www.soinside.com 2019 - 2024. All rights reserved.