I'm setting up HAproxy as a reverse proxy on my NAS, because I would like to use easy to remember subdomains instead of referring to the apps on my NAS with their port numbers.

I managed to get it working, except for few backend 'servers', those who don't just refer to a port, but to a certain path.

For instance I would like to have nav.mydomain.com point to backend

My first thought was to configure the backend like this

frontend http-in
   bind *:80
   mode http

   acl nav hdr_beg(host) -i nav
   use_backend nav_node if nav

backend nav_node
   mode http
   server nav-server check

But apparently, it is not as simple as that... So did some more hours of research on how to handle this and found topics on reqrep which is rather chinese to me... That's why I decided to register here to get some help to figure this out.

For now I'm just trying to get it working, in a later phase I will (try to) add SSL.


These reqreps are usually too cumbersome to clearly understand. You can use set-path

http-request set-path /modules/navigator/www%[path]

in either frontend or backend. Then you get /modules/navigator/www/login.php if /login.php is requested. You can additionally rewrite an / request to /login.php if you wish.


Have been experimenting with reqrep until I found a working command. I don't really understand what all those characters do, probably there are some too many, but it works!

reqrep ^([^\ :]*)\ /(.*)     \1\ /modules/navigator/www/\2 
server nav-server check
  • ^ is the beginning of the string. The ([^\ :]*) part matches the first word of the request, typically GET or POST (it matches everything that isn't a space or a colon, and that 0 or more times). Then comes the URL and the rest of the request; the URL starts with the slash. Everything inside brackets () is "captured", and can be inserted into the replacement with \1 for the first capture, \2 for the second etc. The `\` is also used to escape or protect the following space so that that space doesn't separate the different parameters. – wurtel Jan 30 '18 at 14:11

Firtsly,I don't think you want a directory (i.e. / on the virtual host nav.example.com) to request a login.php URL. What happens when e.g. /whatever is requested? Should that be forwarded to /modules/navigator/www/login.php/whatever ? It's probably just the /modules/navigator/www/ path; an empty request there probably gets rewritten to /login.php if necessary.

Assuming that, you need to rewrite / to /modules/navigator/www/. So:

server nav-server check
reqrep ^GET\ /(.*) GET\ /modules/navigator/www/\1

^ is the beginning of the line, so the path gets added to the beginning.

  • Thank you for your reaction! You are right regarding the 'login.php', that's indeed obsolete. However your solution doesn't seem to work... I'm getting error 400 - page not found. – Koenraad Jan 29 '18 at 20:25
  • The problem was that the reqrep command takes the complete request into account, not just the URL. I have edited my answer to take into account GET requests. Ideally also POST requests should be done as those probably are used as well, your answer handles that, see my comment there. – wurtel Jan 30 '18 at 14:09

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.