Gitea 自建代码仓流量大坑
背景
前端时间租的腾讯云服务器是按照流量计费的,最近一段时间流量走的老快了,并且发现默认1G的带宽老是卡。
原因
通过分析nginx的日志发现有大量的爬虫在大批量的访问代码仓。导致占用了大量带宽。
解决
nginx中过滤爬虫
在nginx中配置下面信息,过滤掉大量爬虫的请求。
if ($http_user_agent ~ "(meta-externalagent|Amazonbot|ClaudeBot|Baiduspider|SemrushBot|bingbot|Bytespider|AhrefsBot|Linguee)" ) {
return 403;
}
if ($http_user_agent ~ "Swiftbot|YandexBot|jikeSpider|MJ12bot|ZmEu phpmyadmin|EasouSpider|YYSpider|jaunty|oBot|FlightDeckReports" ) {
return 403;
}
if ($http_user_agent ~ "(Googlebot|GoogleOther|Java|feedparser|l9explore)" ) {
return 403;
}
修改robots.txt
在gitea的public目录下面新增robots.txt,写入下面内容:
User-agent: *
Disallow: /

0 评论