首页 文章

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

提问于
浏览
0

我使用专用服务器在Centos和WHM上托管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

    如果我理解正确,您希望只有一个域(在下面的配置中为 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
    

    希望有所帮助 .

相关问题