nginx设置禁止直接访问robots.txt文件
admin 阅读:43 2024-03-02
很多时候网站的 robots.txt 中包含很多敏感信息,如果直接访问就会泄露这些敏感内容,我们可以在 nginx 中设置禁止用户直接访问 robots.txt 文件,但匹配并排除搜索引擎蜘蛛。
在 nginx 对应站点的配置文件中加入下面的代码即可:
location = /robots.txt {
if ($http_user_agent !~* "spider|bot|yahoo|sogou") {
return 404;
}
}
声明
1、部分文章来源于网络,仅作为参考。 2、如果网站中图片和文字侵犯了您的版权,请联系1943759704@qq.com处理!