You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Shopware多域名场景下配置Nginx实现各域名对应独立robots.txt

两个Shopware站点配置独立robots.txt的Nginx实现方案

前置准备

在Shopware的public目录下创建两个独立的robots配置文件,避免覆盖原有共用的robots.txt:

  • robots.domainA.txt(适配正式上线的domainA,允许搜索引擎收录):
User-agent: *
Allow: /
Sitemap: https://domainA.com/sitemap.xml
  • robots.domainB.txt(适配需要隐藏的domainB,禁止所有搜索引擎收录):
User-agent: *
Disallow: /

修改Nginx站点配置

编辑domainA.conf

在domainA对应的server配置块内添加如下规则,指定robots.txt的返回内容:

location = /robots.txt {
    # 请替换为你实际的Shopware public目录绝对路径
    alias /www/shopware/public/robots.domainA.txt;
    expires 1h;
    add_header Content-Type text/plain;
}

编辑domainB.conf

在domainB对应的server配置块内添加如下规则:

location = /robots.txt {
    # 请替换为你实际的Shopware public目录绝对路径
    alias /www/shopware/public/robots.domainB.txt;
    expires 1h;
    add_header Content-Type text/plain;
}

可选简化方案:如果不想维护额外的配置文件,可直接在location块内返回robots内容,以domainB为例:

location = /robots.txt {
    return 200 "User-agent: *\nDisallow: /\n";
    add_header Content-Type text/plain;
}

生效配置

  • 执行nginx -t验证配置语法是否正确,确认返回syntax is ok、test is successful
  • 执行nginx -s reload或对应系统的Nginx重载命令使配置生效

验证效果

分别访问https://domainA.com/robots.txt和https://domainB.com/robots.txt,确认返回的内容和预期一致即可。

内容的提问来源于stack exchange,提问作者JohannesH

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 22:27:05