HAProxy: Backend with subdirectory / subpath / subfolder?

tung picture tung · Mar 6, 2014 · Viewed 22.1k times · Source

I am trying to achieve this:

http://front-end       --> http://back-end/app-1
http://front-end/app-2 --> http://back-end/app-2-another-path

So that requests will be handled this way:

http://front-end/do-this       --> http://back-end/app-1/do-this
http://front-end/app-2/do-that --> http://back-end/app-2-another-path/do-that

How can I do this? Thank you.

Answer

Gooner picture Gooner · Mar 7, 2014

You can achieve this "http://front-end/app-2/do-that --> http://back-end/app-2-another-path/do-that" with the following configuration:

frontend http   
   #match url ending with /xxxxx/do-that
   acl do-that path_end -i /app-2/do-that

   use_backend server1 if do-that

backend server1
   reqirep ^([^\ :]*)\ /app-2/(.*)     \1\ /app-2-another-path/\2
   server server 168.192.X.X

Here is more information on reqirep.