How can i get content path in Haproxy?

I stored port number in client side path and i want to use it in webserver in frontend section.
How can i get path content in Haproxy? i dont want to use if command

My code is:

global
    log /dev/log    local0
    log /dev/log    local1 notice
    chroot /var/lib/haproxy
    stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
    stats timeout 30s
    user haproxy
    group haproxy
    daemon

defaults
    log global
    mode    http
    option  httplog
    option  dontlognull
    timeout connect 5000
    timeout client  50000
    timeout server  50000

frontend http80
        bind *:2095
        mode http
        
        use_backend webs1 if { path -m beg -i /1023 }
        use_backend webs2 if { path -m beg -i /5449 }
        use_backend webs3 if { path -m beg -i /4855 }
        
backend webs1
        mode http
        server webserver1 ip:1023
        
backend webs2
        mode http
        server webserver1 ip:5449        
        
backend webs3
        mode http
        server webserver1 ip:4855      

thanks

Upvotes: 0

Views: 458

Answers (1)

Aleksandar
Aleksandar

Reputation: 2672

You can try to set the dst port via http-request set-dst-port

Here a untested example, just that you get the idea

backend webs2

  http-request set-var(txn.dst-port) %[url,'regsub("\/","",i)']
  http-request set-dst-port %[var(txn.dst-port)]
  
  server webserver1 0.0.0.0:0

Here is the documentation for http-request set-dst

Upvotes: 1

Related Questions