首页 > 解决方案 > 如何在use_backend(Haproxy)中使用多条件?

问题描述

我正在使用 Haproxy 以不同的域设置分隔 http 和 https,但使用 http 的域限制效果不佳。我的设置如下。任何的想法?

frontend ha_8080
  mode tcp
  bind *:8080
  tcp-request content accept if { req_ssl_hello_type 1 }
  tcp-request inspect-delay 100ms
  tcp-request content accept if HTTP
  acl is_using_ssl req.ssl_hello_type gt 0

  acl is_abc hdr_dom(host) -i abc.com
  use_backend http_server if !is_using_ssl is_abc  #it works and only works on abc.com,
  use_backend local_server1 if is_using_ssl is_abc #https will not working
  use_backend local_server1 if is_using_ssl        #it works, but I need it work only on abc.com

标签: sslhaproxy

解决方案


hdr_dom(host) 不适用于 https(ssl)。

我应该改用 req_ssl_sni。

我的最终设置如下。

frontend ha_8080
  mode tcp
  bind *:8080
  tcp-request content accept if { req_ssl_hello_type 1 }
  tcp-request inspect-delay 100ms
  tcp-request content accept if HTTP
  acl is_abc hdr_dom(host) -i abc.com
  acl is_abc_ssl req_ssl_sni -i abc.com
  use_backend http_server if is_abc 
  use_backend local_server1 if is_abc_ssl 


推荐阅读