How to balance w/ consistent-hash based on only the filename?


#1

Hi,

it’s probably dead simple, but I can’t figure it out. I have request URLs in a form of

http://hostname.tld/some/subdir/filename.suffix
http://hostname.tld/other/subdir/filename.suffix

The “/some/subdir/” and “/other/subdir/” are more or less random; only the “filename.suffix” is consistent.

Consequently, I can’t use the beginning of the path for balancing with “hash-type consistent”, but need to balance based only on the filename portion of the URL. Is there something like a negative value for the “depth” parameter (depth -1)? Otherwise, I could probably extract the filename.suffix portion by a regex, add the result as a header, and use that header for the balancing.

frontend
http-request set-header “X-Filename” <filename.suffix extracted>

backend
hash-type consistent
balance hdr(“X-Filename”)

In addition, I only want the filename.suffix taken in to account for the consistent hashing, nothing else, especially NOT the Host header.

So basically the question is, how do I add the header with the filename?

Thanks in advance

Sascha


#2

just in case anyone is interested, I ended up with

backend image-proxies-80
balance hdr(X-LB)
hash-type consistent

frontend images-443
http-request set-header X-LB %[path,regsub(/.*/,)]

that is, removing everything from the path up to and including the last “/” (forwared slash), which is the filename.

Cheers

Sascha