Forwarding to a backend on a new URL path


#1

Hello!

I currently host a multi-server application using Apache HTTPD as a proxy, and am in the process of moving across to HAProxy. I’ve found a lot of the configuration far simpler and more intuitive than Apache, but am stumped on one particular requirement (enforced by the application).

Requests come in to HAProxy on a path matching /ApplicationA/rest/of/path, /ApplicationB/rest/of/path, /ApplicationC/rest/of/path, and based on the application letter (A, B, C) HAProxy is to pass the request onto one of a number of backend servers. The caveat is that the request needs to be forwarded to the backend on /Application/rest/of/path, rather than /Application/rest/of/path.

I’ve tried the something along these lines, but since the reqrep is applied before use backend, I end up with the request URL failing to match.

acl   url_application_a   path_beg   /ApplicationA
acl   url_application_b   path_beg   /ApplicationB
acl   url_application_a   path_beg   /ApplicationC

use_backend   APP_A   if   url_application_a
use_backend   APP_B   if   url_application_b
use_backend   APP_C   if   url_application_c

reqrep   ^([^\ :]*)\ /ApplicationA[/]?(.*)        \1\ /Application/\2      if url_application_a
reqrep   ^([^\ :]*)\ /ApplicationB[/]?(.*)        \1\ /Application/\2      if url_application_b
reqrep   ^([^\ :]*)\ /ApplicationC[/]?(.*)        \1\ /Application/\2      if url_application_c

Is what I’m looking for possible? And am I just missing something silly? Any help would be greatly appreciated!

Thanks in advance


#2

You should be able to just put reqrep in the backend section.


#3

Perfect, thanks for that. Still getting used to the config options that are applicable to different sections. Adjusting my backend def to include the reqrep did the job.

backend APP_A
        balance        roundrobin
        reqrep          ^([^\ :]*)\ /Application[A-Z][/]?(.*)        \1\ /Application/\2
        server          tomcat01app    x.x.x.x:8080/Application check
        server          tomcat02app    x.x.x.x:8081/Application  check

#4

If in doubt, consult the documentation, for every keyword there is a table with “May be used in sections”:

https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#4.2-reqrep