I have a site where requesting a particular JSON file and finding it missing triggers a request for a fallback JSON file. However, rather than getting a 404 for the first file, I was getting the contents of index.html
, which isn't valid JSON and created an error.
I traced the problem to this directive:
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.html;
}
How can I get it to serve a 404
for mysite.com/some/nonexistent/file.json
, but still get index.html
for mysite.com/
?