Previewing Content on Load Balanced Web Servers

I have one client with an unusual configuration – the web servers are load balanced, but the database servers are not. Each web server has a static hosts entry for a database server and there is a script that periodically runs to see if the database server is alive. If it isn't, the script edits the host file and changes IP of dummy entry for the database server. It's a fairly crappy solution that exists to deal with some ColdFusion session handling issues and an even junkier database architecture.

I can't change the configuration, but fairly frequently I have to troubleshoot a problem that lies on an individual server. The challenge of course, is to figure out which server is having the problem. If you're using Firefox the ShowIP extension is helpful, but you will only see the IP address of the load balancer (at least in this configuration).

Externally if you browse to http://domain.tld/ you are accessing the NLB and have no control of which server you are directed to. Internally you can browse to each server by their IP address, or the NLB directly. To browse to an individual server you use the IP address and provide a Host header (this is the same way that name based virtual hosting works).

Example Load Balanced Design

In the image above, browsing to http://domain.tld/ would take me to the Load Balancer, which would then provide content from one of the individual servers.

Manually Testing

One method of testing is to edit your hosts file (%systemroot%\\system32\\drivers\\etc\\hosts on Windows, /etc/hosts on Linux/OS X) and add an entry in the format of ip host. For example if I wanted to preview domain.tld on 192.168.1.5 I would add the following line to my hosts file:

192.168.1.5    domain.tld

I've found that I need to close and re-open Firefox because of its DNS caching, which means it can take serveral minutes to check a page on 4 or 5 individual servers.

Automated Testing with ColdFusion

I finally tired of the manual process and wrote a quick page in ColdFusion that uses the CFHTTP tag and passes a Host header using CFHTTPPARAM, like this:

<cfhttp url="http://192.168.1.5" resolveurl="YES" timeout="20" getasbinary="auto">
 <cfhttpparam type="header" name="Host" value="domain.tld"></cfhttpparam>
</cfhttp>

Content is embedded in an iframe and you can use a regular expression to help restrict browsing to valid hosts. Here's an example using google.com.

Google NLB Sample

Issues and Code

I'm using CFMX 7 and ran into an issue related to the URL rewriting; relative URLs are rewritten to http://ip/image.gif, which won't work if you're using name based virtual hosts. If you replace http://ip with http://hostname then you'll be browsing through the NLB. I didn't spend too much time on it, but I couldn't find a way to have ColdFusion output binary content, allowing the page to behave more like a proxy server. CFMX 8 allegedly this easier, but I haven't tried it yet.

In the end I decided that proxying linked content wasn't anything I needed time since the majority of the issues I was troubleshooting were database related, not CSS/JS/image. If I ever need to do more with this then I'll probably rewrite it using PHP and cURL.

You can download the code here.

 

2 Responses to “Previewing Content on Load Balanced Web Servers”

  1. Brian Blood Says:

    You can also go a different route. Create Single service content rules in the load balancer that map a specific port to only a single server.

    In the NLB, the rules would be:
    port 80 could go to servers A, B, C or D
    port 8001 would go to Server A
    port 8002 would go to Server B
    etc. etc…

    On the server side you won't have to change anything, as the NLB should translate the ports internally from 8001 to port 80.

    This way you can still use full host names from the outside, yet be sure that you are only accessing content on a specific server like so:

    http://www.domain.com:8001/

  2. Corey Says:

    I'd definitely prefer a solution like that, unfortunately I'm not in a position to force that type of change (or at least it's not worth the fight given the other issues I'd rather see fixed). The other issue will be any form that uses absolute URLs and pages that redirect you.

Leave a Reply


© 2007-2010, Corey Gilmore | Posts RSS Feed | Comments RSS Feed | Contact

 

The views expressed on these pages are mine alone and not those of any past or present employer. All information presented on this site was obtained lawfully and not through disclosure under the terms of an NDA.