Forum Discussion

4 Replies

  • Well, one of the simplest things you could do might look like this:

    when HTTP_REQUEST {
        if { [active_members http_pool] < 1 } {
            HTTP::redirect "http://dr-site.example.com"
        }
    }
    

    where "http_pool" is the name of the pool assigned to the VIP (along with this iRule). I'd also add that this is a good case for global server load balancing (GSLB) where users are redirected via DNS to different data centers based on health and availability.

  • Hi Kevin,

     

    Thank you very much for your answer. However I forgot to mention one thing in my question, the customer has hosted multiple websites on a single physical web server.

     

    So if any of the single instance goes down, redirection should happen. Can you please share required changes in above iRule to achieve this requirement?

     

    Regards, Darshan

     

  • This highly depends on how the BIG-IP is routing traffic to these web sites. If you're doing host-based balancing at the physical server, then it sort of negates the need for an actual load balancer, as all traffic is simply routing to a single IP. If all of the web sites are on different IPs on the same physical server, then you'd probably want to do host-based balancing on the load balancer AND configure each site as an individual pool. This allows you to easily scale up any given service over time by simply adding service IPs to the pool.

    So I'll assume that you're using different IPs for each web site, that you're using the BIG-IP for host-based (or URI-based) balancing, that each web site is in its own pool, and that you're using something like a BIG-IP data group to make all of this happen. Example:

    Data group (my_host_datagroup):

    "sales.example.com" := "sales_pool"
    "tech.example.com" := "tech_pool"
    "mgmt.example.com" := "mgmt_pool"
    "www.example.com" := "www_pool"
    

    And then the iRule:

    when HTTP_REQUEST {
        if { [class match [string tolower [HTTP::host]] equals my_host_datagroup] } {
            set my_pool [class match -value [string tolower [HTTP::host]] equals my_host_datagroup]
            if { [active_members $my_pool] < 1 } {
                HTTP::redirect "http://dr-[HTTP::host][HTTP::uri]"
            } else {
                pool $my_pool
            }
        }
    }
    

    This does the basic host-based balancing using a datagroup to match the host name to the pool name. If the active members of the given pool is less than 1, the user is redirected to another URL. In this case I've simply added "dr-" to the front of the URL (ex. dr-tech.example.com). This part is dependent on your own naming and DNS conventions. If there are active members in the given pool, then the traffic is sent there.

    You could also do this with URI values as well for URI-based balancing - where the host name is the same but the URI dictates the pool to use.