HAProxy community

Help creating content rule from parameter


#1

Hello,

HAProxy 1.6.3

I need some help creating acls to branch based off a URL Parameter.

Example: http://www.mysitesample.com/my/site/is/here/myfile.aspx?parameter1=foo&clientid=bar01&index=100

I want to switch send traffic to backend servers matching a range of what “clientid” equals, type is text.
Samples of what clientid can equal: Client01, client01, CLIENT01, cLIENT01, CottageCheese01, Bluesky03 (and all upper/lower case variants), might not be the word client at all. more like the client’s name. The text ‘bar01’ is a sample and not a constant) and the ClientID parameter can appear anywhere in the client list.

say
Client01 through client05 goes to backend 1
Client06 through client10 goes to backend 2
CottageCheese01 or Bluesky03 goes to backend 3
If all else fails, go to backend 4.

Hopefully this explains it.
thank you!


#2

Query is in the string query:
https://cbonte.github.io/haproxy-dconv/1.6/configuration.html#7.3.6-query

You can match it with regular expressions, exact matches or substring matches, among other things:
https://cbonte.github.io/haproxy-dconv/1.6/configuration.html#7.1.3

And then you just use use_backend and default_backend

acl clients_for_backend1 query -m reg -i clientid=client0[1-5]

acl clients_for_backend2 query -m reg -i clientid=client0[6-9]
acl clients_for_backend2 query -m sub -i clientid=client10

acl clients_for_backend3 query -m sub -i clientid=CottageCheese01
acl clients_for_backend3 query -m sub -i clientid=Bluesky03

use_backend backend1 clients_for_backend1
use_backend backend2 clients_for_backend2
use_backend backend3 clients_for_backend3
default_backend backend4