It’s been forever since I edited the HAProxy file. I had been using a GUI for it and I forgot a lot of stuff.
I didn't have much luck with the docs.
Well, that’s not completely true. I found more than a couple of ways to go about, straightforward but neither was the full solution and both kept a pretty strict scope not giving the slightest hint that it was okay to go out of it, it was like one of those situations where you should know something else first to know about some non-trivial list of caveats which are so unrelated that there aren’t mentioned at all in the current instructions, off the top of my head; setting up fastpath
rules for the first time in a firewall, or VRRP with some sort of multicast proxy in the network. It’s all straightforward until it isn’t.
I’m trying to use a section of the path in a request to compose the subdomain string and use it to send it in the Host
header.
The “variables” doodled in the screenshot don’t exist or match anything else in the picture. They’re only there to show more or less my idea of their syntax, so hopefully somebody would correct me.
I though about two 1½ ways of doing it, one is using {I forgot the name just now}, but what I mean is that sort of regex string manipulation shown in the line with set-header
in the picture above.
The other is more or less the same, but taking from var(txn.txnpath)
[1] what’s needed, the second (\2
) capture group from ^(\/)([^/]*)(.*)$
[2] set that into another variable then call it again from the set-header
line, hopefully. I figured that this way although it’s an extra step, I’d also have an extra variable available for use in some other manipulation, right?? IDK it’s probably nonsense.
Of course I could just assemble the strings myself because — yes — I am aware that since what I’m matching is exactly what I am attempting to rewrite, I could just directly write the rule and be done with it since I know the values needed, and wouldn’t likely be creating something close to a wildcard-matching security compromise. But then I wouldn’t learn anything, and as it is I’m breaking the one rule I have which is not to write code (i.e. copy and paste) that I don’t understand. I never thought about what would or should I do if I stopped understanding it and it’s driving me a little insane.
I’m open to any advice/suggestions even if unrelated. Thanks!
which BTW I don’t completely remember how are these set; I rescued my config file from the last time I used HAProxy without a GUI hence the existing code syntax. I wasn’t an expert but I felt very natural by the end of it, even the layout looked like more like stats than syntax. ↩︎
in other words: whatever’s between the first or leftmost set of
/
s in the path where the rightmost/
is optional ↩︎