Forum Discussion

GJR-UK_248612's avatar
GJR-UK_248612
Icon for Nimbostratus rankNimbostratus
Jan 25, 2018

irule to change http host based on port

Hi all, I have a need to change a http host based on port.

I have four virtual servers - same IP address but each listening on 443, 444,446,447.

The need is for all traffic to be sent to server.domain.co.uk on one of the four ports but then to rewrite the header and be sent to the pool member based on port to one of: server-443.domain.com

server-444.domain.com

server-446.domain.com

server-447.domain.com

all receiving on 443 This is so that the relevant log store can be hit

I have a different irule for each virtual server specific for the port and head: e.g.

when HTTP_REQUEST {
   if { ([HTTP::host] eq "server.domain.co.uk") } {
         HTTP::header replace Host "server-444.domain.com"
        }
  }

I'm finding that the "443" rule is hit every time even if one of the other ports is addressed.

Hoping I've not over-complicated the explanation.

Is there a neat way to get the result I'm after?

1 Reply

  • Try this:

    when HTTP_REQUEST {
       if { ([HTTP::host] eq "server.domain.co.uk") } {
            switch [TCP::local_port] {
                443 {
                    HTTP::host "server-443.domain.com"
                    pool POOL_443
                }
                444 {
                    HTTP::host "server-444.domain.com"
                    pool POOL_444
                }
                446 {
                    HTTP::host "server-446.domain.com"
                    pool POOL_446
                }
                447 {
                    HTTP::host "server-447.domain.com"
                    pool POOL_447
                }
            }
        }
    }
    

    or even better

    when HTTP_REQUEST {
       if { ([HTTP::host] eq "server.domain.co.uk") } {
            HTTP::host "server-[TCP::local_port].domain.com"
            pool POOL_[TCP::local_port]
        }
    }