Implicit root location?

Francis Daly francis at daoine.org
Wed Jul 31 11:54:16 UTC 2019


On Tue, Jul 30, 2019 at 04:20:41PM -0500, J. Lewis Muir wrote:

Hi there,

> I have a minimal nginx.conf with one server block that sets the root
> directory but has *no* location directives, yet for a request of "/", it
> serves "/index.html".  Why?  With no locations specified, I expected it
> to return 404 or similar for any request.

As you've seen: if there is not a best-match location{} for this request;
then nginx uses the server{}-level config. Without other configuration,
that will eventually default to serving from the filesystem with the
defined root directory.

If *that* directory or file is not there, you'll get a 404.

(And there is a compile-time root directory, if you do not set "root"
explicitly.)

In the common case, you want a "location / {}" so that there will always
be a best-match location{}.

Perhaps this "no-location-matched" case could be documented more clearly?

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list