Forum Discussion

networkingman_3's avatar
networkingman_3
Icon for Nimbostratus rankNimbostratus
Jan 15, 2018

URL based load balancing. How?

Hi,

 

We are kinda new to F5 and iRules so we don't really know how to create url based load balancing and we are not good at writing iRules. :)

 

What we want to do is that we have different pools and when example.com is typed into a browser it would direct the a user to the specific pool. When subdomain.example.com is called then it would direct them to another pool.

 

Could you please help with this?

 

Thanks in advance.

 

  • If you're not good at writing iRules, use LTM policy with 2 rules

     

    • HTTP Host equals example.com --> forward pool primary_pool
    • HTTP Host equals subdomain.example.com --> forward pool subdomain_pool
  • Here's an iRule I use for this type of thing. It uses a "Datagroup" that you can update the http host header to pool mapping to do what you want.

    1. Create a Datagroup "HOST_2_POOL_DataGroup" with entries like:

      "expample.com" := "APP_Pool01",
      "subdomain.example.com" := "APP_Pool02",
      

      `

    2. Here is the iRule "HTTP-Host-2-Pool-MAP"
      `when HTTP_REQUEST {
      set pool_select_value [class lookup [string tolower [HTTP::host]] HOST_2_POOL_DataGroup]
      if {[active_members $pool_select_value] > 0 } {
          log local0.notice "available pool members"
          pool $pool_select_value
          } else {
              HTTP::respond 503 content "No active pool members in pool"
          }
      }