网站屏蔽掉无用的蜘蛛,修改robots.txt

做个小网站,天天被搜索引擎乱爬取。

于是写了一份robots,把没用的沙雕蜘蛛全部给屏蔽掉。

这是第一步。

User-agent: DotBot
Disallow: /

User-agent: SemrushBot
Disallow: /

User-agent: SiteAuditBot
Disallow: /

User-agent: SemrushBot-BA
Disallow: /

User-agent: SemrushBot-SI
Disallow: /

User-agent: SemrushBot-SWA
Disallow: /

User-agent: SplitSignalBot
Disallow: /

User-agent: SemrushBot-OCOB
Disallow: /

User-agent: SemrushBot-FT
Disallow: /

User-agent: RyteBot
Disallow: /

User-agent: SemrushBot-ESI
Disallow: /

User-agent: MJ12bot
Disallow: /

User-agent: AhrefsBot
Disallow: /

User-agent: BLEXBot
Disallow: /

User-agent: TrendictionBot
Disallow: /

User-agent: ClaudeBot
Disallow: /

User-agent: Anthropic-ai
Disallow: /

User-agent: GPTBot
Disallow: /

User-agent: Amazonbot
Disallow: /

User-agent: PetalBot
Disallow: /

User-agent: *
Disallow: 
Crawl-delay: 10

第二步,这下沙雕蜘蛛访问我网站,直接返回403.

伪静态的代码,我的是nginx环境。

# 屏蔽冷门爬虫(不遵守 robots.txt 或只采集不贡献流量的)
if ($http_user_agent ~* "(DotBot|SemrushBot|SiteAuditBot|SemrushBot-BA|SemrushBot-SI|SemrushBot-SWA|SplitSignalBot|SemrushBot-OCOB|SemrushBot-FT|RyteBot|SemrushBot-ESI|MJ12bot|AhrefsBot|BLEXBot|TrendictionBot|ClaudeBot|Anthropic-ai|GPTBot|Amazonbot|PetalBot)") {
    return 403;
}

 名单说明

  • DotBot:Moz 的爬虫。

  • Semrush 全家桶:包括主爬虫和各种工具专用的分身(SemrushBotSiteAuditBotSemrushBot-BA 等),一次性全封。

  • MJ12botAhrefsBotBLEXBotTrendictionBot:都是国外知名的 SEO/数据分析爬虫,只采集不送流量。

  • ClaudeBotAnthropic-aiGPTBot:AI 训练爬虫,你之前服务器负载 100% 可能就是它们在狂扫。

  • AmazonbotPetalBot:其他商业爬虫,同样无益。

为什么用 403 而不用 502?

  • 403 Forbidden:明确的“禁止访问”信号,爬虫收到后会知道你不允许,通常会停止抓取。

  • 502 Bad Gateway:表示网关错误,可能让爬虫误以为服务器临时故障,反而会反复重试,加重负担。

© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容