Forum Discussion

aberrati0n_902's avatar
aberrati0n_902
Icon for Nimbostratus rankNimbostratus
Jan 09, 2012

iRule using alternate address to hit specific node

Hello,

 

 

I've got a problem that's proving to be trickier than I expected. Our company hosts a variety of public facing servers running similar software, each client on a vlan of their own that follow our standard IP addressing scheme. Previously, we only served out of one datacenter and we had an iRule that let us specify a port that would then translate into a server IP. We would use that to check on the state of individual pool members without having to resort to host file trickery. Recently though, we turned up a second datacenter and are load balanced across the two with a pair of GTMs that pick a pool member (in this case, a datacenter) and that rule only works if the GTM decides to send you to the datacenter you were hoping for. Otherwise, you have to wait 10 minutes for your session to expire and hope you get the other one then.

 

 

 

Now that that's out of the way... the plan so far has been to create a series of new subdomains on an IP address that we assign to a new virtual server. That virtual server then has 1 iRule assigned to it that reads the new subdomains, sets a variable based on the client (used to send to the correct subnet) and replaces the header with that of the correct site (to bypass using the GTM for DNS so that we can always hit the datacenter we want). This almost works. The example I have posted below will allow me to hit the server I want, but the application depends on being served at a specific address, as does the google maps v2 api key (which is being replaced soon), so all I get is the application server's default page.

 

 

 

Here is an example of what I've got so far

 

 

 

when HTTP_REQUEST {

 

if { [HTTP::host] contains "ptk.first.example.org" } {

 

set clientsubnet 10

 

HTTP::header replace "ptk.first.example.org" "web.first.com"

 

}

 

elseif { [HTTP::host] contains "ptk.second.example.org" } {

 

set clientsubnet 11

 

HTTP::header replace "ptk.second.example.org" "web.second.com"

 

}

 

 

if {[string length [TCP::local_port]] == 4} {

 

set last_two [string range [TCP::local_port] 2 3]

 

node 10.0.$clientsubnet.1$last_two:80

 

}

 

}

 

 

 

 

To reach the other datacenter, I have another rule in place on the other site's LTMs for ran.first.example.org and servers run on 10.1.x.x. So... if I access ptk.first.example.org:8001, my host header is changed to web.first.com and I am directed to the node 10.0.10.101 which is what I want. However, the web application and the google maps API key both know that I'm still actually at ptk.first.example.org and refuse to work.

 

 

 

Anyway, does anyone know of a way to pass a host header in a way that the web application acknowledges it or a way to just replace the whole URL without then falling back on the GTM or a hosts file to resolve the DNS? Am I going about this problem the entirely wrong way? Thank you.

 

  • shouldn't it be HTTP::header replace Host "web.first.com" and HTTP::header replace Host "web.second.com"?
  • Thanks, that helped a lot. It's almost working perfectly now!

     

     

    The issue now is that if I type only the root url and port (ptk.first.example.org:8001) then I am redirected to the address that I'm replacing the host header to (web.first.com), the GTM is queried for DNS which is currently sending me to the wrong datacenter and the server selection bit of the code is effectively ignored. However, if I specify an exact page/file to load (ptk.first.example.org:8001/main.jsf), the URL will not change to what I'm replacing the host header with and the application will load on the server I specified. However, the Google Maps API v2 is still complaining that the site needs its own unique API key which is keeping the rest of the application from loading. Is there anything else I can do, or are my hands tied until we upgrade to the newer API?