nginx屏蔽拒绝user_agent访问网站

定期会查看网站的访问日志

会看到很多的爬虫扫描以及ab测试还有curl

在nginx中有没有办法屏蔽掉呢

我们只需要新建文件

deny_agent.conf

>if ($http_user_agent ~* " SemrushBot|SemrushBot-SA|Bytespider|BLEXBot|CompSpyBot|Exabot|ZoominfoBot|ExtLinksBot|AlphaBot|DotBot|MauiBot|MegaIndex.ru|SiteExplorer|Webdup|AcoonBot|AhrefsBot|Ezooms|EdisterBot|EC2LinkFinder|jikespider|Purebot|MJ12bot|WangIDSpider|WBSearchBot|Wotbox|xbfMozilla|Yottaa|YandexBot|Jorgee|SWEBot|spbot|TurnitinBot-Agent|mail.RU|perl|Python|Wget|Xenu|ZmEu|MSNBot|WinHttpRequest|libssh2|libcurl|curl|ApacheBench") {
return 403;
}

加入网站的配置文件中

`include deny_agent.conf`

重启nginx

>nginx -t
nginx -s reload

即可

    A+
发布日期:2021年04月23日  所属分类:未分类

发表评论

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