When otherwise unspecified, the index
directive has an implied default of index.html
. Which is present in your document root. (See the documentation below that I included detailing defaults and such)
If you want to change what it serves as its index page, you need to define a new index
directive, such that you add this to your /
location block, or apply it globally by just putting it outside the location blocks but still within your server block:
index nginx.html;
This tells nginx to instead look for a different index file.
The problem you're seeing is because the /
location block only applies if you have the / specified, and because you don't allow autoindex
and because /whatever
is your URI and that doesn't exist either as a file or a directory, it falls back to your third option, the nginx.html
file. I know this is counter-intuitive, as an empty URI or a /
URI typically means "Process this per the location / { }
block, but it's more implied in the world that this takes you to the home or index page of a given website, and that is why the index
directive exists.
You need to tell the system what to treat as an index file for any configuration. You can't rely solely on try_files
in your /
location block, you have to tell it what your index file should be. I always define this even if the defaults work fine for me.
Note that if you don't define a URI, try_files
falls back to the index
directive, so a request to http://foobarbaz.foo:8510
will reach the nginx server block listening on port 8510 for the server name / $HOST
request record of foobarbaz.foo
, with an empty URI, and is technically going to have nginx, internally, try and serve the default index.html
index page because of your configuration not specifying a different index
to serve for any type of request.
From the related nginx documentation of the index
directive:
Syntax: index
file ...;
Default: index index.html;
Context: http, server, location
Defines files that will be used as an index. The file name can contain
variables. Files are checked in the specified order. The last element
of the list can be a file with an absolute path. Example:
index index.$geo.html index.0.html /index.html;
It should be noted that using an index file causes an internal
redirect, and the request can be processed in a different location.
For example, with the following configuration:
location = / {
index index.html;
}
location / {
...
}
... a “/” request will actually be processed in the second location as
“/index.html”.