You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 fileparameter 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.
try_files
try_files
是 nginx 中http_core
核心模块所带的指令,主要是能替代一些rewrite
的指令,提高解析效率。语法规则
try_files file ... uri
;try_files file ... = code
;含义
file
顺序查找存在的文件,并使用第一个找到的文件进行请求处理root
或alias
为根路径来查找的file
都没有匹配到,则重新请求最后一个参数给定的uri
,就是新的location
匹配= 404
,若给出的file
都没有匹配到,则最后返回404
的响应码例子
比如请求
127.0.0.1/images/test.gif
会依次查找/opt/html/images/test.gif
/opt/html/images/test.gif/
下的index
文件127.0.0.1/images/default.gif
try-files
如果不写上$uri/
,当直接访问一个目录路径时,并不会去匹配目录下的索引页,即访问127.0.0.1/images/
不会去访问127.0.0.1/images/index.html
。The text was updated successfully, but these errors were encountered: