HAproxy - multiple conditions in ACL

Viewed 87

I'm try to take few redirect on HAproxy and all of them don't work on the same time. So in my config

    bind *:443 ssl crt SOME CERT
    mode http
    http-request add-header X-Forwarded-Proto http
    option forwardfor
    option forwardfor header X-Real-IP
    http-request set-header X-Forwarded-Proto https if { ssl_fc }
    timeout client 300000
    acl route_1 hdr(host) -i some.example.com
    use_backend some_example1 if route_1
    acl route_2 hdr(host) -i some.example.com && path_beg /test
    use_backend some_example2 if route_2
    acl begins_with_test path_beg /test
    use_backend normal_test if use_backend
    default_backend regular_backend

I was try to change order ACL route_1 and route_2 but only first of them working. Domain without alias is ok and works fine. Split route_2 to two ACL's and place it into use_backend not working as I wish

1 Answers

Well the order counts.

# Because this acl matches will the second not be evaluated
acl route_1 hdr(host) -i some.example.com
use_backend some_example1 if route_1
acl route_2 hdr(host) -i some.example.com && path_beg /test
use_backend some_example2 if route_2

My suggestion is to rearrange the acls

bind *:443 ssl crt SOME CERT

  mode http
  timeout client 300000

  option forwardfor
  option forwardfor header X-Real-IP

  http-request add-header X-Forwarded-Proto http
  http-request set-header X-Forwarded-Proto https if { ssl_fc }

  # && (AND) is implicit
  acl route_2 hdr(host) -i some.example.com path_beg /test
  use_backend some_example2 if route_2

  acl route_1 hdr(host) -i some.example.com
  use_backend some_example1 if route_1

  acl begins_with_test path_beg /test
  use_backend normal_test if use_backend

  default_backend regular_backend
Related