Forum Discussion

mattboston_5893's avatar
mattboston_5893
Icon for Nimbostratus rankNimbostratus
Apr 11, 2011

Different pool depeding on the URI

With the F5 is it possible to send all traffic for www.domain.com to a default pool, but when someone requests www.domain.com/images it goes to a special images pool of servers?

 

 

Thanks

 

Matt

 

  • Yes. We do something like this:

     

     

    when HTTP_REQUEST {

     

     

    use tolower to make the match case-insensitive

     

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

     

     

    "/images/*" {

     

    pool ImagesPool

     

    }

     

     

    "/js/*" {

     

    pool JsPool

     

    }

     

     

    etc.

     

    etc.

     

     

    default {

     

    pool defaultPool

     

    }

     

    }

     

    }

     

     

     

    The URI gets compared to the strings you specify, and if it matches, the request gets sent to specified pool. If it doesn't match any of them it falls through to the pool specified in the default clause.
  • All of our existing rules use if/elseif/else and do matches like the following (trimmed down). Is it possible to do what you said using the existing if/elseif/else statement.

     

     

    when HTTP_REQUEST {

     

    if { [string tolower [HTTP::host]] equals "www.domain.com"}

     

    {

     

    HTTP::respond 301 Location "http://www.domain.com[HTTP::uri]"

     

    }

     

    elseif { [string tolower [HTTP::host]] equals "images.domain.com"}

     

    {

     

    pool images.domain.com

     

    }

     

    else

     

    {

     

    pool public_http_pool

     

    }

     

     

    }

     

  • The if/elseif/else option will be less efficient than a switch statment--particularly since you're setting the Host header value to lower case again for each conditional check. But yes, that would function.

     

     

    Aaron
  • I'd rather not change our existing rules without having time to test them.

     

     

    One last question. If I make a request to www.domain.com/images that will be looking for the /images subfolder on the images.domain.com pool, correct? Or can I point /images to the root folder. So if someone requested /images/banners/mybanner.jpg it would look for /banners/mybanner.jpg on the destination pool.
  • You can strip /banners from the URI using string range:

     

     

    HTTP::uri [string range [HTTP::uri] 8 end]

     

     

    Here's a quick test:

     

     

    % string range /banners/mybanner.jpg 8 end

     

    /mybanner.jpg

     

     

    Aaron
  • So how would I add the stripping into the following?

     

     

    when HTTP_REQUEST {

     

    if { [string tolower [HTTP::host]] equals "www.domain.com"}

     

    {

     

    HTTP::respond 301 Location "http://www.domain.com[HTTP::uri]"

     

    }

     

    elseif { [string tolower [HTTP::host]] equals "images.domain.com"}

     

    {

     

    pool images.domain.com

     

    }

     

    elseif { [string tolower [HTTP::host]] starts_with "/images"}

     

    {

     

    pool images.domain.com

     

    }

     

    else

     

    {

     

    pool public_http_pool

     

    }

     

     

    }
  • I would think it needs to be in the scope of the elseif, like this:

     

     

    elseif { [string tolower [HTTP::uri]] starts_with "/images"}

     

    {

     

    HTTP::uri [string range [HTTP::uri] 7 end]

     

    pool images.domain.com

     

     

    }

     

     

    I don't know that it would matter if it was before or after the pool statement since the string inspection has already been done. Note that I changed the string inspection line to use HTTP::uri where you had HTTP::host.