Regex to block url in nginx

耗尽温柔 提交于 2021-01-29 05:20:40

问题


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

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

but want it to allow https://www.example.com/url-pattern/amp or https://www.example.com/url-pattern/amp/

Will this work?

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

Please guide.


回答1:


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

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


来源:https://stackoverflow.com/questions/62984495/regex-to-block-url-in-nginx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!