user2648990
user2648990

Reputation: 103

Haproxy Route Traffic Based on Querystring

I want to config Haproxy to route traffic based on querystring. In particular...

  1. If /lookup is in the URL, go to xxx.xxx.xxx.xxx
  2. If /related and ?loc= is in the url, go to yyy.yyy.yyy.yyy
  3. If /related and no ?loc=, go to zzz.zzz.zzz.zzz

Any ideas how to do this? Thanks in advance!

Upvotes: 2

Views: 3164

Answers (1)

user9461715
user9461715

Reputation:

You're probably looking for urlp (aka url_param) to fetch sample from query string.

Something like this perhaps?

acl lookup path_beg /lookup
acl related path_beg /related
acl loc urlp(loc) -m found

use_backend xxx if lookup
use_backend yyy if related loc
use_backend zzz if related !loc

NOTE: lookup and related ACLs check if the URL begins with the path (not "in the" path). Also loc ACL checks if the query parameter exists even if it's empty. You need to change it a bit if it doesn't exactly fit your case.

Upvotes: 3

Related Questions