Last week I rolled out a new web application for a customer of mine. This application is configured in a warm-standby failover configuration. However, in the case of a failure, the customer wanted the application to failover to a static webpage (in a future post I will go over the monitoring implementation). The reason for doing this, was the customer’s staff wanted to review the cause of the failure before deciding to redirect all traffic to the warm-standby server. At this time, the application did not require 99.99% uptime or even 99.9% uptime, so this is a fine plan.

The static “site is down” webpage is running in a separate server from web application (in a different datacenter). In the case of a failure, the IP address of the server hosting the web application would be moved to this server. The server is running nginx for as the HTTP/HTTPS server.

The nginx configuration was very vanilla, except that had to

  1. For all incoming requests, no matter the URL, return a simple static page and all associated images and css files.
  2. The URL in the browser should not be re-written.
    • This allows the user to refresh the page and return to the same place in the application as they were before the failure.

This was handled using the nginx rewrite module. I used the following configuration

{% highlight apache linenos%} server { listen 80; location / { root /var/www/default; index index.html index.htm; rewrite ^(.*)$ /sitedown/ last; } location /sitedown { root /var/www/sitedown; index index.html index.htm; } … … } {% endhighlight %}

The webpage and any required css,js or image files will need to be placed in the /var/www/sitedown/sitedown directory. The src attribute for any image, css or js file will need to be prefaced with /sitedown. For example, if the image filename is maintenance.jpg and it is located in the /var/www/sitedown/sitedown directory, then the image tag should look like

<img src="/sitedown/maintenance.jpg">