【摘自张宴的"实战:Nginx"】try_files指令

语法:try_files param1 [param2...paramN] fallback

默认值:none

使用环境: location

该指令用于告诉nginx测试每个文件是否存在,并且使用首先找到的文件作为URI,如果没有找到指定文件,则调用location fallback ("fallback"可以用任何名称).

fallback是一个请求参数,它可以是任何命名的location,也可以是任何可能的URI

location / {
root /data/source;
#index index.html index.htm;
try_files index.html index.htm @fallback;
#autoindex on;
}

location @fallback{
root /data/test;
index index.html;
}

原文地址:https://www.cnblogs.com/maxomnis/p/5542348.html