Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

iRule for sending traffic to a different pool based on the Hostname.

ashk
Cirrus
Cirrus

Team, 

 

I have a virtual server with port 8899 configured as PerformanceLayer4 and FastL4. I am using couple Host names to drive thru this Virtual Server. 

I want to send the traffic to pool_magnus when the traffic is coming with host magnus.com. 

I wrote an Irule as below but its not working I can see the host coming and still going to the default pool. I think the traffic coming is not http traffic its TCP traffic. Need assistance. 🙂 

when HTTP_REQUEST {
set host [string tolower [HTTP::host]]
if { $host eq "magnus.com" } {
pool pool_magnus
}
}

 

5 REPLIES 5

Hi @ashk , 

- you must add a HTTP profile in your bigip to let it able to parse http requests and understand the meaning of hostnames and headers. 
you can use the following syntax but after adding http profile first : 

 
 when HTTP_REQUEST { 
  
     #Check requested host header (set to lowercase) 
    switch [string tolower [HTTP::host]] { 
  
       "www.site1.com" { 
          pool site1_pool 
       } 
       "www.site2.com" { 
          pool site2_pool 
       } 
       default { 
          pool default_pool 
       } 
    } 
 } 
 


- you can use If statement as well. 

- the most efficiecnt one is to use Local traffic policies , it's light weight on system CPU and it's very easy to implement. 

I hope this helps you  

_______________________
Regards
Mohamed Kansoh

Dear Mohamed , 

can you please clarify the setting for this LTM Policy if we do not need to use the Irule? 

you need to ensure that you have http profile binded to the VIP in order to have irule attached thats all you need.

If you are planning to use traffic policies then you can refer the below 

https://techdocs.f5.com/kb/en-us/products/big-ip_ltm/manuals/product/local-traffic-policies-getting-....

Hi @Amr_Ali , 

it's like @vaibhav sent the official article. 

you will need to match on host header in uri , then Take forward action to specific pool. 

_______________________
Regards
Mohamed Kansoh

If it helps, you can do this very quickly in a Policy (LTP)
When HTTP Host = <Hostname> on Request.
Forward to "Virtual Server or Pool"
Its a very simiular concept to vip targetting vip, but its vip targetting many pools.
I do something very simular with uri's and pools.