try_files
- 语法:try_files file … uri;或 try_files file … = code;
- 作用域:server location
- 语法解释:
官方:Checks the existence of files in the specified order and uses the first found file for request processing; the processing is performed in the current context. The path to a file is constructed from the *file*parameter according to the root and alias directives. It is possible to check directory’s existence by specifying a slash at the end of a name, e.g. “$uri/”. If none of the files were found, an internal redirect to the *uri* specified in the last parameter is made.
- 翻译:
首先:按照指定的顺序检查文件是否存在,并使用第一个找到的文件进行请求处理
其次:处理是在当前上下文中执行的。根据 root 和 alias 指令从 file 参数构造文件路径。
然后:可以通过在名称末尾指定一个斜杠来检查目录的存在,例如“ $uri/”。
最后:如果没有找到任何文件,则进行内部重定向到最后一个参数中指定的 uri。
自己理解的:按顺序检查文件是否存在,返回第