【问题标题】:Matching nginx locations starting with letter i匹配以字母 i 开头的 nginx 位置
【发布时间】:2018-05-13 17:00:12
【问题描述】:

我遇到了以“i”开头的位置块的问题。

请求“/”不匹配以下位置块(这是预期的结果)

location /h {
    return 302 /redirect-for-testing-purposes ;
}

但是这个以“i”开头的另一个是通过请求“/”来匹配的

location /i {
    return 302 /redirect-for-testing-purposes ;
}

请注意,此行为仅发生在字母“i”中,您可以使用以下位置块对其进行测试:

请求“/”将不会匹配此位置块

location ~* ^/([a-h]|[j-z]) {
    return 302 /redirect-for-testing-purposes ;
}

这会

location ~* ^/[a-z] {
    return 302 /redirect-for-testing-purposes ;
}

这里发生了什么我无法弄清楚的事情? 谢谢。

nginx 版本:1.14.0 和 1.12.1

【问题讨论】:

    标签: nginx nginx-location


    【解决方案1】:

    i也是index.html的首字母。

    当您访问像 / 这样的 URI 时,index 指令会在内部将 URI 重写为 /index.html

    内部重写后,nginx 将开始再次搜索匹配的 location 块并找到您的 location /i 块。

    请参阅this document 了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-10
      • 2012-01-22
      相关资源
      最近更新 更多