haproxy 同时重定向方案和位置
haproxy redirect both scheme and location together
我需要先将特定的 http URL 重定向到其等效的 https,然后再重定向到完全不同的 https URL(不要问我为什么不能只重定向原始 http直接到最后的 https URL,这就是客户想要的,客户永远是对的!)。此外,我还需要能够将原始 https 重定向到不同的 https。
所以,我需要的是重定向的能力 http://foo.bar.com => https://foo.bar.com and then https://foo.bar.com => https://another.foobar.com, as well as redirecting 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 将被删除,所以我不希望重定向永久缓存在客户端的浏览器中)
但我需要能够同时进行两次搬迁,我不确定您如何将两者结合起来?
我不确定您的问题是与绑定相关还是与 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 之间的 space 被解释为 AND。所以你会得到类似的东西:
- 如果主机是 foo.bar.com 并且不使用 ssl
,则重定向到 https
- 重定向到 https://another.foobar.com 如果主机是 foo.bar.com 并且使用 ssl
我需要先将特定的 http URL 重定向到其等效的 https,然后再重定向到完全不同的 https URL(不要问我为什么不能只重定向原始 http直接到最后的 https URL,这就是客户想要的,客户永远是对的!)。此外,我还需要能够将原始 https 重定向到不同的 https。
所以,我需要的是重定向的能力 http://foo.bar.com => https://foo.bar.com and then https://foo.bar.com => https://another.foobar.com, as well as redirecting 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 将被删除,所以我不希望重定向永久缓存在客户端的浏览器中)
但我需要能够同时进行两次搬迁,我不确定您如何将两者结合起来?
我不确定您的问题是与绑定相关还是与 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 之间的 space 被解释为 AND。所以你会得到类似的东西:
- 如果主机是 foo.bar.com 并且不使用 ssl ,则重定向到 https
- 重定向到 https://another.foobar.com 如果主机是 foo.bar.com 并且使用 ssl