Forum Discussion

Chandru_01's avatar
Chandru_01
Icon for Nimbostratus rankNimbostratus
May 28, 2017

irule to loadbalance and for header replace

I have 2 servers a.com and b.com which needs to be load balanced through F5, and the FQDN for the service would be c.com. The hostname c.com is not configured in either of the servers a.com or b.com.

When traffic hits the F5 as c.com, F5 needs to load balance the traffic by changing the HTTP::host to a.com or b.com based on the server that gets the connection.

This is the iRule that I try, but unable to fetch the results:

when CLIENT_ACCEPTED {

Returns 1 or 2 based on IP
set poolselection [expr {[crc32 [IP::client_addr]] % 2 }]

if { $poolselection eq 1 } {
    if { [active_members A] > 0 } {
set server 1
        pool A
    } else {
set server 2
        pool B
    }
} else {
    if { [active_members B] > 0 } {
set server 2
        pool B
    } else {
set server 1
        pool A
    }
}

}

when HTTP_REQUEST { if { $server eq 1 } { if { [string tolower [HTTP::host]] eq "c.com" } { STREAM::disable HTTP::header remove "Accept-Encoding" HTTP::header replace "Host" "a.com" pool A } } if { $server eq 2 } { if { [string tolower [HTTP::host]] eq "c.com" } { STREAM::disable HTTP::header remove "Accept-Encoding" HTTP::header replace "Host" "b.com" pool B } } }

when HTTP_RESPONSE {

Check if response type is text

if {[HTTP::header value Content-Type] contains "text" } { Replace URL STREAM::expression {@a.com@c.com@@b.com@c.com@}

Enable the stream filter for this response only

STREAM::enable } }

What am I missing?

  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    What type is the Web server on a.com and b.com?

     

    It shouldn't be hard to get the Web servers of the back-end servers to accept the traffic for c.com, which would be a better solution.