Replace Host Header based on server selection
in aFleX
Posted by kberton
I have a web app that's picky about the host HTTP header that it receives.
The backend servers expect the web clients to hit the backend server hostname directly, so when servers reach it through the hostname assigned to the load balancer, the app gets confused. Is there any way via aFlex that I can a) determine which backend server the client is getting routed to, and b) rewrite the host header to the value the server is expecting?
I have a web app that's picky about the host HTTP header that it receives.
The backend servers expect the web clients to hit the backend server hostname directly, so when servers reach it through the hostname assigned to the load balancer, the app gets confused. Is there any way via aFlex that I can a) determine which backend server the client is getting routed to, and b) rewrite the host header to the value the server is expecting?
0
Comments
Yes the aFleX can help there too
We introduced in 2.6.0 the aFleX new events and commands.
The new event "LB_SELECTED" and command "LB::server" provides information about resources selected by SLB.
For your need, you can use the following code:
when LB_SELECTED { # Set up variables automatically set server_ip [LB::server addr] # Change Host for each server switch $server_ip { "10.0.2.18" { HTTP::header replace Host server1.example.com } "10.0.2.19" { HTTP::header replace Host server2.example.com } } }
Enjoy,
Dimitri