2

我正在使用 HaProxy 来平衡传入请求并进行基于子域的重定向。现在我想使用查询参数强制所有传入请求使用 HTTPS。

例如:-

http://foo.test.com/test_page?person_name= "Bla"

应该被重定向到:-

https://foo.test.com/test_page?person_name= "Bla"

我知道我可以使用 Apache 进行这种重定向:-

   RewriteEngine On
   # This will enable the Rewrite capabilities
   RewriteCond %{HTTPS} !=on
   # This checks to make sure the connection is not already HTTPS
   #RewriteRule ^/?(.*) HTTPS_REDIRECTION_LOGIC{SERVER_NAME}/$1 [R,L]

或者我可以使用监听端口 80 的 apache 进行这种重定向,并使重定向的 HA-Proxy 监听 prt 443 上的重定向请求,两者都在同一个盒子上运行?我尝试了这种方法,但每当 Apache 启动时,它都会与端口 80 和 443 绑定。

4

2 回答 2

0

您必须使用 haproxy 版本 1.5.x(截至 2014 年 6 月,它已被宣布为稳定版)。haproxy.cfg 中的一个简单代码片段应该会为您整理好:

frontend http-in
        bind *:80
        redirect scheme https code 301 if !{ ssl_fc }

frontend https-in
        bind *:443
        <other configuration>

干杯:)

于 2014-09-17T13:40:13.923 回答
-1

放入您的虚拟主机:

UseCanonicalName on
UseCanonicalPhysicalPort On

并使用 SERVER_PORT 代替 HTTPS 示例:

RewriteEngine On
   # This will enable the Rewrite capabilities
   RewriteCond %{SERVER_PORT} !=443
   # This checks to make sure the connection is not already HTTPS
   #RewriteRule ^/?(.*) HTTPS_REDIRECTION_LOGIC{SERVER_NAME}/$1 [R,L]

或者

您可以使用域重定向

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www.)?example.com$
    RewriteRule ^(.*)$ https://example.com/$ [R=302,L]
于 2013-12-23T15:08:28.210 回答