HAProxy community

Having hard time with redirect


I have a horribly written application and am trying to work around that limitation.

I’m having a hard time figuring out how to do this. I’ve actually done it before so know it’s possible but that was some time ago. I have HAProxy installed and it’s doing transparent balancing to three backend servers. The problem is that it’s doing it transparently and I actually need it to just redirect. Doesn’t even need to proxy the connections necessarily.


Request is for (this is HAPRoxy host)

Redirect should be to one of my backend servers or

The way it’s working now is that it’s proxying to but leaving the URL as I need the URL to be

There’s a lot of good information about how to change the URI, but I can’t figure out how to have HAProxy substitute the frontend url for the back end IP.


As per

this should be as simple as:
redirect prefix


But how do I redirect to multiple backend servers using round Robin or leastconn? It’s a web farm on the backend so there isn’t necessarily an acl I can create to determine which of the backend servers to hit…


That is a strange and uncommon setup. You may want to go back to the drawing board.

That said, it is possible by using an ACL with the rand() function:

Something like this (adjust as per requirements):

redirect prefix if { rand() gt 2147483647 }
redirect prefix if { rand() gt 2147483647 }
redirect prefix

Last redirect should be unconditional, otherwise some request may not get redirected.


It’s the web application’s fault. I’d love to use HAP transparently but haven’t been able to figure the damn thing out. The application makes secondary connections after establishing a session so what happens is the application authenticates you on host and then somewhere else in the application it uses the URL to make another connection to / app2/plasticapp whichis the HAP host and HAP does it’s thing and sometimes it works but other times (when the load balance algorithm picks host it fails because the user is authenticated to It’s stupid.

I actually did this once before but maybe the HAP versions are different…I used the following rather than a frontend backend:

listen webloadbalance xxx.xxx.xxx.xxx:80
mode http
stats enable
stats uri /haproxy?stats
stats realm Strictly\ Private
stats auth navbalance: xxxxxxxxx
balance roundrobin
option httpclose
option forwardfor
option httpchk
server web01 xxx .xxx.xxx.xxx redir http :// xxx .xxx.xxx.xxx check
server web02 xxx .xxx.xxx.xxx redir http :// xxx .xxx.xxx.xxx check

That did the trick for me…but no joy now…


You right, that would also work.

Why it doesn’t work right now I can’t tell with the data provided.

Can you:

  • provide the output of haproxy -vv
  • provide the complete configuration
  • provide the output of a curl request in verbose mode
  • provide the output of the haproxy log


I got it. When I moved the config to the new box my syntax was off. I found it and appear to be all good now. Thanks a lot for the assistance!