Nginx: When `index` and` try_files` are in the same block, why will `try_files` be processed and not the` index` directive?

nginx.conf is as follows:

http { server { listen 8080; server_name example.com; root /tmp/test/example; location / { index index.html; try_files $uri /test.html; } } } 

When I refer to example.com:8080 , it refers to /tmp/test/example/test.html , not index.html .

+6
source share
1 answer

The try_files directive try_files documented here .

It specifically documents two elements of the file: $uri and $uri/ . The first tests for the presence of normal files, and the second - the presence of directories.

The index directive is called as a result of processing a URI that points to a directory that contains a file that matches one of the directive parameters.

In case of try_files $uri /test.html; the existence of the directory is not verified, and therefore the default action is performed.

In case of try_files $uri $uri/ /test.html; the existence of the directory is checked and, therefore, the index action is performed.

+7
source

All Articles