I’m working on setting up a maintenance page, and I can’t figure out
where Nginx is looking for the maintenance.html that I have specified.
I’ve tried placing the file in a lot of different locations, but I still
get the generic “503 Service Temporarily Unavailable” page.
My question is, is there a way I can get Nginx to display it’s
configuration at run-time, so perhaps I can determine where it is
looking for the file?
Jim O.
On Apr 16, 2012 5:15 PM, “michael_teter” [email protected] wrote:
Howdy.
I’m working on setting up a maintenance page, and I can’t figure out
where Nginx is looking for the maintenance.html that I have specified.
I’ve tried placing the file in a lot of different locations, but I still
get the generic “503 Service Temporarily Unavailable” page.
then nginx will look for maintenance.html in the root directory and
serve
it if it’s present.
So to put our sites into maintenance mode, we simply copy our
maintenance.html into the root directory. No need to reload nginx. When
we’re ready to go back up, the file is removed.
My question is, is there a way I can get Nginx to display it’s
configuration at run-time, so perhaps I can determine where it is
looking for the file?
I have tried a variety of paths.
/maintenance.html
$document_root/maintenance.html
/some/other/path/maintenance.html
etc.
I don’t understand how Nginx can see the stop.txt that I use to put it
in maint mode, but it can’t see (or ignores)
$document_root/maintenance.html (when I had that set as the error_page)
Why are you not using this line? It’s the perfect use case for
“try_files”.
Note that I believe that you should remove the leading “/” from
“/maintenance.html”.
On Mon, Apr 16, 2012 at 06:02:45PM -0400, michael_teter wrote:
Hi there,
My error log shows nothing, but my
access log does show the visit.
The error log doesn’t seem immediately useful in this case; but with
the debug log you can work out what is happening.
The short answer is “internal redirect”, or “subrequest”.
Here’s the relevant part of my config:
error_page 503 /maintenance.html;
if (-f $document_root/../tmp/stop.txt) {
set $maintenance 1;
}
if ($maintenance) {
return 503;
}
For any request, if the file exists then return 503, which does an
internal redirect to /maintenance.html. This subrequest goes through the
same process, and since the file still exists, you would end up in a
loop.
With the following config, you can break out of the loop:
error_page 503 /maintenance.html;
if ($uri = "/maintenance.html") {
break;
}
if (-f $document_root/../tmp/stop.txt) {
return 503;
}
Although I confess I don’t know if there is a “best” way to implement
a 503 response to all requests in nginx based on the existence of a
flag file.