杰拉斯的博客

nginx 中 location 的匹配规则

杰拉斯 杰拉斯 | 时间:2014-12-24, Wed | 16,463 views
后台技术 

location 匹配规则

=     # 普通字符精确匹配
^~    # 普通字符路径前缀匹配
~     # 区分大小写的正则匹配
~*    # 不区分大小写的正则匹配

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 条规则的匹配结果。

如需转载请注明出处:杰拉斯的博客

当前暂无评论 »