Forum Discussion

Mat78_387100's avatar
Mat78_387100
Icon for Nimbostratus rankNimbostratus
Mar 28, 2019

Irule redirection based on URL

Hi, I need to create a VIP, an redirect the traffic to different Pool depending of the URL requested. I have created this Irule: when HTTP_REQUEST {

 if { [HTTP::host] eq "URL_1" } {

    pool  POOL_1
}
elseif { [HTTP::host] eq "URL_2" } {

    pool  POOL_2
}

elseif { [HTTP::host] eq "URL_3" } {

    pool  POOL_3
}

elseif { [HTTP::host] eq "URL_4"} {

    pool POOL_4
}

}

URL_1 [...] and URL_4 have the same VIP IP. Each POOL have been created via GUI.

Usually, each time i create a VIP, i need to associate it to a POOL. But for my case, i don't know how to implement it, becasue i have 4 POOL.

thanks for your help.

Best regards

2 Replies

  • Hi Mbarreau,

    I'd prefer the

    switch
    command to parse the requested
    HTTP::host
    value for
    pool
    selection.

    when HTTP_REQUEST {
        switch -exact -- [string tolower [HTTP::host]] {
            "site1.domain.de" {
                pool pool_1
            }
            "site2.domain.de" {
                pool pool_2
            }
            "site3.domain.de" {
                pool pool_3
            }
            "site4.domain.de" {
                pool pool_4
            }
        }
    }
    

    Note: The the example above uses a

    [string tolower [HTTP::host]]
    command to ignore the case during evaluation. It helps to make the pool selection more robust...

    Cheers, Kai

  • I modify the irule to get some logs. Now, the Irule looks like that: when CLIENT_ACCEPTED { set client [IP::client_addr] log local0. "Client: $client has established a connection"

     

    } when HTTP_REQUEST { log local0. "Request HTTP is [HTTP::host]" set client_info [IP::client_addr]:[TCP::client_port] set url [HTTP::request] log local0. "Client Source IP: $client_info is requesting URL: $url " switch -exact -- [string tolower [HTTP::host]] { "test1.fr" { pool test1 } "test2.fr" { pool test2 } "test3.fr" { pool test3 } "test4.fr" { pool test4 } } }

     

    when SERVER_CONNECTED { set pool_name [LB::server pool] log local0. "Client Source IP: [IP::client_addr]:[TCP::client_port] <--> POOL : $pool_name <--> ACTUALNODE <--> [IP::server_addr]:[TCP::server_port]" }

     

    It still not working, and on the log, i didn't see the URL requested: Apr 11 16:26:12 BIG-IP-LTM info tmm1[10587]: Rule /Common/Irule_TEST : Client: X.X.X.X has established a connection Apr 11 16:26:12 BIG-IP-LTM info tmm1[10587]: Rule /Common/Irule_TEST : Client: X.X.X.X has established a connection Apr 11 16:26:12 BIG-IP-LTM info tmm1[10587]: Rule /Common/Irule_TEST : Client Source IP: X.X.X.X:31506 is requesting URL: Apr 11 16:26:12 BIG-IP-LTM info tmm1[10587]: Rule /Common/Irule_TEST : Client: X.X.X.X has established a connection Apr 11 16:26:12 BIG-IP-LTM info tmm1[10587]: Rule /Common/Irule_TEST : Client Source IP: X.X.X.X:28300 is requesting URL:

     

    For sure, something is missing on my configuration. On the Virtual server, you just have to add the irule, no POOL ?

     

    regards