我有一个网站,请求一个特定的JSON文件,发现它缺less触发一个后备JSON文件的请求。 但是,而不是得到第一个文件的404,我得到的index.html
,这是不是有效的JSON的内容,并创build一个错误。
我把这个问题追溯到这个指令:
location / { # First attempt to serve request as file, then # as directory, then fall back to index.html try_files $uri $uri/ /index.html; }
我怎样才能得到它的mysite.com/some/nonexistent/file.json
404
,但仍然得到index.html
的mysite.com/
?
读了一些之后,我改变了try_files
指令:
# Old way: fallback to index.html try_files $uri $uri/ /index.html; # New way: serve a 404 response try_files $uri $uri/ =404;
另一种select是:
# Fall back to this error page try_files $uri $uri/ error_pages/404.html
我仍然有这个指令来处理为mysite.com/
服务index.html
:
server { # ... index index.html index.html; #... }