正则表达式阻止 nginx 中的 url [英] Regex to block url in nginx

查看:39
本文介绍了正则表达式阻止 nginx 中的 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想阻止访问末尾有多余字符的网址.

I want to block access to urls that have excess characters at its end.

例如我希望 nginx 阻止对 https://www.example.com/url-pattern/amp/extra-chars/more-extra

E.g. I want nginx to block requests to https://www.example.com/url-pattern/amp/extra-chars/more-extra

但希望它允许 https://www.example.com/url-pattern/amphttps://www.example.com/url-pattern/amp/

这行得通吗?

location .*\/amp\/. {
   deny all
}

请指导.

推荐答案

自己解决了.如果有人正在寻找相同的解决方案

Solved it myself. If anyone is looking for the same solution

location ~* /amp/. {
 deny all;
}

这篇关于正则表达式阻止 nginx 中的 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆