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

Create a cookie with a value of the requested subdomain

$
0
0

Create a cookie with a value of the requested subdomain

Community version 2.0.14-lp152.1.2.x86_64
openSUSE leaf 15.2

Working with a new system that is multi-tenanted where externally the customers use a url of customerX.mysite.com only rather than a number its a name
Bob.mysite.com
Fred.mysite.com
Charlotte.mysite.com

The backend servers are all balanced using leastconn and any customer can use any backend server.

At present we have a complicated an clunky way of redirecting each user to the correct database however this could be set as a session cookie

I have been asked to insert a cookie that has the subdomain (bob, fred, etc.) as a value which could then function as the identifying cookie

Currently I have tried creating a variable within the listen statement and then using that within the backend. This creates the cookie DBNAME with a / path but as I have done it so far, there is no value

frontend mysite
bind *:443 ssl crt /etc/haproxy/mydomain.pem alpn h2,http/1.1
mode http
option httpclose
http-request set-var(req.subdomain) req.hdr(host),lower,regsub(.mysite.com$,) if { hdr_end(host) -i .mysite.com
default_backend myservers

backend myservers
mode http
cookie SERVERID insert indirect nocache
http-response add-header Set-cookie DBNAME=%[var(req.subdomain)];\ path=/
server myserver1 192.168.0.1:8443 cookie srv1 ssl verify none check
server myserver2 192.168.1.1:8443 cookie srv2 ssl verify none check
… (10 total my servers)

Why no value? I have used the same set-var statements in the past but this time nothing.

Thanks

Tim

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 4714

Trending Articles