Skip to content

Instantly share code, notes, and snippets.

@mundry
Last active December 2, 2015 20:31
Show Gist options
  • Save mundry/8b6dc0374511a84e2471 to your computer and use it in GitHub Desktop.
Save mundry/8b6dc0374511a84e2471 to your computer and use it in GitHub Desktop.
Web server maintenance configuration for Apache and Nginx.

Web Server Maintenance Configuration

Serves a file maintenance.html for every request while it is present. No need to restart the web server or alter its configuration to switch the site into maintenance mode.

Apache

<Directory /var/www/site>
    Allow from all

    RewriteEngine On
    RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
    RewriteCond %{SCRIPT_FILENAME} !maintenance.html
    # Every request:
    #RewriteRule ^.*$ %{DOCUMENT_ROOT}/maintenance.html [L]
    # Still provide meta data:
    RewriteRule ^(?!(favicon\.(ico|png)$|(robot|human)s\.txt$|sitemap\.xml$)).*$ %{DOCUMENT_ROOT}/maintenance.html [L]
</Directory>

Nginx

location / {
    root       /var/www/site;
    index      index.html;
    try_files  /maintenance.html $uri $uri/index.html $uri.html /fallback/index.html;
}

location ~* ^/(favicon\.(png|ico)|(human|robot)s\.txt|sitemap\.xml)$ {
    root  /var/www/site;
}

Tested with Apache 2.4.6 and Nginx 1.8.0 on CentOS 7.1

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment