【问题标题】:haproxy redirect both scheme and location togetherhaproxy 将方案和位置一起重定向
【发布时间】:2016-12-07 17:29:17
【问题描述】:

我需要先将特定的 http URL 重定向到其等效的 https,然后再重定向到完全不同的 https URL(不要问为什么我不能直接将原始 http 重定向到最终的 https URL,这就是客户想要,客户永远是对的!)。此外,我还需要能够将原始 https 重定向到不同的 https。

所以,我需要的是能够重定向http://foo.bar.com => https://foo.bar.com 然后https://foo.bar.com => https://another.foobar.com,以及重定向https://foo.bar.com => https://another.foobar.com

目前只重定向https://foo.bar.com => https://another.foobar.com 我正在使用这个:

acl is_new_portal hdr(host) -i foo.bar.com
redirect location https://another.foobar.com code 302 if is_new_portal 

在端口 443 上进行初始绑定,我知道将 http 重定向到我会使用的 https:

redirect scheme https code 302 if !{ ssl_fc }

(使用代码 302 而不是 301,因为最终 another.foobar.com 将被删除,所以我不希望重定向永久缓存在客户端的浏览器中)

但我需要能够同时进行这两种重定位,我不确定您如何将两者结合起来?

【问题讨论】:

    标签: redirect haproxy


    【解决方案1】:

    我不确定您的问题是与绑定有关还是与 ACL 有关。您已经有了问题的所有答案。您可以将它们包装在一个简单的前端:

    frontend main
      bind :80
      bind :443 ssl crt yourCertFile
    
      acl is_new_portal hdr(host) -i foo.bar.com
      redirect scheme https code 302 if !{ ssl_fc } is_new_portal
      redirect location https://another.foobar.com code 302 if { ssl_fc } is_new_portal
    
      http-response set-header Strict-Transport-Security max-age=31536000;\ includeSubDomains;\ preload; if { ssl_fc }
    

    if 之后的 ACL 之间的空格被解释为 AND。所以你会得到类似的东西:

    • 如果主机是 foo.bar.com 并且不使用 ssl,则重定向到 https
    • 如果主机是 foo.bar.com 并且使用 ssl,则重定向到 https://another.foobar.com

    【讨论】:

    • 好的,我不确定是否会执行两个重定向,谢谢您的建议。我还需要在Strict-Transport-Security:"max-age=31536000" 设置中工作,但我猜我可以将它添加到同一个前端。
    • @HelenH 是的,我刚刚将它添加到我的答案中。我不确定在您的情况下是否需要“if { ssl_fc }”
    猜你喜欢
    • 2017-07-30
    • 2014-12-08
    • 1970-01-01
    • 2012-12-10
    • 2016-04-26
    • 2020-09-05
    • 1970-01-01
    • 2018-08-25
    • 1970-01-01
    相关资源
    最近更新 更多