Internal marked 503 error page returns default 404

Francis Daly francis at daoine.org
Sat Aug 22 23:54:09 UTC 2015


On Sat, Aug 22, 2015 at 04:31:35AM +0200, Ádám Joó wrote:

Hi there,

> My goal is to have all existing files with the exception of
> unavailable.html served with 200, and serving unavailable.html with
> 503 for anything else and itself.
> 
> The location is marked as internal because otherwise a direct request
> for /unavailable.html would result in a 200. The expectation is that
> on a direct request it would be deemed non-existent by try_files, so a

"selecting the location to handle this request" happens before
try_files. So try_files doesn't get to say whether it exists or not.

> 503 would be issued, and through an internal redirect unavailable.html
> would eventually be served.
> 
> Requesting /unavailable.html, however, results in the default 404
> served, which is, after all, consistent with the documentation, but is
> not what one would expect it to do.

If the expectation is that the documentation is wrong, the expectation
is probably incorrect.

> Can anyone please shed some light on this?

I would probably move unavailable.html out of the "default" document root,
so that it cannot be accessed directly.

Then use a named location, so that a request for /unavailable.html is
the same as a request for /random_filename.html.

  location @unavailable {
    root /tmp;
    try_files /unavailable.html =500;
  }
  try_files $uri =503;
  error_page 503 @unavailable;

The try_files with the "location @" strikes me as inelegant, but seems
to be the quickest way to always serve a single named file. The =500
could be =503, depending on what output you want when your preferred
unavailable.html file is not accessible.

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list