【问题标题】:HAProxy redirect port and mask urlHAProxy 重定向端口和掩码 url
【发布时间】:2020-03-19 11:31:52
【问题描述】:

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

https://abcd.example.com:8445/desktop/container/landing.jsp?locale=en_US https://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 会将您重定向到任何网络服务器,并强制您的客户端直接访问网络服务器,而不是通过 HAProxy。我需要通过 HAProxy 保持连接。

【问题讨论】:

    标签: haproxy


    【解决方案1】:

    如果您的应用程序所做的只是重定向到 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 }
    

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 2012-12-10
      • 1970-01-01
      • 2018-08-25
      • 1970-01-01
      • 2013-10-21
      • 2015-10-27
      • 2012-05-27
      • 1970-01-01
      相关资源
      最近更新 更多