Options

Replace Host Header based on server selection

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?

Comments

  • Options
    edited July 2022
    Posted by ddesmidt

    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:
    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
Sign In or Register to comment.