Forum Discussion

msdatla_64383's avatar
msdatla_64383
Icon for Nimbostratus rankNimbostratus
Aug 16, 2013

Selecting another Virtual from and iRule of one Virtual ? URI based routing ?

Hi guys,

Is there a way that we can select new virtual from the iRule of one Virtual server? i tried "LB::reselect virtual vs1" but it didn't worked.

I am trying to implement URI based routing between two apps ( website/vip1 || website/vip2 should go to one app1 and everything else should go to another app2)
app1 is a webapplications which has its own iRule which does some additional tasks like inserting new headers and some redirects
app2 is just a static web site

here is the first iRule

when HTTP_REQUEST {
if {
([HTTP::uri] starts_with "/vip1") ||
([HTTP::uri] starts_with "/vip2") 
} then {
pool pool1
} else {
pool pool2
}
}
when LB_SELECTED {
log local0. "[LB::server addr] is selected" 
if { 
([LB::server addr] eq "192.168.68.46") ||
([LB::server addr] eq "192.168.68.45") 
} then {
log local0. "[LB::server addr] is selected" 
LB::reselect virtual vs2
} } `

5 Replies

  • You should be able to just use the virtual command without LB::reselect:

     

    https://devcentral.f5.com/wiki/iRules.virtual.ashx

     

    Aaron

     

  • Thanks Aaron for a quick answer, appreciate it.

    But the virtual vs2 is not getting the request if you do so

    When you go directly to vs2, it is serving the request (autoSNAT is enabled on both, also CMP is also enabled on both)

    i also modifed the iRule to look like this, which should have same affect, same thing happens here as well.

    when HTTP_REQUEST {
    if {
    ([HTTP::uri] starts_with "/vip1") ||
    ([HTTP::uri] starts_with "/vip2")
    } then {
    virtual vs2
    } else {
    pool pool2
    }
    }
    
  • Minor update to your code:

     

    when HTTP_REQUEST {
        if { ( [HTTP::uri] starts_with "/vip1" ) || ( [HTTP::uri] starts_with "/vip2" ) } {
            virtual vs2
        } else {
            pool pool2
        }
    }

    Does this work?

     

  • Try this:

    when HTTP_REQUEST {
        log local0. "URI = [HTTP::uri]"
        if { ( [string tolower [HTTP::uri]] starts_with "/vip1" ) or ( [string tolower [HTTP::uri]] starts_with "/vip2" ) } {
            log local0. "Going to virtual vs2"
            virtual vs2
        } else {
            log local0. "Going to pool pool2"
            pool pool2
        }
    }
    

    Then from the command line:

    tail -f /var/log/ltm
    
  • Any chance your internal virtual (vs2) is using a client SSL profile? And you're not using a server SSL profile on the external VIP? Try this just to simplify things:

    when HTTP_REQUEST {
        virtual vs2
    }
    

    Then just purposefully go to "/vip1" to test. Does this get you to the internal VIP?