Quantcast
Channel: HAProxy community - Latest topics
Viewing all articles
Browse latest Browse all 4755

Append string to backend name after using field to get substring of host header?

$
0
0

We have HAproxy 2.1.11 configured so that it handles 80/443 and routes to backends based on the subdomain (i.e. test.some.example.org goes to the backend named test), and want to extend this to doing range based (i.e. 3000-4000) rather than explicit ports as well.

We can’t directly just add bind *:3000-4000 ssl crt ... to our existing frontend definition, because we terminate SSL and both 80/443 get proxied to port 80 on the backends, and we don’t want to map 3000-4000 to port 80 too, but to 3000-4000.

So, I have basically copy-pasted the existing setup, and change the bind to the range, and set up the backend with same names but with _range appended to the end (i.e. there would be bother a test and test_range backend with the above example).

The problem I’m having is figuring out how to append _range to the backend name that we’re determining by using field to extract the subdomain from the host header.

Here’s the relevant bit of the original config:

frontend main
  bind *:80
  bind *:443 ssl crt /etc/haproxy/ssl/
  # Detect hyphens in subdomain (technically, anywhere, but we'd only see them on subdomain)
  acl rule_hyphen hdr(host) -m sub -- -
  # Set X-Forwarded-Proto according to whether SSL was used
  http-request set-header X-Forwarded-Proto https if { ssl_fc }
  http-request set-header X-Forwarded-Proto http if !{ ssl_fc }
  # If a hyphen is present in subdomain, split on hyphen
  use_backend %[req.hdr(host),field(1,-)] if rule_hyphen
  # Split on .
  use_backend %[req.hdr(host),field(-4,.)]
  # Backend not found, default to the wild backend
  default_backend wild

Basically, for the use_backend lines, I want to have whatever the %[req.hdr(host),field(...)]... gets determined to be, have _range appended to the end of it. I.e. test.some.example.org is test after the host field extraction, and we need it to become test_range.

I have tried the following:
use_backend %[req.hdr(host),field(-4,.)]_range
use_backend concat(%[req.hdr(host),field(-4,.)],_range)

I’m not sure what else to try, the documentation doesn’t seem to really cover this use case with it’s examples.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 4755

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>