HAProxy - 将一个域的流量重定向到https,将其他域的流量重定向到仅http

时间:2016-02-01 04:06:49

标签: apache redirect ssl haproxy

我使用专用服务器在Centos&上使用4个域和3个子域。南国。最近计划使用HAProxy进行负载均衡。

我想要实现的是使用前端的HAProxy配置将一个特定域的所有流量重定向到https,因为我在HAProxy终止了该特定域的SSL。

这是我用过的东西

frontend www-https
    bind haproxy_www_public_IP:443 ssl crt /etc/ssl/private/example.com.pem
    reqadd X-Forwarded-Proto:\ https
    default_backend www-backend


backend www-backend
    redirect scheme https if !{ ssl_fc }
    server www-1 www_1_private_IP:80 check
    server www-2 www_2_private_IP:80 check

我已经google搜索解决方案,但大多数可用的解决方案都告诉我们将所有流量重定向到https或http。

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您希望只有一个域(在下面的配置中为httpsonlydomain.com)才能通过https访问,并且对该域的所有http请求都会转发到https。对于其他域,他们可以通过http或https工作,无需转发。最后,我假设所有四个域(包括httpsonlydomain.com)都将使用www-backend后端。

如果是这种情况那么这应该可以解决问题:

frontend www-http
    bind haproxy_www_public_IP:80
    acl https_domain hdr(host) -i httpsonlydomain.com
    redirect scheme https if !{ ssl_fc } https_domain
    default_backend www-backend

frontend www-https
    bind haproxy_www_public_IP:443 ssl crt /etc/ssl/private/example.com.pem
    default_backend www-backend

backend www-backend
    server www-1 www_1_private_IP:80 check
    server www-2 www_2_private_IP:80 check

希望有所帮助。