使用 HA 代理进行反向代理

时间:2021-04-03 13:46:14

标签: ssl subdomain reverse-proxy haproxy

我主要尝试使用 HA 代理作为负载平衡和健康检查目的的反向代理。

因此,我必须使用多个子域和/或子路径来处理不同的域。

  1. https://sub1.example1.com
  2. https://subsub.sub1.example1.com
  3. https://sub2.example2.com
  4. https://example3.com/path1

不幸的是,我没有找到机会为每个域定义一个前端来绑定 SSL-cert-file。 此外,我不太确定 HAProxy 是否提供了 ProxyPass 之类的东西来处理“路径”-Stuff。

谁能给我举个例子,如何用 HAProxy 解决这个问题?

谢谢

1 个答案:

答案 0 :(得分:1)

您可以拥有一个处理所有子域的前端,并使用 ACL's 路由到不同的后端。您可以在 bind 行上定义您的 certificates,并且可以指定多个。我不太确定您所说的“处理“路径”-东西的 ProxyPass 是什么意思,但如果您提供更多详细信息,我可以提供帮助。 HAProxy 非常灵活。

<块引用>

提供诸如 ProxyPass 之类的东西来处理“路径”-Stuff。

您可能如何处理多个子域的示例:

defaults
    mode http

frontend fe_main
    bind :80
    # define all certificates
    bind :443 ssl crt /etc/haproxy/ssl/sub1.example.com.pem crt /etc/haproxy/ssl/sub2.example.com.pem crt /etc/haproxy/ssl/example3.com.pem

    use_backend be_sub1 if { req.hdr(host) sub1.example.com }
    use_backend be_sub2 if { req.hdr(host) sub2.example.com }
    default_backend be_catchall

backend be_sub1
    server app1 192.168.1.10:80 check

backend be_sub2
    server app1 10.2.0.4:443 check ssl verify none

backend be_catchall
    server catchall1 10.3.2.5:80 check