具有 SSL 直通到具有多个后端的多个域的 HAProxy
HAProxy with SSL passthrough to multiple domains with multiple backends
我需要为我们所有的应用程序设置一个负载平衡器。
目前我们所有的应用程序都是集群的(2 节点应用程序服务器,每个节点上还有 1 个 apache)并且我们没有 LB,所以我们只是将我们的 DNS 别名指向每个节点的第一个网络服务器,使第二个节点无用(在节点 1 出现故障的情况下必须手动进行 DNS 切换,并且我们没有负载平衡 https 查询)。
每个应用程序都使用具有特定域和 SSL 证书的 SSL。我们不能接受解密 SSL 并将未加密的流量发送到后端,因为 LB 可能位于另一个国家等。所以我们需要使用 passthrough。
首先,我只想知道这在 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 -+
感谢您的支持,致以最诚挚的问候
我想你有两个选择:
在haproxy前端和后端使用TCP模式将流量传递到后端。这样做的好处是您的后端 SSL 证书可以通过。尽管您失去了在站点中使用一个 SSL 终止的可能性。所以我给你介绍
拥有一个(通常的)SSL 证书,作为您站点的终止,并在您的后端和 haproxy 实例之间启用 SSL。这为您提供了一个优势,即您仍然只有一个入口点,但具有唯一证书的不同后端。
第二个选项可能如下所示:
frontend f_foo
bind :443 ssl crt /path/to/bundle
mode http
log global
use_backend b2_foo
backend be_foo
mode http
timeout connect 5s
server FOO address:port ssl check crt /path/to/client/bundle force-tlsv10 verify none
缺点是每个后端服务器都需要一个客户端证书,但这应该很容易实现自动化。
更多关于多域配置的更新答案我使用下面的路由不同的域。
在前端是绑定端口并添加多个证书的地方,afaik 必须在同一行上。
frontend https_in
bind *:443 ssl crt /link/to/cert+key-file.pem crt /link/to/cert+key-file.pem
acl 主机是您指定域名以及根据该域名使用哪个后端的地方。
acl host_example.com hdr(host) -i example.com
use_backend BACKEND_NAME if host_example.com
您指定域所在服务器的后端 运行。
backend BACKEND_NAME
mode http
option httpclose
option forwardfor
cookie JSESSIONID prefix
server server-name server-ip:443 check ssl verify none
仅供参考,我正在使用这种非常有用的配置。
我已经替换了文件中的值以隐藏我们的域和主机名,并限制了 urls/backends 的数量,但我们现在有大约 50 运行 负载平衡器将请求转发给许多 apache服务器(并且每个 Apache 将请求转发到后面的 tomcat 个服务器)
如有任何问题,请随时联系
我们使用平衡源来确保会话粘性
#---------------------------------------------------------------------
# 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
我需要为我们所有的应用程序设置一个负载平衡器。
目前我们所有的应用程序都是集群的(2 节点应用程序服务器,每个节点上还有 1 个 apache)并且我们没有 LB,所以我们只是将我们的 DNS 别名指向每个节点的第一个网络服务器,使第二个节点无用(在节点 1 出现故障的情况下必须手动进行 DNS 切换,并且我们没有负载平衡 https 查询)。
每个应用程序都使用具有特定域和 SSL 证书的 SSL。我们不能接受解密 SSL 并将未加密的流量发送到后端,因为 LB 可能位于另一个国家等。所以我们需要使用 passthrough。
首先,我只想知道这在 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 -+
感谢您的支持,致以最诚挚的问候
我想你有两个选择:
在haproxy前端和后端使用TCP模式将流量传递到后端。这样做的好处是您的后端 SSL 证书可以通过。尽管您失去了在站点中使用一个 SSL 终止的可能性。所以我给你介绍
拥有一个(通常的)SSL 证书,作为您站点的终止,并在您的后端和 haproxy 实例之间启用 SSL。这为您提供了一个优势,即您仍然只有一个入口点,但具有唯一证书的不同后端。
第二个选项可能如下所示:
frontend f_foo
bind :443 ssl crt /path/to/bundle
mode http
log global
use_backend b2_foo
backend be_foo
mode http
timeout connect 5s
server FOO address:port ssl check crt /path/to/client/bundle force-tlsv10 verify none
缺点是每个后端服务器都需要一个客户端证书,但这应该很容易实现自动化。
更多关于多域配置的更新答案我使用下面的路由不同的域。 在前端是绑定端口并添加多个证书的地方,afaik 必须在同一行上。
frontend https_in
bind *:443 ssl crt /link/to/cert+key-file.pem crt /link/to/cert+key-file.pem
acl 主机是您指定域名以及根据该域名使用哪个后端的地方。
acl host_example.com hdr(host) -i example.com
use_backend BACKEND_NAME if host_example.com
您指定域所在服务器的后端 运行。
backend BACKEND_NAME
mode http
option httpclose
option forwardfor
cookie JSESSIONID prefix
server server-name server-ip:443 check ssl verify none
仅供参考,我正在使用这种非常有用的配置。
我已经替换了文件中的值以隐藏我们的域和主机名,并限制了 urls/backends 的数量,但我们现在有大约 50 运行 负载平衡器将请求转发给许多 apache服务器(并且每个 Apache 将请求转发到后面的 tomcat 个服务器)
如有任何问题,请随时联系
我们使用平衡源来确保会话粘性
#---------------------------------------------------------------------
# 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