Hi for reasons outside my control, I need to load balance two servers, that run a non-virtual host enabled app on IIS.

Normally in HAProxy I would load balance servers(apache, tomcat, etc) like this :

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 cookie node1
  server node1 cookie node1

Which will route to the node 1 and node 2 server and serve up the virtual host site. if I need to route to www.example.com/application/data

How would I be able to do it, with the above example, if at all even possible?


You can use a regex search and replace it with a string, like so --

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.

I may not have understood your question. Anyway, you can use the following options to match against a URL path:

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.

These are taken from haproxy documentation. There are also other options like path_end and path_reg. These can be used to create acls to choose the appropriate backend server.

  • Hi, no I don't want to match the incoming URL. Request comes in to HAProxy as example.com I want to route this to example.com/application/data in the backend. – daemonza Mar 20 '12 at 8:34
  • If so, you can use mod_rewrite (for apache). This depends on your web server. – Khaled Mar 20 '12 at 10:29
  • webserver is IIS and outside my control. – daemonza Mar 20 '12 at 11:14
  • Then you'll want to use the reprep options mentioned in Dave's answer. The exact syntax would depend on the URLs you've got and how you want to change them. – GregL Mar 21 '15 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.