avoid downtime due to DNS-drag

Ever had this problem?

You have to switch servers for some reason and so naturally your DNS-settings have to be updated to the new IP-Adress. Well, moving the website to the new server is not the problem in itsself. The Problem is, that DNS-settings sometimes take very long to take effect. They might be right at your nameserver, but that does not mean, that your visitors get the same result for a dns-query.

Most ISPs have their own DNS-machines that cache request – and some do that for a very long time – several days. Yes, and that way possible visitors for your site experience days of downtime even though your server is running perfectly.

My solution to the problem is pragmatic, but it works:

The DNS-cache serves out my old server’s IP-Adress. And because my old server stays online for at least a week after the switch (for failsave reasons etc.) I only had to find a way to make it respond to the requests that it gets because of DNS-cache.

The clue here is not to serve the page from the old server, but to retrieve the pages and files from the new server and serve them. As I had a mongrel-cluster running on my old server, most of the config was already in place. It makes use of the Apache Proxy Configuration. You basically define your new server as the host your old server proxies for. This config might not be the most elegant way to do this, but for something that should not stay online for longer than a week, I refused to spend more time researching.

So here is the config:
For each website you want to forward, write the following into you apache-config (on SuSE a new file in /etc/apache/conf.d did the trick)

<Proxy balancer://yoursite>
BalancerMember http://www.yoursite.com:80

<VirtualHost 123.456.334.332:80>
ServerName   yoursite.com:80
ServerAlias  http://www.yoursite.com
RewriteEngine On
RewriteRule ^/(.*)$ balancer://yoursite%{REQUEST_URI} [P,QSA,L]

As I said, this might not be the most elegant solution, but it definately does the trick. 😉

I hope, someone might find this useful. I know that it saved a few of my visitors from staring at an almost blank screen when expecting my site. 😉


It turnes out that the above is no good for multiple domains. 😦

So here is a better version:

<VirtualHost *:80>
     ServerName red.x-tend.be

     ProxyRequests off
     ProxyPreserveHost On
     ProxyPass / http://red.internal.x-tend.be/
     ProxyPassReverse / http://red.internal.x-tend.be/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s