Nginx try_files not working for default index.html Nginx try_files not working for default index.html nginx nginx

Nginx try_files not working for default index.html


The last element of the try_files statement is the default action, which is either a URI or a response code. The /index.html starts a search for a new location to process the request, and ends up back at the start, so you have a redirection loop.

You can fix the problem by making /index.html a file term instead. For example:

try_files /$geoip_country_code/index.html /index.html =404;

The =404 is never actioned, because /index.html always exists.

Personally, I would use a generic solution:

try_files /$geoip_country_code$uri $uri /index.html;

See this document for more.