A Nginx Maintenance Configuration That Works


nginx maintenanceWe use the lightening fast Nginx web server to handle our mightyvites.com requests. Like most sites we need to go offline once in awhile to deploy new code, address server issues, etc. When we take the main site down we start a single-page website that gives the obligatory “down for maintenance” message. Recently I updated the configuration file for this maintenance site so that it worked properly. By properly I mean all incoming requests get the maintenance page and are returned a HTTP 503 “Service Unavailable.”

Simple enough, right? A pretty common need. I thought it would be easy to find an example online that I could use. Turns out there are tons of examples, but few work! It took me awhile but I eventually cobbled together a useable config.

server {
  listen 80;
  server_name localhost;
  root /var/www/maintenance;
  error_page 503 /index.html;
  location /index.html {
    # show page
  }
  location / {
    return 503;
  }
}

Dead simple once you get it. Every incoming request is served index.html (the maintenance page) and receives a 503 status code. This works with Nginx 0.7.65.

Incoming search terms:

  • nginx maintenance page
  • nginx maintenance
  • nginx down for maintenance
  • maintenance page nginx
  • nginx maintenance message
  • nginx offline page
  • nginx maintenance config
  • maintenance nginx
  • message de maintenance avec nginx
  • mightyvites examples

Leave a Reply