屏蔽 AI 训练爬虫最有效的做法是两层同时上:在 robots.txt 里按爬虫名逐个声明 Disallow: /,再在 Nginx 或 CDN 层按 User-Agent 直接返回 403 或断连。只写 robots.txt 等于“贴告示”,守规矩的 OpenAI、Anthropic 会照做,不守规矩的直接无视;真正的拦截必须在服务器层完成。
屏蔽 AI 训练爬虫有哪些常用方法?
结论:按拦截强度从弱到强依次是「robots.txt → Nginx UA 拦截 → CDN/WAF 规则 → IP 段封禁」,前两步覆盖 90% 场景,成本最低,建议一起做。
robots.txt 是爬虫协议约定,由爬虫自行遵守,服务器不会强制执行。Nginx 层拦截是物理拒绝,爬虫拿不到 HTML。CDN/WAF 层拦截的好处是省源站带宽,Cloudflare 在 2024 年 7 月上线了「Block AI bots」一键开关,可直接拦住已知 AI 爬虫及其伪装 UA。IP 段封禁最彻底,但维护成本高——OpenAI 会在 https://openai.com/gptbot.json 公布 GPTBot 的 IP 段,需要定期同步。
robots.txt 怎么写才能屏蔽 GPTBot、CCBot、Bytespider?
结论:robots.txt 里每个 AI 爬虫要单独写一个 User-agent 段,不能用逗号合并;写得越早、越靠前越保险。
把下面内容追加到站点根目录的 robots.txt(如 https://www.gj0.com/robots.txt)最前面:
User-agent: GPTBot
Disallow: /
User-agent: ChatGPT-User
Disallow: /
User-agent: OAI-SearchBot
Disallow: /
User-agent: ClaudeBot
Disallow: /
User-agent: anthropic-ai
Disallow: /
User-agent: CCBot
Disallow: /
User-agent: Bytespider
Disallow: /
User-agent: Amazonbot
Disallow: /
User-agent: meta-externalagent
Disallow: /
User-agent: PerplexityBot
Disallow: /
User-agent: cohere-ai
Disallow: /
User-agent: Google-Extended
Disallow: /
User-agent: Applebot-Extended
Disallow: /
要注意两个例外:Google-Extended 和 Applebot-Extended 是 robots.txt 里的令牌(token),不是真实 User-Agent 字符串,你没法在 Nginx 日志或 UA 里匹配到它们,只能靠 robots.txt 生效。它们分别控制 Google Gemini/Vertex AI 和 Apple 智能的训练用途,屏蔽后不影响 Googlebot 正常抓取和排名。
Nginx 怎么按 User-Agent 拦截 AI 爬虫?
结论:用 map 指令在 http 块里把 UA 映射成变量,再在 server 块里 return 403(或 return 444 直接断连、不返回任何内容),这是最省事且不会误伤真实用户的写法。
在 nginx.conf 的 http { } 里加:
map $http_user_agent $ai_bot {
default 0;
"~*GPTBot" 1;
"~*ChatGPT-User" 1;
"~*OAI-SearchBot" 1;
"~*ClaudeBot" 1;
"~*anthropic-ai" 1;
"~*CCBot" 1;
"~*Bytespider" 1;
"~*Amazonbot" 1;
"~*meta-externalagent" 1;
"~*PerplexityBot" 1;
"~*cohere-ai" 1;
"~*Diffbot" 1;
"~*ImagesiftBot" 1;
}
在对应站点的 server { } 里加:
if ($ai_bot) {
return 403;
}
改完执行 nginx -t 检查语法,再 nginx -s reload 生效。想拦得更狠就把 403 换成 444,爬虫会直接收到连接关闭,连状态码都拿不到,也不会消耗你的 PHP 进程。
怎么验证屏蔽规则真的生效?
结论:用 curl 伪造 UA 请求一次,看返回码是不是 403 或空响应,这是唯一靠谱的验证方式。
curl -A "Mozilla/5.0 (compatible; GPTBot/1.1; +https://openai.com/gptbot)" -I https://www.gj0.com/
返回 HTTP/1.1 403 Forbidden 即拦截成功;返回 200 说明规则没匹配上,检查 map 是否放在了 http 块、~* 是否漏了。
拦截前建议先查日志,确认哪些 AI 爬虫真的来过:
grep -iE "GPTBot|CCBot|Bytespider|ClaudeBot|meta-externalagent" /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -rn
屏蔽 AI 爬虫会影响 SEO 和 AI 搜索流量吗?
结论:屏蔽训练型爬虫不影响传统搜索排名,但会降低你在 AI 搜索里的被引用概率,需要按业务取舍。
GPTBot、CCBot、ClaudeBot 收集的是训练语料,和 Googlebot、Bingbot 的抓取排名是两条链路,屏蔽它们不会让你的百度、Google 排名掉。但 CCBot 是 Common Crawl 的数据源,很多 AI 检索和二次数据服务都基于它;屏蔽后你大概率不会出现在 ChatGPT、Perplexity 的引用答案里。
如果你的目标是「被 AI 搜索收录并引用」而不是「防训练」,思路要反过来:保留 OAI-SearchBot、PerplexityBot 这类检索型爬虫,只封训练型爬虫,同时补充 llms.txt、结构化数据和问答聚合内容。站内的 GEO 版块专门讨论这些配置和监测方法,站长交流版块也有 Nginx 层面的防护排错帖,可以对照自己的日志再决定封哪些。
收个尾:robots.txt 负责表态、Nginx map 负责执行,两条一起上才算真屏蔽;Google-Extended、Applebot-Extended 只能靠 robots.txt,验证一律用 curl -A 打一次看返回码。封之前先看日志,别把检索型爬虫一起封掉,否则你丢的不是训练数据,是 AI 搜索的入口流量。