Nginx位置优先级

编程入门 行业动态 更新时间:2024-10-12 05:53:16
本文介绍了Nginx位置优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

位置指令按什么顺序触发?

What order do location directives fire in?

推荐答案

来自 HttpCoreModule文档:

  • 带有"="前缀的指令与查询完全匹配.如果找到,搜索将停止.
  • 所有剩余的带有常规字符串的指令.如果此匹配项使用"^〜"前缀,则会停止搜索.
  • 正则表达式,按照它们在配置文件中定义的顺序.
  • 如果#3匹配,则使用该结果.否则,将使用#2中的匹配项.
  • 文档中的示例:

    location = / { # matches the query / only. [ configuration A ] } location / { # matches any query, since all queries begin with /, but regular # expressions and any longer conventional blocks will be # matched first. [ configuration B ] } location /documents/ { # matches any query beginning with /documents/ and continues searching, # so regular expressions will be checked. This will be matched only if # regular expressions don't find a match. [ configuration C ] } location ^~ /images/ { # matches any query beginning with /images/ and halts searching, # so regular expressions will not be checked. [ configuration D ] } location ~* \.(gif|jpg|jpeg)$ { # matches any request ending in gif, jpg, or jpeg. However, all # requests to the /images/ directory will be handled by # Configuration D. [ configuration E ] }

    如果仍然令人困惑,请此处有较长的解释.

    If it's still confusing, here's a longer explanation.

    更多推荐

    Nginx位置优先级

    本文发布于:2023-11-25 10:31:34,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1629402.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:优先级   位置   Nginx

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!