9

I have a problem with HAProxy, it's a snippet of my haproxy.cfg below,

acl url_a path_beg   /a
acl dom_eye hdr_dom(host) -i www.mydomin.com
use_backend eye1 if dom_eye
use_backend eye2 if dom_eye url_a
  1. when i visit www.mydomin.com/a, it use eye2
  2. when i visit www.mydomin.com/a/b, it use eye1

but I would expect that all the url begin with /a use eye2.

And, I found that when switch the order of use_backend like below,

acl url_a path_beg   /a
acl dom_eye hdr_dom(host) -i www.mydomin.com
use_backend eye2 if dom_eye url_a
use_backend eye1 if dom_eye

it worked for me.

But I don't understand the "match order rule" of Haproxy and can't find any explain from google.

Any ideas on this?

Swoogan
  • 2,087
  • 1
  • 14
  • 21
glancesx
  • 91
  • 1
  • 1
  • 2

1 Answers1

12

I don't know why it doesn't work for you, but the HAProxy documentation states:

There may be as many "use_backend" rules as desired. All of these rules are evaluated in their declaration order, and the first one which matches will assign the backend.

From: http://cbonte.github.io/haproxy-dconv/configuration-1.4.html#4-use_backend

Looking at your code:

acl url_a path_beg /a
acl dom_eye hdr_dom(host) -i www.mydomin.com
use_backend eye1 if dom_eye
use_backend eye2 if dom_eye url_a

I would expect the following results:

www.mydomin.com -> eye1
www.mydomin.com/a -> eye1
www.mydomin.com/a/b -> eye1

Because all of them match the first use_backend.

If you change the config to:

acl url_a path_beg /a
acl dom_eye hdr_dom(host) -i www.mydomin.com
use_backend eye2 if dom_eye url_a
use_backend eye1 if dom_eye

I would expect these results:

www.mydomin.com -> eye1
www.mydomin.com/a -> eye2
www.mydomin.com/a/b -> eye2

Because only URL 2 and 3 match the first use_backend.

Could you confirm this is not what happens in your config?