iRule to do simple LB based only in HTTP host or uri.

Hello everyone!

There are several threads about this, but I didn’t find any specifically related to a simple HTTP::host or ::uri LB.

Most of my projects so far are based only on WAF without any other license. I need the help of an iRule to do simple LB when receiving multiple HTTP requests that belong to different servers.

I use this iRule to do it:

when HTTP_REQUEST {

    if { [HTTP::host] equals "example.com" } {
        pool pool_example_port-80
        snatpool snatpool_lan1
   log local0. “example.com sent to pool_example-port from snatpool_lan1.”
    }
    if { [HTTP::uri] starts_with "/myApp1" } {
        pool pool_app1_port-80
        snatpool snatpool_lan2
   log local0. “/myApp1 sent to pool_app1_port-port from snatpool_lan2.”
    }
}

I was just wondering if any of you guys could help me improve it. Maybe there’s something still left to do regarding best practices. For instance, it could be a best practice to return a status code when we’re done with a function that allocates memory in other languages.

Hi Rodrigo,

There’s nothing wrong with your iRule, it’s very common to do host or URI based load balancing like this. However current best practice would be to migrate this to an LTM traffic policy in the GUI as it is better for performance

You wouldn’t need to amend the status code in this instance as the applications serviced by the two pools will respond with a status code. You can obviously rewrite this if there is a requirement to do so.

Let me know if I can help you further.

Lee