HAProxy重定向端口和掩码url



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

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保持连接。

如果您的应用程序所做的只是重定向到HTTPs,那么您可能应该直接在HAProxy中处理它。您可能还想了解您的应用程序是否支持X-Forwarded-Proto和X-Forwarded-Host。

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

http-response replace-header location https?://[^:/]*(:?[0-9]+/.*)  https://1234.example.com1 if { status 301:302 }

最新更新