haproxy match various conditions in use_backend
Asked Answered
C

3

21

I'm trying to match various conditions inside one backend, like this:

acl rule1 hdr_dom(host) -i ext1
acl rule2 utl_beg /img
default_backend back-server-http if rule1 and rule2

but, how can I put this "and" between the two rules?

Continuum answered 21/6, 2012 at 14:9 Comment(1)
An other related question: serverfault.com/questions/768575/…Continuum
C
25

Yes, this is the solution:

acl rule1  hdr_dom(host) -i www.uno.es  hdr_dom(host) -i www.one.com
use_backend uno.com if rule1
Continuum answered 10/12, 2012 at 16:21 Comment(4)
How can a request have both hosts? It seems impossible that this ACL could ever be matched.Molybdenous
Yes, you can, its the same if you add contidions to the same acl inside different lines.Continuum
the answer example doesn't match the question example: for the question would it be something like this: acl rule1 hdr_dom(host) -i ext1 utl_beg /img?Moise
@Moise - see the examples here: github.com/langpavel/haproxy-doc/blob/master/version-1-4-19/tex/…. Given what you've written I'd expect that to work.Grigg
P
21

You don't need to use the word "and" between the two rules. It's implicit.

Source: http://haproxy.1wt.eu/download/1.5/doc/configuration.txt in Section 7.2

Pitchman answered 6/8, 2012 at 2:49 Comment(0)
B
-1

I think the below syntax will do the trick (check this link HAProxy - basic authentication for backend server)

acl rule1 hdr_dom(host) -i ext1
acl rule2 utl_beg /img
default_backend back-server-http if rule1  rule2
Boor answered 12/3, 2021 at 11:25 Comment(1)
'default_backend' cannot handle unexpected argument 'if'.Essam

© 2022 - 2024 — McMap. All rights reserved.