问题原文
原帖链接 · Ruhrohshingo · CC BY-SA 4.0
So I've been working on building out an haproxy cluster (1.5.x) and hit a snag where for a particular webapp I'm wanting to pitch API GETs to a read-only app cluster and the PUTs into a much smaller write cluster.
I've tried using a path_reg, which doesn't seem to want to match anything beyond a filename. The urlp derivatives seem to be what I should be using, but their proper usage has eluded me. The one tricky nuance with the URL parameters I'm trying to capture and differentiate all begin with either a "get" or "set" something...but the parameters do not have values. From what I've understood or attempted to, the urlp derivatives generally expect there to be a value associated with a parameter, so it seems like I can't simply use something like:
acl api_gets urlp_reg(get) (get?){1}
from an URL with parameters like:
/api.foo?apikey=stuff¶m1=foo&getsomething¶m2=bar
Similarly, path_reg seems to not pick up anything beyond a filename, so rudimentary testing of trying to match the following as a proof of concept were also fruitless:
acl path_sanity_check path_reg ^\/api\.foo\?apikey.*
Whereas simply making the regex pattern ^/api.foo will pick up where the requests are being sent to.
Should I be using urlp_reg for this even if the parameter(s) don't have values? What alternatives are there if not using an urlp derivative?
已采纳解答
原帖链接 · Michael - sqlbot · CC BY-SA 4.0
Path fetches the path. The query isn't part of the path. capture.req.uri fetches the full URI.
Although sloppy, you could match that with something like this:
acl foo capture.req.uri -m reg [&\?]get
The character class escaping might require adjustment, but the idea is to find either ?get or &get in the request URI.
If you are building a new cluster, use HAProxy 1.6, which has a number of new, useful fetches and converters, plus optional Lua integration for more complicated logic.
urlp_reg is the wrong solution, because the regex match is for the value of the parameter, not its name... and you don't have values.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
