【问题标题】:Rewrite Rule in Nginx to Block a Specific URL在 Nginx 中重写规则以阻止特定 URL
【发布时间】:2012-07-23 12:37:23
【问题描述】:

我想阻止特定 URL 被访问并返回 444 错误。

例子:

if ( $request_uri ~ https://subdomain.domain.com/abc/xyzdirector/login.do ) {
return    444;
}

现在这工作正常,问题是如果我在浏览器中键入以下 URL 并更改子目录中的任何大小写,它都不起作用:

例子:

https://subdomain.domain.com/ABC/xyzdirector/login.d
https://subdomain.domain.com/abc/XYZdirector/login.d
https://subdomain.domain.com/abc/xyzdirecTOR/login.d
https://subdomain.domain.com/Abc/XyzDirector/login.d

当我这样做时,url 会被转发和服务器。

如何阻止这个?

【问题讨论】:

    标签: nginx rewrite reverse-proxy


    【解决方案1】:

    你想要一个不区分大小写的regex location

    location ~* ^/abc/xyzdirector/login\.do$ {
      return 444;
    }
    

    如果您的配置中有任何其他正则表达式位置,请确保将其放在可能匹配此 url 的任何其他位置之上。

    【讨论】:

    • 感谢您的回答。这是完美的,就像一个魅力。抱歉回复晚了。
    猜你喜欢
    • 2018-07-14
    • 2013-10-12
    • 1970-01-01
    • 2015-10-23
    • 1970-01-01
    • 1970-01-01
    • 2017-05-28
    • 2018-12-02
    • 2017-03-13
    相关资源
    最近更新 更多