Skip to content. | Skip to navigation

Sections
Personal tools
What is this?
Hi, my name is Tom Lazar and I'm a Plone and Zope developer based in Berlin, Germany and this is my personal and professional (no big difference, really...) website.
 

Site wide maintenance message

Filed Under:

When doing maintenance work on a deployment site it is always a good idea (and in good taste) to show visitors a human-readable page explaining that you'll be back soon[tm] instead of letting them see ugly tracebacks etc.

Easy, right? Just put a static HTML file and configure it as the site root and you're done, right? Well, not quite. Because that will show the page to all visitors of the root of your site, but everybody else will get a 404.

Well, regular expressions and nginx to the rescue. The following configuration snippet displays the same index.html page to any request, not just the front page. I now keep it commented out in all my config files to be able to quickly turn on a maintenance message if something requires some fixing:

server {
    listen 80;
    server_name foobar.tld;

    root /usr/local/www/foobar/;
    index  index.html index.htm;
    location ^~ /index.html {
    }
    location / {
        rewrite "^/(.+)$" / last;
    }
}

The crucial part is the (empty) ^~ /index.html location that simply exists to stop an endless recursion that would take place otherwise. It also means, that your HTML file must be named index.html and reside in /usr/local/www/foobar/ on the file system.