Backends "use-server" with dynamic name

Hello all,

I’m trying to create redirect if java console redirect to my proxy url /redirect/something?host=host1
then it gets basically redirected to that host in url parameter. The problem is the backend server list is not static at all, new servers are added and removed all the time…

I would need something like this to work:

frontend customer_facing
  mode http
  bind <ip>:80
  bind <ip>:443 ssl crt /etc/ssl/private/key.pem
  http-request redirect scheme https unless { ssl_fc }
  use_backend console_redirect if { path_beg /redirect }

backend console_redirect
  mode http
  use-server urlp(host) if { urlp(host) -m found }  <-- this does not work 
  server test

I think I can use dataplane API to insert new server test2, server test3 etc into the config without reloading the whole haproxy… but I need the backend to choose correct server base on the host variable from URL…

So If i do https:///redirect/something?host=test it gets redirected to the server called “test” in the backend

I really need some help with this :slight_smile:

Funny enough, this seems to work:

use-server %[urlp(host)] if { urlp(host) -m found }

But if I have more servers in the backend, then if he does not find the server specified in use-server it chooses round-robin any of the servers in there… I need it to either choose a specific server defined by use-server or not use any of them… fail or go to some default

Ok so I went one level up and add choosing between whole backends with:

`use_backend %[urlp(host)] if { urlp(host) -m found }

and then having just one server in backend… this is kind of working but its adding additional API calls to whole system, now I will have to create backend, then add server to it… there must be a simpler solution.

I just noticed, there was a similar thread already: