Hi,

I am not sure if there is a better way, but the only one I can think of
would be something like:

  http-request set-header     X-Tmp %[path]
  http-request replace-header X-Tmp /([^/]+) \1
  use_backend %[req.hdr(X-Tmp),lower,map(/path/tofile)]

No idea which one is preferable with regards to performance, maybe test,
I'd assume it depends on your number of backends. The basic string map is
indeed quite performant, so using this variant might help if you do have a
lot of backends.

Cheers,
Conrad


On 01/28/2016 04:27 PM, Klavs Klavsen wrote:
> I got this to work:
> 
> use_backend %[path,lower,map_reg(/path/tofile)]
> 
> and with a map file containing:
> ^\/sebseb/
> ^\/test2/
> 
> and so on..
> 
> Only issue is the performance hit.. its going to do regex match with path
> on each line in the map file.. :(
> 
> I'd prefer to find a function to replace path.. which could substract the
> first part ^\/([^/])\/ - and then use \1 to match in map file..
> 
> But perhaps the map_reg isn't that expensive?
> 
> Klavs Klavsen wrote on 01/28/2016 03:39 PM:
>> Hi guys,
>>
>> I figured I could use map feature of 1.5, but I'm coming up short,
>> trying to change this:
>>
>>   use_backend %[req.hdr(host),lower,map(/path/tofile)]
>>
>>
>> To instead take a part of the uri.
>>
>> I can't find any list of functions (such as hdr, hdr_end etc.) in the
>> docs :(
>>
>> I figured I could use "something like" regrep instead of hdr(host)?
>>
>>
>> Klavs Klavsen wrote on 01/26/2016 02:53 PM:
>>> Hi guys,
>>>
>>> we have a long list of backends (want to monitor each application on a
>>> tomcat behind us) - and would like to use part of the url ( first part
>>> between / / ) to identify the backend (in haproxy) to use.
>>>
>>> so if we get a request for /sebseb/api/whatever - we'd like to use
>>> backend named kki-sebseb.
>>>
>>> we figure this should not be dangerous since haproxy seems fairly well
>>> coded - so a request for something bogus, should just result in the
>>> backend being invalid - and returning a 504 (we hope) ?
>>>
>>> I can't seem to find any examples on the net.. and can't figure it out
>>> from the haproxy 1.5 docs..
>>>
>>> I was hoping any of you had some hints :)
>>>
>>
>>
> 
> 

-- 
Conrad Hoffmann
Traffic Engineer

SoundCloud Ltd. | Rheinsberger Str. 76/77, 10115 Berlin, Germany

Managing Director: Alexander Ljung | Incorporated in England & Wales
with Company No. 6343600 | Local Branch Office | AG Charlottenburg |
HRB 110657B

Reply via email to