Server selection based on URI

Posted by ddesmidt One of our customers had a special request and I want to share it with you so you can enjoy our solution if you have similar needs They have 20 servers named S1 to S20. In the URL they give to their customers, each unique URL has to go to a specific server. Example: www.xyz.com/work/S2/etc/index.html. The AX would have to direct the traffic to server S2 The customer had some aFleX knowledge and created first something like: If HTTP::uri contains S2, then go to server S2 If HTTP::uri contains S3, then go to server S3 If HTTP::uri contains S4, then go to server S4 But his concerned was his aFleX had a lot of “if” and could degrade his AX peformance/scalability. I reassured him since aFleX can go through very long aFleX scripts with almost no performance and scalability impact. Note: We have customers with 1MB aFlex scripts processing almost 1Gbps of traffic and still plenty of room to do more! Anyway, his script could be optimized using some cool TCL commands Here is how: Code: when HTTP_REQUEST { # capture the server name (after "/work/" and before next "/") regexp {/work/(.*)/} [HTTP::uri] -> Server_id #log "Server_id = $Server_id" # redirect request to the specific server based on Server_id if { $Server_id ne "" } { switch $Server_id { "S1" { set server_ip "10.0.2.18" } "S2" { set server_ip "10.0.2.19" } } #check if that server is still UP and if so send the request to that server if {[string compare [LB::status node $server_ip port 80 tcp] up] == 0} { node $server_ip 80 #log "selection via URI = $server_ip 80" } } # in all other cases: No Server information or a server DOWN # => Do nothing in aFleX # => Do the VIP configuration # => Send the request to a server UP in the VIP Service Group }

Posted by fsun

It’s a interesting script…

I like it.