Forum Discussion

SteveT_240596's avatar
SteveT_240596
Icon for Nimbostratus rankNimbostratus
Feb 03, 2016

session persistance using x-forward-for

The traffic coming to our virtual server is being reverse proxied from 2 TMG servers meaning we only see 2 source IP addresses. The header does contain the x-forward-for address of the original client. Our application team wants us to load balance this traffic across 3 web servers with session persistence. We have tried using the iRule below from an example we found but it does not appear to work. We are new to F5 so appreciate any assistance.

 

when HTTP_REQUEST { if {[HTTP::header exists "X-Forwarded-For"] }{

 

persist uie [HTTP::header X-Forwarded-For] 1830 log local0. "PATTS X-Forwarded-For: [HTTP::header X-Forwarded-For]"

 

3 Replies

  • Hi Steve,

    you may try the snippet below...

    when HTTP_REQUEST { 
        if { [HTTP::header value "X-Forwarded-For"] ne "" } then {
             log local0. "PATTS \"X-Forwarded-For\" header: [HTTP::header value "X-Forwarded-For"]"
            persist uie [HTTP::header value "X-Forwarded-For"] 1830 
        } else {
             log local0. "No \"X-Forwarded-For\" header found."
        }
    }
    

    Note: I duno if you posted just the half iRule for illustration purposes? I've completed then given iRule, tweaked here and there a little bit the syntax and added an additional [log] statement to get some ouput if no X-Forwarded-For header is not present or somehow empty.

    Cheers, Kai