26人参与 • 2025-10-10 • Linux
主要是能替代一些rewrite的指令,提高解析效率。
官网的文档为module ngx_http_core_module
可应用的上下文: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
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 theurispecified in the last parameter is made
location /images/ {
root /opt/html/;
try_files $uri $uri/ /images/default.gif;
}比如 请求 127.0.0.1/images/test.gif 会依次查找
try-files 如果不写上 $uri/,当直接访问一个目录路径时,并不会去匹配目录下的索引页 即 访问127.0.0.1/images/ 不会去访问 127.0.0.1/images/index.html
location / {
try_files /system/maintenance.html
$uri $uri/index.html $uri.html
@mongrel;
}
location @mongrel {
proxy_pass http://mongrel;
}以上中若未找到给定顺序的文件,则将会交给location @mongrel处理(相当于匹配到了@mongrel来匹配)
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
您想发表意见!!点此发布评论
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论