HAProxy community

HAProxy response based redirection to backend


I have two Vault clusters in two halls which can communicate with each other. A Vault primary cluster in Hall 1 and it’s performance replica in hall 2. I have a one HAProxy instance that routes the traffic to the the primary cluster only. Now due to weirdest reasons possible what I need to do is route the traffic to the performance replica backend servers if the http-response status code is 403 (permission denied) when the requests fail to authenticate with the primary cluster.

To try something more simple I’ve tried to add this in the backend

http-response redirect location https://hostname.com code 302 if { status 403 }

But when I look at the stats page I see that there’s no traffic being routed to that server.
My questions are these:

  1. Is there a way I can redirect to a backend based on a http-response code
  2. Is there a way I can redirect from a backend to another backened based on status code?
  3. If the answers to the above are no then how can I possibly solve this problem? (Problem being routing based on http-response code

Kudos if you can also provide me example-syntax for solutions.