美文网首页
nginx location

nginx location

作者: cgausse | 来源:发表于2020-11-10 12:49 被阅读0次

location 路径正则匹配:

image.png

官方解释

location 优先级官方文档

    1.Directives with the = prefix that match the query exactly. If found, searching stops.
    2.All remaining directives with conventional strings, longest match first. If this match used the ^~ prefix, searching stops.
    3.Regular expressions, in order of definition in the configuration file.
    4.If #3 yielded a match, that result is used. Else the match from #2 is used.

    1.=前缀的指令严格匹配这个查询。如果找到,停止搜索。
    2.所有剩下的常规字符串,最长的匹配。如果这个匹配使用^〜前缀,搜索停止。
    3.正则表达式,在配置文件中定义的顺序。
    4.如果第3条规则产生匹配的话,结果被使用。否则,使用第2条规则的结果。
重要点
  • ^~ 和 正则(~ ~*) 都是匹配到后搜索停止,所以需要注意顺序
  • = 精确匹配

建议

  • ^~ 和 正则匹配不要同时使用

引用:https://www.nginx.cn/115.html

相关文章

网友评论

      本文标题:nginx location

      本文链接:https://www.haomeiwen.com/subject/vkxjbktx.html