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
相关产品推荐
相关产品推荐

