后台修改了 robots.txt,主域名已经更新,其他语言域名仍返回旧内容;或者后台预览正确,公网请求却完全不同。多店铺 robots 的最终响应取决于请求落到哪个 Store、Web Server 是否直接返回静态文件,以及 CDN 是否缓存旧版本。

先建立域名对照表

域名期望 Store Code状态内容哈希
example.com default 200 待测
cn.example.com zh_cn 200 待测
de.example.com de_de 200 待测
for host in example.com cn.example.com de.example.com; do
  curl -sk "https://$host/robots.txt" -o "/tmp/robots-$host.txt"
  sha256sum "/tmp/robots-$host.txt"
done
diff -u /tmp/robots-example.com.txt /tmp/robots-cn.example.com.txt

先明确这些站点是否本来就应该相同。生产与测试环境尤其不能共用允许抓取的 robots。

请求 Host 是否映射到正确 Store

bin/magento store:list
bin/magento config:show web/secure/base_url
nginx -T 2>/dev/null | grep -nE 'server_name|MAGE_RUN_CODE|MAGE_RUN_TYPE' | head -n 100

同一代码库通过 MAGE_RUN_CODE 切换网站时,server block 写错会让 cn 域名一直读取 default scope。后台在中文 Store View 保存,不能修复 Nginx 映射。

静态 robots.txt 是否抢先响应

find . -maxdepth 3 -name robots.txt -ls
curl -skI https://cn.example.com/robots.txt | egrep -i 'age|x-cache|last-modified|etag'
curl -sk --resolve cn.example.com:443:10.0.0.12 https://cn.example.com/robots.txt

Web Server 若在 pub 目录找到实体 robots.txt,可能不会进入 Magento 动态路由。源站新、CDN 旧则刷新这一条 URL,并检查缓存键是否包含 Host。

更新后检查语义

grep -nE '^(User-agent|Allow|Disallow|Sitemap):' /tmp/robots-cn.example.com.txt
curl -skI https://cn.example.com/sitemap.xml

检查 Sitemap 是否使用当前域名,Disallow 是否误封 static、media 或商品路径。robots.txt 不是访问控制,敏感后台路径仍需认证。最后从外部网络请求所有域名并保存响应头与正文,后台预览只能证明数据库值存在。