0

The problem is that, I have haproxy configured for multiple domains with backends respectively. The intended behaviour is to redirect a specific request such as myfirstdomain.com/alerts to backend2 and the already configured backend myfirstdomain.com still configured to provide for backend1.

Current haproxy.cfg

frontend https_443_frontend
  bind *:80
  bind *:443 ssl crt build_rupid_in.pem crt code_rupid_in.pem crt artifacts_rupid_in.pem crt prodmon_rupid_in.pem crt prodmondb_rupid_in.pem

  acl ACL_backend0 hdr(host) -i myzerodomain.com
  use_backend backend_backend0 if ACL_backend0

  acl ACL_backend1 hdr(host) -i myfirstdomain.com
  use_backend backend_backend1 if ACL_backend1

backend backend_backend0
  mode http
  server app01 127.0.0.1:9909

backend backend_backend1
  mode http
  server app02 127.0.0.1:9990

What i tried

ACL_alerts path -i -m alerts
use_backend backend2 if ACL_backend1 ACL_alerts
backend backend2
  mode http
  server app2 127.0.0.1:9999

What else should I change and please help me in understanding how this works. I guess I need to add http-request replace-path and http-response replace-something. I don't know for sure how this works. Please help me resolve this.

3
  • if i understand correctly how haproxy works, i think nginx would be more suiteable due you can change based on locations. there are like this similar question that says even too that it seems haproxy may not the right choice
    – djdomi
    Commented Feb 14 at 7:50
  • @djdomi haproxy changed a lot in 10 years. reqrep isn't supported anymore and replaced by http-request replace-uri. This should help haproxy.com/blog/path-based-routing-with-haproxy
    – AlexD
    Commented Feb 14 at 10:16
  • Alex, I am unaware of the changes because I got stuck on nginx. I believe in your words. ;-)
    – djdomi
    Commented Feb 14 at 10:37

1 Answer 1

0

You can use path_beg matching. Optionally you can remove /alerts part from the URI.

frontend https_443_frontend
  bind *:80
  # ssl stuff
 
  use_backend backend2 if { path_beg /alerts/ }
  # fallback for non-matching requests
  default_backend backend1

backend backend1
  mode http
  server app01 127.0.0.1:9909

backend backend2
  mode http
  http-request replace-path /alerts(/)?(.*) /\2
  server app02 127.0.0.1:9990

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .