如何在nginx中阻止包含单词’admin’的任何URL?

huangapple go评论63阅读模式
英文:

How to block any url contain word 'admin' in nginx?

问题

I want block any URL contain word 'author' in nginx.

Like:

exmaple.com/author/exmple....
exmaple.com/?author=2/exmple....
exmaple.com/?author=4
exmaple.com/blog/?author=1
exmaple.com/blog/author/wellcome
.
.
.

I use below code then restart nginx but not work for all URL.

location ~ author{
deny all;
}

How can I do?

我想在nginx中阻止包含'author'单词的任何URL。

像这样:

exmaple.com/author/exmple....
exmaple.com/?author=2/exmple....
exmaple.com/?author=4
exmaple.com/blog/?author=1
exmaple.com/blog/author/wellcome


我使用以下代码然后重启nginx,但不适用于所有URL。

位置 ~作者{
拒绝所有;
}

我该怎么做?

英文:

I want block any URL contain word 'author' in nginx.

Like:

exmaple.com/author/exmple....
exmaple.com/?author=2/exmple....
exmaple.com/?author=4
exmaple.com/blog/?author=1
exmaple.com/blog/author/wellcome
.
.
.

I use below code then restart nginx but not work for all URL.

location ~ author{
 deny all;
}

How can I do?

答案1

得分: 0

I use 2 rule:

for below url:

www.exmaple.com/author/exmple....
www.exmaple.com/blog/author/wellcome

I use:

location ~ author{
return 403;
}

And for below url :

www.exmaple.com/?author=2/exmple....
www.exmaple.com/?author=4
www.exmaple.com/blog/?author=1

I use

if ($request_uri ~* author ) {
return 403;
}

英文:

I use 2 rule :

for below url:

www.exmaple.com/author/exmple....
www.exmaple.com/blog/author/wellcome

I use:

location ~ author{
return 403;
}

And for below url :

www.exmaple.com/?author=2/exmple....
www.exmaple.com/?author=4
www.exmaple.com/blog/?author=1

I use

  if ($request_uri  ~* author ) {
        return 403;
    }

huangapple
  • 本文由 发表于 2023年5月20日 20:59:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76295358.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定