HAproxy 到网络主机子目录?

HAproxy 到网络主机子目录?

你好,由于我无法控制的原因,我需要对两台服务器进行负载平衡,这两台服务器在 IIS 上运行未启用虚拟主机的应用程序。

通常在 HAProxy 中我会像这样对服务器(apache、tomcat 等)进行负载平衡:

acl is_www_example_com hdr_end(host) -i www.example.com
use_backend www_example_com if is_www_example_com

backend www_example_com
  balance roundrobin
  cookie SERVERID insert nocache indirect
  option httpchk HEAD / HTTP/1.0
  option httpclose
  option forwardfor
  server node1 192.168.1.1:80 cookie node1
  server node1 192.168.1.2:80 cookie node1

它将路由到节点 1 和节点 2 服务器并提供虚拟主机站点。如果我需要路由到 www.example.com/application/data

如果可能的话,我该如何利用上述示例来做到这一点?

答案1

您可以使用正则表达式搜索并将其替换为字符串,如下所示——

reqrep  <search> <string>
reqirep <search> <string>   (ignore case)
  Replace a regular expression with a string in an HTTP request line
  May be used in sections :   defaults | frontend | listen | backend
                                 no    |    yes   |   yes  |   yes
  Arguments :
    <search>  is the regular expression applied to HTTP headers and to the
              request line. This is an extended regular expression. Parenthesis
              grouping is supported and no preliminary backslash is required.
              Any space or known delimiter must be escaped using a backslash
              ('\'). The pattern applies to a full line at a time. The "reqrep"
              keyword strictly matches case while "reqirep" ignores case.

    <string>  is the complete line to be added. Any space or known delimiter
              must be escaped using a backslash ('\'). References to matched
              pattern groups are possible using the common \N form, with N
              being a single digit between 0 and 9. Please refer to section
              6 about HTTP header manipulation for more information.

答案2

我可能没有理解你的问题。无论如何,你可以使用以下选项来匹配 URL 路径:

path <string>
  Returns true when the path part of the request, which starts at the first
  slash and ends before the question mark, equals one of the strings. It may be
  used to match known files, such as /favicon.ico.

path_beg <string>
  Returns true when the path begins with one of the strings. This can be used
  to send certain directory names to alternative backends.

这些取自haproxy 文档。还有其他选项,如path_endpath_reg。这些可用于acls选择适当的后端服务器。

相关内容