Forum Discussion
Rewrite host header to specific pool member
I've done basic host header rewrites rules in the past but I've just received an odd request that's beyond me. I'm scrapping together a solution from multiple posts but haven't got anything to pass yet.
Our developers want the F5 to receive the URL "ims.services.company.com" and rewrite the host header to reflect the specific pool member, after the node is selected by the LB algorithm. To the point, they want the client to send the GET with "ims.services.company.com" in the host header and the F5, serverside, to send a GET for "ims.services..company.com" in the header.
I've tried this with combinations of HTTP_REQUEST, LB_SELECTED, and HTTP_REQUEST_SEND but nothings working.
I'm assuming this can be done?
Thanks.
16 Replies
- suprgroovy_1658
Nimbostratus
I am picking up this project from Andy, and have had to reverse-engineer this irule back into our QA environment (runs the same version of code), and of course, it doesnt work there. I created the data class with the same name and syntax, just with the new IP addresses and string to lookup. the debug logs showthis:
Looked up 10.52.4.67, found: .
I will repost what what i have in the QA environment:
when HTTP_REQUEST_SEND {
Log debug messages to /var/log/ltm? 1=yes, 0=no.
set host_debug 1
Need to force the host header replacement and HTTP:: commands into the clientside context
as the HTTP_REQUEST_SEND event is in the serverside context
clientside {
if {$host_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: New [HTTP::method] request to [HTTP::host][HTTP::uri]"}
Look up the selected server IP in the datagroup to get the host header value
set host_header_value [findclass [LB::server addr] netenghosts " "]
if {$host_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Looked up [LB::server addr], found: $host_header_value."}
Check if the lookup returned a value
if {$host_header_value ne ""}{
Replace the host header value
HTTP::header replace Host $host_header_value
if {$host_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Replaced Host header with $host_header_value."}
}
}
}
class netenghosts {
"10.52.4.67 ims.next004pqa.services.qaprod.company.com"
}
I essentially copied and pasted from the production devices, so it doesnt appear that the irule or data class syntax is bad, yet persists in not finding the lookup value.
TIA
-clay - hoolio
Cirrostratus
Hi Clay,
That looks valid. Can you confirm it's just a space between the IP address and host name in the datagroup?
Aaron - suprgroovy_1658
Nimbostratus
just to be sure, i went back and deleted/retyped those characters, and I get the same message in the ltm log:
Looked up 10.52.4.67, found: .
-clay - suprgroovy_1658
Nimbostratus
Not sure what the problem was, but here is how i fixed it:
1. created a new data group string with a different name
2. pasted in the same parameters.
3. updated the iRule to reference the new data group.
4. watched it work.
PFM
Thanks for keeping an eye on this and being willing to help.
-clay - hoolio
Cirrostratus
That's quite odd. Glad you got it working regardless.
Aaron - w7com_208168
Nimbostratus
Here's how I pulled it off:
when LB_SELECTED { set POOL [LB::server addr] log local0.debug "Pool Member is $POOL" switch $POOL { 10.65.16.135 { HTTP::header replace Host "strv-int2.corp.lan" } 10.65.17.62 { HTTP::header replace Host "strv-int4.corp.lan" } default { log local0.debug "Default hit on STRV-rewrite." } } }
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
