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

如果可能的话,我怎样才能做到这一点?

您可以使用正则expression式search,并用一个stringreplace它,

 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. 

我可能不了解你的问题。 无论如何,您可以使用以下选项来匹配URLpath:

 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 。 这些可以用来创buildacls来select适当的后端服务器。