Forum Discussion
iRule for host rewriting between nodes
Finally it works ok with the Data group + iRule solution.
Thanks to all of you!
- mlympany
Nimbostratus
Hello,
Have you tried replacing the event "LB_SELECTED" with "HTTP_REQUEST" in your iRule?
According to the online docs:
HTTP::header and HTTP::host are not under the "LB_SELECTED" event, but
LB::server, HTTP::header and HTTP::host commands are available under HTTP_REQUEST
Thanks, - mlympany
Nimbostratus
Have you tried switching the event from LB_SELECTED to HTTP_REQUEST? I don't believe the HTTP::Header or HTTP::Host commands are available under LB_SELECTED.
- Martin182
Cirrus
Yes, I have tested both events, but it seems that the fact that there is an SSL Profile Server makes the rewrite not behave correctly.
However, if I disable the SSL Profile Server it seems to be working correctly. It seems to be some incompatibility between my code and the existence of encryption F5 <> Nodes. Hi Martin182
What is the backend server application port?
- Martin182
Cirrus
Both the virtual server and the nodes listen to port 443
- Martin182
Cirrus
I have found another possible approach, using data groups combined with iRule.
https://community.f5.com/discussions/technicalforum/rewrite-host-header-to-specific-pool-member/152235
https://community.f5.com/discussions/technicalforum/change-host-header-for-each-node-in-a-pool/190532
I may try it out during the day.
- Martin182
Cirrus
Finally it works ok with the Data group + iRule solution.
Thanks to all of you!
Hi Martin,
You can try add logging statements to your iRule to capture the selected server and the rewritten Host header. This will help you verify that the iRule is executing as expected.
Adding logging can help debug the issue:
when LB_SELECTED {
log local0. "Selected server: [LB::server addr], Host: [HTTP::host]"
switch -glob [string tolower [HTTP::host]] {
"service1.dns.com" {
if { [LB::server addr] eq "192.168.50.100" } {
log local0. "Rewriting Host to service1.ocp.site1.com"
HTTP::header replace Host "service1.ocp.site1.com"
} elseif { [LB::server addr] eq "192.168.50.101" } {
log local0. "Rewriting Host to service1.ocp.site2.com"
HTTP::header replace Host "service1.ocp.site2.com"
}
}
"service2.dns.com" {
if { [LB::server addr] eq "192.168.50.100" } {
log local0. "Rewriting Host to service2.ocp.site1.com"
HTTP::header replace Host "service2.ocp.site1.com"
} elseif { [LB::server addr] eq "192.168.50.101" } {
log local0. "Rewriting Host to service2.ocp.site2.com"
HTTP::header replace Host "service2.ocp.site2.com"
}
}
"service3.dns.com" {
if { [LB::server addr] eq "192.168.50.100" } {
log local0. "Rewriting Host to service3.ocp.site1.com"
HTTP::header replace Host "service3.ocp.site1.com"
} elseif { [LB::server addr] eq "192.168.50.101" } {
log local0. "Rewriting Host to service3.ocp.site2.com"
HTTP::header replace Host "service3.ocp.site2.com"
}
}
"service4.dns.com" {
if { [LB::server addr] eq "192.168.50.100" } {
log local0. "Rewriting Host to service4.ocp.site1.com"
HTTP::header replace Host "service4.ocp.site1.com"
} elseif { [LB::server addr] eq "192.168.50.101" } {
log local0. "Rewriting Host to service4.ocp.site2.com"
HTTP::header replace Host "service4.ocp.site2.com"
}
}
}
}
This will log the selected server and the host header, helping you verify if the conditions are being met and the headers are being rewritten correctly.
Use a tool like curl or a web browser to generate traffic to your virtual server. For example:
curl -H "Host: service1.dns.com" http://192.168.50.100
curl -H "Host: service2.dns.com" http://192.168.50.100
curl -H "Host: service3.dns.com" http://192.168.50.100
curl -H "Host: service4.dns.com" http://192.168.50.100
curl -H "Host: service1.dns.com" http://192.168.50.101
curl -H "Host: service2.dns.com" http://192.168.50.101
curl -H "Host: service3.dns.com" http://192.168.50.101
curl -H "Host: service4.dns.com" http://192.168.50.101
When you run the command curl -H "Host: service1.dns.com" http://192.168.1.100, you are making an HTTP request to the server at 192.168.50.100 and setting the Host header to service1.dns.com. This simulates a request as if it were coming from a client trying to access service1.dns.com, allowing you to test how your iRule handles this specific host.Check Logs:
Review the logs on your F5 load balancer to verify that the iRule is executing correctly. Look for the log entries you added to confirm that the Host header is being rewritten as expected.
Ensure that the applications on OpenShift are receiving the correct Host headers and responding appropriately. Check for any 404 errors or other issues.
Monitor the traffic and logs to ensure the iRule continues to function correctly. Make any necessary adjustments based on your observations.
Use tools like grep to filter and view specific log entries. For example:
grep "Selected server" /var/log/ltm
grep "Rewriting Host" /var/log/ltm
HTH
Best Regards
F5 Design Engineer
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