Http

HAProxy - 基於 URI 轉發到不同的 Web 伺服器

  • October 24, 2016

我有一個具有以下配置的 HTTP 場:

listen webfarm 10.254.23.225:80
      mode http
      balance roundrobin
      cookie SERVERID insert
      option httpclose
      option forwardfor
      option httpchk HEAD /check.txt HTTP/1.0
      server webA 10.254.23.4:80 cookie A check
      server webB 10.248.23.128:80 cookie B check

我想添加一些選項,它將對特定 URI(即 /special)的所有請求轉發到第三個 Web 伺服器。我該怎麼做?

這是我寫的關於基於主機頭的負載平衡的部落格文章:

http://www.mattbeckman.com/2009/09/18/using-the-acl-in-haproxy-for-load-balancing-named-virtual-hosts/

如果您想匹配 URI 或目錄,我建議使用 path_beg 而不是該頁面上提供的範例中使用的 hdr_end。下面是一個範例,說明如何使用您的配置執行此操作:

frontend http-in
   bind 10.254.23.225:80
   acl has_special_uri path_beg /special
   use_backend special_server if has_special_uri
   default_backend webfarm

backend webfarm
   balance roundrobin
   cookie SERVERID insert
   option httpchk HEAD /check.txt HTTP/1.0
   option httpclose
   option forwardfor
   server webA 10.254.23.4:80 cookie webA check
   server webB 10.248.23.128:80 cookie webB check

backend special_server
   balance roundrobin
   cookie SERVERID insert
   option httpchk HEAD /check.txt HTTP/1.0
   option httpclose
   option forwardfor
   server webC 10.0.0.1:80 cookie webC check

希望有幫助!

引用自:https://serverfault.com/questions/127491