做個小網站,天天被搜索引擎亂爬取。
於是寫了一份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 全家桶:包括主爬蟲和各種工具專用的分身(
SemrushBot、SiteAuditBot、SemrushBot-BA等),一次性全封。MJ12bot、AhrefsBot、BLEXBot、TrendictionBot:都是國外知名的 SEO/數據分析爬蟲,只採集不送流量。
ClaudeBot、Anthropic-ai、GPTBot:AI 訓練爬蟲,你之前服務器負載 100% 可能就是它們在狂掃。
Amazonbot、PetalBot:其他商業爬蟲,同樣無益。
爲什麼用 403 而不用 502?
403 Forbidden:明確的“禁止訪問”信號,爬蟲收到後會知道你不允許,通常會停止抓取。
502 Bad Gateway:表示網關錯誤,可能讓爬蟲誤以爲服務器臨時故障,反而會反覆重試,加重負擔。