如何使用2种不同的后端在TCP模式下为同一IP和端口配置Haproxy



我确实使用HTTP模式配置了HTTPS终止的HAPROXY:

frontend apache-https
   #mode tcp
    bind 192.143.56.150:443 ssl crt /etc/ssl/private/rabbit.pem 
    option http-server-close                # needed for forwardfor
    option forwardfor                       # forward IP Address of client
    reqadd X-Forwarded-Proto: https
    default_backend apache-http
    acl fx_static   hdr(host) -i static.rabbit.fx-com
    use_backend nginx-cluster       if fx_static

现在我确实想更改静态。域到http2。问题是,我需要切换到TCP模式才能做到这一点,与此同时,我将失去ACL HTTP模式功能。

如何在TCP模式下为相同的IP和端口配置Haproxy以使用2种不同的后端?

我想将此线与TCP模式一起使用,仅用于静态。

   use_backend nginx-cluster-http2 if { ssl_fc_alpn -i h2 }

下面的解决方案消除了http模式,因此注入了 forward 标题,支持通过send-proxy指令使用代理协议。后端服务器必须能够接受代理协议,并且Apache和Nginx都支持它。

主机匹配是使用SNI而不是Host标头执行的。

http/2静态域的请求将转发到http/2后端服务器,在示例在 127.0.0.1:8888上侦听示例,其中清晰的text http/2服务器必须在其中侦听。

>

所有其他请求都将转发到127.0.0.1:9999,其中清晰的text http/1.1服务器必须侦听。

frontend fe
  mode tcp
  bind *:443 ssl no-sslv3 crt /etc/ssl/domain.pem
  acl static_domain req.ssl_sni -i static.domain.com
  acl http2 ssl_fc_alpn -i h2
  use_backend be_static if static_domain http2
  default_backend be_non_static
backend be_static 
  mode tcp
  server 127.0.0.1:8888 send-proxy
backend be_non_static
  mode tcp
  server 127.0.0.1:9999 send-proxy

例如,由于您的应用程序依赖于它们,因此您可以使用以下解决方案:

frontend fe
  mode tcp
  bind *:443 ssl no-sslv3 crt /etc/ssl/domain.pem
  acl static_domain req.ssl_sni -i static.domain.com
  acl http2 ssl_fc_alpn -i h2
  use_backend be_static if static_domain http2
  default_backend be_non_static
backend be_static 
  mode tcp
  server 127.0.0.1:8888 send-proxy
backend be_non_static
  mode tcp
  server 127.0.0.1:7777 send-proxy
frontend fe_non_static
  mode http
  bind 127.0.0.1:7777 accept-proxy
  option forwardfor
  reqadd X-Forwarded-Proto: https
  default_backend be_other
backend be_other
  mode tcp
  server 127.0.0.1:9999

对于第二个解决方案,想法是http/2静态请求将像以前一样工作,而其他请求将首先将其定向到私人" local"," local",前端在端口7777上,在http模式下工作,可以注入向前标题。

从私有"本地",前端您可以像以前一样转到后端服务器 - 仅此一次,您不需要send-proxy指令。

几乎通过任何服务器给出了对代理协议的广泛支持,我建议不要使用 forward 标题,除非真正必要。

最新更新