iRule pool selection based on [HTTP::host]

Hello,

I’m trying to distribute traffic that comes to VS among some pools based on ]HTTP::host]. Here is the iRule but unfortunately it doesn’t work:

when HTTP_REQUEST {

set hostname [string tolower [HTTP::host]] if { $hostname contains "site1.com" } { pool pool1 } elseif { $hostname contains "site2.com" } { pool pool2 } elseif { $hostname contains "site3.com" } { pool pool3 } }

VIP resets the connection:

Recv failure: Connection reset by peer

Wireshark says that RST has been sent due to “no server selected”

Looking for your help.

Hi Andrey,

Could you include logging in your irule to see if there is a match?

when HTTP_REQUEST {
set hostname [string tolower [HTTP::host]]
    if { $hostname contains "site1.com" } { 
        pool pool1
        log local0. "pool1 selected"
    } elseif { $hostname contains "site2.com" } { 
        pool pool2 
        log local0. "pool2 selected"
    } elseif { $hostname contains "site3.com" } { 
        pool pool3 
        log local0. "pool3 selected"
    } 
}

Cheers,

Kees

Hi,

you can use local traffic policies instead of irule to do that.

if you want to use irule, use this one:

when HTTP_REQUEST {
switch -- [string tolower [HTTP::host]] {
    "site1.com" { 
        pool pool1
    "site2.com" { 
        pool pool2 
    "site3.com" { 
        pool pool3 
    } 
    log local0. "The selected pool is : [LB::server pool]"
}