NGiNX Dynamic Maintenance Page

MD
S
Markdown

Simple script which reads a txt and generates the corresponding HTML version (on each request). Based on: http://mailman.nginx.org/pipermail/nginx/2009-January/thread.html#9075

Code for dynamic generation of the HTML file (via symlink)

This suggestion is more performant than having nginx read the contents of a file on each request.

 if [ -s maintenance_file.txt ]; then ln -s `cat maintenance_file.txt`
maintenance.html; elif [ -f maintenance.html ]; then rm maintenance.html; fi

NGiNX Directives

server {
    ...
    if (-f $document_root/system/maintenance.html) {
        rewrite  ^(.*)$  /system/maintenance.html last;
        break;
    }
    if (-f $document_root/system/down_for_a_while.html) {
        rewrite  ^(.*)$  /system/down_for_a_while.html last;
        break;
    }
    ...
}

Created on 9/2/2018