【问题标题】:case sensitive/in-sensitive match not working in nginx区分大小写/不区分大小写的匹配在 nginx 中不起作用
【发布时间】:2021-04-19 19:06:47
【问题描述】:

在我的server 指令中,位置配置如下

    location ~ \.(html)$ {
        expires max;
        return 200 "case sensitive match";
    }

    location ~* \.(html)$ {
            expires 10d;
            return 200 "case insensitive match";
    }

我的期望是,当我加载localhost/somthing.html 时,它应该打印case sensitive match,当我加载localhost/something.hTML 时,它应该打印case insensitive match

但是,在这两种情况下,case sensitive match 都会被打印出来

access.log的请求日志是

127.0.0.1 - - [18/Apr/2021:17:56:15 +0530] "GET /something.hTML HTTP/1.1" 200 20 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15"

附加图片,请参阅打印的声明以及设置为MAXexpires,证明case sensitive match 有效。这里可能出了什么问题?

【问题讨论】:

  • nginx在什么操作系统下运行?
  • Mac,大苏尔,11.2.3

标签: nginx nginx-config


【解决方案1】:

location ~ 匹配在具有不区分大小写文件系统的操作系统(例如 Mac OS 和 Windows)下仍然不区分大小写。

要强制使用不区分大小写的模式,您需要使用 (?-i) 将其包含在正则表达式本身中,例如

location ~ "(?-i)\.(html)$" {
    ...
}

this (very old) issue

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-19
    • 1970-01-01
    • 2013-06-20
    • 1970-01-01
    • 1970-01-01
    • 2017-11-14
    • 2012-03-15
    • 1970-01-01
    相关资源
    最近更新 更多