Maintenance message pages

Alexander Staubo alex at
Mon Aug 6 19:22:42 MSD 2007

We're using Nginx with Mongrel + Rails. Whenever we take the system
down for upgrades or maintenance, we take down all Mongrel processes
and set a flag using a file. The Nginx config looks like this:

  if (-f $document_root/.maintenance) {
    rewrite ^(.*)$ /maintenance.html last;

There are two problems with this approach:

(1) Users who are POSTing forms at the moment when we put up this
message will get a  405 ("Method not allowed") error.

(2) AJAX requests that occur at the same time will get the maintenance
page in its entirety, which is not approriate for inline embeds.

I could solve #1 by using the error_page directive to change the page,
although it's a bit hacky. However, I don't think I can solve #2 using
purely Nginx, as there seems to be no way to check for the existence
of a header, in this case X-Requested-With.

Another option I am considering is to have the maintenance page be
served by a CGI script which simply ignores the method (possibly even
provides a "retry" button for POSTs so that form data can be
re-posted) and provides a slimmed-down version for AJAXed embeds.



More information about the nginx mailing list