apache - 具有 SSL 直通到具有多个后端的多个域的 HAProxy

标签 apache ssl nginx load-balancing haproxy

我需要为我们所有的应用程序设置一个负载均衡器。

目前我们所有的应用程序都是集群的(2 节点应用程序服务器,每个节点上还有 1 个 apache)并且我们没有 LB,所以我们只是将我们的 DNS 别名指向每个节点的第一个网络服务器,使第二个节点没用(如果节点 1 出现故障,必须手动执行 DNS 切换,而且我们没有负载均衡的 https 查询)。

每个应用程序都使用具有特定域和 SSL 证书的 SSL。我们不能接受解密 SSL 并将未加密的流量发送到后端,因为 LB 可能位于另一个国家等。因此我们需要使用直通。

在此之前,我只想知道这在 HAProxy 中是否真的可行?

我说的是大约 50 种不同的应用程序。我们的 LB 配置必须是 HA,所以我想我们将使用 keepalived 之类的东西和 HAProxy 本身的共享 VIP。

我想设置应该是这样的:

domain-a.com-'            '-> backend_dom_a -> 1.1.1.1 (app node1 dom a)
             |            |                    1.1.1.2 (app node2 dom a)
domain-b.com-'            '-> backend_dom_b -> 2.1.1.1 (app node1 dom b)
             |            |                    2.1.1.2 (app node2 dom b)
domain-c.com-'            '-> backend_dom_c -> 3.1.1.1 (app node1 dom c)
             |            |                    3.1.1.2 (app node2 dom c)
domain-N.com-'            '-> backend_dom_N -> 4.1.1.1 (app node1 dom N)
             |            |                    4.1.1.2 (app node2 dom N)
             +-> haproxy -+

感谢您的支持,致以最诚挚的问候

最佳答案

仅供引用,我正在使用这种非常有效的配置。

我已经替换了文件中的值以隐藏我们的域和主机名,并限制了 url/后端的数量,但我们现在有大约 50 个正在运行,负载均衡器将请求转发到许多 apache 服务器(并且每个 apache 将请求转发到后面的tomcat服务器)

如有任何问题,请随时联系我们

我们使用平衡源来确保 session 粘性

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
    daemon
    user                haproxy
    group               haproxy
    log                 /dev/log local6 notice
    log                 /dev/log local5 info
    maxconn             50000
    #chroot              /var/lib/haproxy
    pidfile             /var/run/haproxy.pid

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                 tcp
    option               tcplog
    log                  global
    option               dontlognull
    timeout connect      5000
    timeout client       50000
    timeout server       50000

#---------------------------------------------------------------------
# dedicated stats page
#---------------------------------------------------------------------
listen stats
    mode http
    bind :22222
    stats enable
    stats uri            /haproxy?stats
    stats realm          Haproxy\ Statistics
    stats auth           <mylogin>:<mypass>
    stats refresh        30s

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main_https_listen
    bind <ip address>:443
    mode                tcp
    option              tcplog
    log                 global
    tcp-request inspect-delay 5s
    tcp-request content accept if { req.ssl_hello_type 1 }

#---------------------------------------------------------------------
# Common HAProxy nodes configuration
#---------------------------------------------------------------------

# -------------------------------
# ACLs
# -------------------------------

acl acl_SIT_AT35073      req.ssl_sni -i <app_url1>.my.domain.net  # SIT_AT35073 is just an internal code we use, but you can use any alias
acl acl_SIT_AT34305      req.ssl_sni -i <app_url2>.my.domain.net
acl acl_SIT_AT28548      req.ssl_sni -i <app_urlN>.my.domain.net

# -------------------------------
# Conditions
# -------------------------------

use_backend backend_SIT_AT35073 if acl_SIT_AT35073   # same here
use_backend backend_SIT_AT34305 if acl_SIT_AT34305
use_backend backend_SIT_AT28548 if acl_SIT_AT28548

#---------------------------------------------------------------------
# Backends
#---------------------------------------------------------------------

# APP 1
backend backend_SIT_AT35073
    description APPNAME1
    mode tcp
    balance source
    option ssl-hello-chk
    server server_SIT_AT35073_1 <apache_server1>.my.domain.net:443 check
    server server_SIT_AT35073_2 <apache_server2>.my.domain.net:443 check

# APP 2
backend backend_SIT_AT34305
    description APPNAME2
    mode tcp
    balance source
    option ssl-hello-chk
    server server_SIT_AT34305_1 <apache_server3>.my.domain.net:443 check
    server server_SIT_AT34305_2 <apache_server4>.my.domain.net:443 check

# APP N
backend backend_SIT_AT28548
    description APPNAMEN
    mode tcp
    balance source
    option ssl-hello-chk
    server server_SIT_AT28548_1 <apache_server5>.my.domain.net:443 check
    server server_SIT_AT28548_2 <apache_server6>.my.domain.net:443 check

关于apache - 具有 SSL 直通到具有多个后端的多个域的 HAProxy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57513884/

相关文章:

nginx - `listen` 指令实际上在 nginx 中监听什么?

javascript - document.ready 不是在每次加载时都执行

java - HttpMethodBase 与 HttpRequestBase

java - 接收 SSLHandshakeException : handshake_failure despite my client ignoring all certs

php - WordPress 多站点的 SSL 404 错误

nginx - 如何在特定类型的 URL 上禁用 mod_pagespeed

apache - header 添加 Content-Disposition "attachment"导致内部服务器错误

linux - Apache 虚拟主机 - xxx.241.214.xxx :80 has no VirtualHosts

express - 使用 Google Cloud Run 进行 SSL 客户端身份验证

nginx - 如何在Nginx中重写或代理URL?