Url’s are called by http://somewebsocket.domain.com/123.123.123.123/8700 on the frontend.
These ip and ports can differ.
We want to split the url and set variables for the ip and port (first and second parts after the domain) and be able to use these as a backend server.
Not separate blocks of backends but like we already do with incoming different ports.
For port only we have come up with something like this, but it also has to include the server-ip
On the backend something like :
frontend default
…
acl is_port path_reg /([0-9]+)$
use_backend range_http if is_port
backend range_http
http-request set-var(req.port) path,regsub(^.*/([0-9]+)$,\1,\1)
server lab 10.10.10.10:[var(req.port)]
Which in fact also fails with a nice “error detected in backend ‘range_http’ while parsing ‘http-request set-var(req.port)’ rule : invalid arg 2 in converter ‘regsub’ : missing arguments (got 1/2), type ‘string’ expected.”
In short something like NGINX does like the example below :
server {
listen 80;
server_name websocket.domain.com;
location ~ ^/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/([0-9]+) {
set $backend_ip $1;
set $backend_port $2;
proxy_pass http://$backend_ip:$backend_port;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# If you need to proxy WebSocket connections, include the following headers
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
Can this be done with haproxy since this will make it really flexible and removes the need for hundreds of separate backends and a lot of reloading/reconfiguring.