Forum Discussion

stolivar_88319's avatar
stolivar_88319
Icon for Nimbostratus rankNimbostratus
Mar 28, 2012

Using iRule for host header and uri routing (problem)

I have a virtual Server(F5) set up on an IP. I have two websites that share this IP and IIS is configured to handled host header hosting. I also run some java tomcat apps on one of the domains hosted so I need to route that to a different pool as well. So here is my config and maybe you all can help me

 

 

Virtaul server: Listens on 10.120.1.30 for www.host1.com, www.host2.com

 

 

www.host1.com gets routed to host1 pool

 

www.host2.com get routed to another pool

 

www.host1.com/pubservices-war gets hosted to tomcat pool

 

 

This all works correctly, but for some reason, I think something is being stripped out when host1 gets directed to the tomcat pool.

 

 

when HTTP_REQUEST {

 

switch [HTTP::host] {

 

www.host2.com { pool host2 }

 

www.host1.com {

 

if { [HTTP::uri] starts_with "/itunesu" } {

 

pool www.host1-Tomcat

 

} elseif { [HTTP::uri] starts_with "/iTunesu" } {

 

pool www.host1-Tomcat

 

} elseif { [HTTP::uri] starts_with "/iTunesU" } {

 

pool www.host1-Tomcat

 

} elseif { [HTTP::uri] starts_with "/pubservices-war" } {

 

pool www.host1-Tomcat

 

} elseif { [HTTP::uri] starts_with "/ref_form" } {

 

pool www.host1-Tomcat

 

} elseif { [HTTP::uri] starts_with "/ccv" } {

 

pool www.host1-Tomcat

 

}}

 

}

 

}

 

 

I believe by default all traffic goes to the default pool host1 as configured by the virtual server unless configured differently in the iRule.

 

 

Any thoughts?

 

 

 

 

 

2 Replies

  • Hi Stolivar,

    Can you try this version of the iRule which explicitly selects a pool for all cases? Once you're done testing, you can disable or remove the debug logging.

    
    when CLIENT_ACCEPTED {
     Log debug to /var/log/ltm? 1=yes, 0=no.
    set switch_debug 1
    
     Save the name of the VS default pool before the iRule could change it
    set default_pool [LB::server pool]
    }
    when HTTP_REQUEST {
    switch [string tolower [HTTP::host]] {
    www.host2.com {
    pool host2
    if {$switch_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Using host2 pool for [HTTP::host][HTTP::uri]"
    return
    }
    www.host1.com {
    switch -glob [string tolower [HTTP::uri]] {
    "/itunesu*" -
    "/pubservices-war*" -
    "/ref_form*" -
    "/ccv*" {
    pool www.host1-Tomcat 
    if {$switch_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Using www.host1-Tomcat pool for [HTTP::host][HTTP::uri]"}
    return
    }
    }
    }
    }
     If we are still in the iRule select the VS default pool
    pool $default_pool
    if {$switch_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Using $default_pool pool for [HTTP::host][HTTP::uri]"}
    }
    when LB_SELECTED {
    if {$switch_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Selected [LB::server]"}
    }
    when SERVER_CONNECTED {
    if {$switch_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Connected [IP::server_addr]:[TCP::client_port]"}
    }
    

    Aaron
  • Thanks Aaron, I put that into play and make the changes to actually reflect our real domain names and pools and I get the following error: Thoughts?

     

     

    01070151:3: Rule [idu-virtual-websites-pool] error:

     

    line 8: [parse error: missing close-brace] [{

     

    switch [string tolower [HTTP::host]] {

     

    salina.kumc.edu {

     

    pool idu-virtual-websites

     

    if {$switch_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Using idu-virtual-websites pool for [HTTP::host][HTTP::uri]"

     

    return

     

    }

     

    www.kumc.edu {

     

    switch -glob [string tolower [HTTP::uri]] {

     

    "/itunesu*" -

     

    "/pubservices-war*" -

     

    "/ref_form*" -

     

    "/ccv*" {

     

    pool www.kumc.edu-Tomcat

     

    if {$switch_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Using www.kumc.edu-Tomcat pool for [HTTP::host][HTTP::uri]"}

     

    return

     

    }

     

    }

     

    }

     

    }

     

     

    If we are still in the iRule select the VS default pool

     

    pool $default_pool

     

    if {$switch_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Using $default_pool pool for [HTTP::host][HTTP::uri]"}

     

    }

     

    when LB_SELECTED {

     

    if {$switch_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Selected [LB::server]"}

     

    }

     

    when SERVER_CONNECTED {

     

    if {$switch_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Connected [IP::server_addr]:[TCP::client_port]"}

     

    }]

     

    line 9: [command is not valid in the current scope] [switch [string tolower [HTTP::host]] {

     

    salina.kumc.edu {

     

    pool idu-virtual-websites

     

    if {$switch_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Using idu-virtual-websites pool for [HTTP::host][HTTP::uri]"

     

    return

     

    }

     

    www.kumc.edu {

     

    switch -glob [string tolower [HTTP::uri]] {

     

    "/itunesu*" -

     

    "/pubservices-war*" -

     

    "/ref_form*" -

     

    "/ccv*" {

     

    pool www.kumc.edu-Tomcat

     

    if {$switch_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Using www.kumc.edu-Tomcat pool for [HTTP::host][HTTP::uri]"}

     

    return

     

    }

     

    }

     

    }

     

    }

     

     

    If we are still in the iRule select the VS default pool

     

    pool $default_pool

     

    if {$switch_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Using $default_pool pool for [HTTP::host][HTTP::uri]"}

     

    }]

     

    line 9: [command is not valid in the current scope] [string tolower [HTTP::host]]

     

    line 9: [command is not valid in the current scope] [HTTP::host]