Poorman's Redundant Server (master)

This page uses JavaScript to detect whether the primary server is up, and if it is not, transfer to a secondary server. No access to routers or nameservers is required. The method requires a cached copy of the page, either locally or on e.g. Google.

Testing

To test the operation of this script, block access from your PC to vancouver-webpages.com, visit some other page such as this one, then return. You should see the master page for a few seconds (cached in your browser, or in a public cache), then your browser should jump to the slave page. If access to the master site vancouver-webpages.com is restored, and you leave and return to the slave page, the master site will be reloaded.

In Linux, blocking access may be done easily with ipchains, e.g.

ipchains -A input -s  vancouver-webpages.com -j DENY
to block access and
ipchains -D input -s  vancouver-webpages.com -j DENY
to allow it. On other systems, a firewall command may be used, or a static route created to a nonexistent interface or gateway, or a temporary entry made in a hosts file to an address such as 127.0.0.2.

The Script

You may use view source, or visit a text version of the Master and Slave pages.

How it Works

The document is a regular static HTML page (cacheable, with no immediate expiry date. In includes an image that is uncacheable, so that every time the page is visited, it will be loaded from the server. In this example, the image is visible, but normally it would be invisible, perhaps a small transparent GIF. It is important that its size be defined in the HTML, otherwise the browser "broken image" icon may appear full-size.

Here, the Apache ASIS feature is used to serve a JPEG image with defined HTTP headers, specifically

Content-type: image/jpeg
Pragma: no-cache
Expires: 0
Cache-Control: none
When the page is visited, it is retrieved from cache and displayed, The check image should not be in cache and must be retrieved from the master server. If there is an error loading the image, or a timeout, as may result from the master server being down or unreachable, then a script is called to jump to the slave server.

A similar script on the slave page checks the availability of the master server and jumps back if it is up, since it is generally not desired that people remember or bookmark the slave pages. Search engines may be deterred from indexing the slave pages by using e.g. the ROBOTS meta tag <meta name="robots" content="none">

Andrew Daviel
andrew@vancouver-webpages.com
Vancouver Webpages