Forum Discussion

LaJuan_267846's avatar
LaJuan_267846
Icon for Nimbostratus rankNimbostratus
Oct 23, 2017

iRule for Single Wildcard VIP to Multiple Pools

I need suggestions for troubleshooting or help resolving how to send requests to a single domain to multiple pools based on the URL path. For example: https://apps.mydomain.com/dev/, https://apps.mydomain.com/qa/, https://apps.mydomain.com/test/, and https://apps.mydomain.com (default). I tried several variations and referenced several web resources. My current iRule sample is listed below. The default pool comes up, but none of the URL paths work.

when HTTP_REQUEST { 
   switch -glob [string tolower [HTTP::uri]] { 
     "*/dev/*" { 
       pool DEV-HQ_Pool
     } 
     "/qa/*" { 
       pool QA-HQ_Pool 
     } 
     default { 
       pool PROD-HQ_Pool 
     } 
   } 
 }

6 Replies

  • Your iRule looks fine. You probably want to change */dev/* to just /dev/*

     

    By default the F5 load balances per TCP connection and not per HTTP request. This means if you your first request goes to the default pool, any subsequent request down the same connection will go to the same pool. It will ignore any request to change the pool as the pool member selection is performed only once at the start of the connection.

     

    If you need per request load balancing then apply the oneconnect profile - see article K7208 for details but essentially at the bottom of your virtual server properties you will see oneconnect. Enable the system default profile and see if that solves your problem.

     

  • You can try with below irule and you can tweak according to your requirement. when HTTP_REQUEST { if {([HTTP::host] equals "; ) } { pool pool1 } elseif { ([HTTP::uri] starts_with "/dev")} { pool pool2 } elseif { ([HTTP::uri] starts_with "/qa")} { pool pool3 } elseif { ([HTTP::uri] starts_with "/test")} pool pool4 } }

     

    Hope this helps.

     

    • Kevin_Davies's avatar
      Kevin_Davies
      Icon for MVP rankMVP
      when HTTP_REQUEST { 
          if {[HTTP::host] equals "https://apps.mydomain.com"} { 
              pool pool1 
          } elseif {[HTTP::uri] starts_with "/dev"} { 
              pool pool2 
          } elseif {[HTTP::uri] starts_with "/qa"} { 
              pool pool3 
          } elseif {[HTTP::uri] starts_with "/test"} { 
              pool pool4 
          } 
      }

      I have corrected the typos.. in any case thats not going to work as the first condition will always match.

       

      FYI when pasting iRules, put your code on the page, when done, highlight the code and press TAB to indent it. Check the preview and you should see it formatted correctly.

       

  • You can try with below irule and you can tweak according to your requirement. when HTTP_REQUEST { if {([HTTP::host] equals "; ) } { pool pool1 } elseif { ([HTTP::uri] starts_with "/dev")} { pool pool2 } elseif { ([HTTP::uri] starts_with "/qa")} { pool pool3 } elseif { ([HTTP::uri] starts_with "/test")} pool pool4 } }

     

    Hope this helps.

     

    • Kevin_Davies's avatar
      Kevin_Davies
      Icon for MVP rankMVP
      when HTTP_REQUEST { 
          if {[HTTP::host] equals "https://apps.mydomain.com"} { 
              pool pool1 
          } elseif {[HTTP::uri] starts_with "/dev"} { 
              pool pool2 
          } elseif {[HTTP::uri] starts_with "/qa"} { 
              pool pool3 
          } elseif {[HTTP::uri] starts_with "/test"} { 
              pool pool4 
          } 
      }

      I have corrected the typos.. in any case thats not going to work as the first condition will always match.

       

      FYI when pasting iRules, put your code on the page, when done, highlight the code and press TAB to indent it. Check the preview and you should see it formatted correctly.

       

  • Hi LaJuan,

     

    your iRule syntax looks fine to me. To further troubleshoot your iRule, you may want to insert additional debug code to see if the iRule is getting triggered and which code path it has choosen...

     

    when HTTP_REQUEST { 
        log local0.debug "New Request to: [string tolower [HTTP::uri]]"
        switch -glob -- [string tolower [HTTP::uri]] { 
            "*/dev/*" { 
                log local0.debug "*/dev/* is selected..."
                pool DEV-HQ_Pool
            } 
            "/qa/*" {
                log local0.debug "/qa/* is selected..."
                pool QA-HQ_Pool 
            } 
            default { 
                log local0.debug "Default pool is selected..."
                pool PROD-HQ_Pool 
            } 
        } 
    }

    Cheers, Kai