Forum Discussion

Jean_Mamène's avatar
Jun 25, 2019

Rewrite HTTP host based on server name loadbalanced

Hi all,

My application is not compatible with the reverse proxy.

I have 2 servers in my pool.

I need to replace the http host with the name of the server loadbalanced.

I try this iRule

when HTTP_REQUEST_SEND {
  clientside {
    if {[HTTP::host] equals "bi.test.com"} {
      HTTP::header replace Host "[class match -value [LB::server addr] equals test-datagroup]"
    }
  }
}

test-datagroup:


1.1.1.1 := "server1.test.local",
1.1.1.2 := "server2.test.local",

but when I try the URL I have a response but only the uri https://hub and not https://bi.test.com/hub

Regards

1 Reply

  • Hello Jean.

    I would say that "LB::server addr" is not a valid method to use in this event (HTTP_REQUEST_SEND) base on this -> https://clouddocs.f5.com/api/irules/LB__server.html

    I recommend you to use "IP::server_addr" instead. I'm also including some log events to trace the iRule variables. You can remove those logs after verify that everything is working properly.

    when HTTP_REQUEST_SEND {
    	clientside {
    		log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] request to [HTTP::host][HTTP::uri]"
    		if {[HTTP::host] equals "bi.test.com"} {
    			set host_header_value [class match -value [IP::server_addr] equals test-datagroup]
    			log local0. "[IP::client_addr]:[TCP::client_port]: Looked up [IP::server_addr], found: $host_header_value."
    			if {$host_header_value ne ""}{
    				HTTP::header replace Host $host_header_value
    				log local0. "[IP::client_addr]:[TCP::client_port]: Replaced Host header with $host_header_value."
    			}
    		}
    	}
    }

    REF - https://devcentral.f5.com/s/articles/rewrite-host-header-to-server-name

    KR,

    Dario.