问题描述
我们有些服务仅供内部使用,但是可以通过公网访问。
我们希望可以屏蔽所有的搜索引擎
该笔记将记录:如何调整 Nginx 配置,以屏蔽所有的搜索引擎机器人。
解决方案
操作系统:Ubuntu 18.04.2 LTS(各种发行版的目录结构存在差异,请根据场景进行调整)
配置 robots.txt 文件:
# 创建配置文件 mkdir /etc/nginx/conf.d/common echo 'location = /robots.txt { return 200 "User-agent: *\nDisallow: /\n"; }' \ > /etc/nginx/conf.d/common/block-all-robots.conf # 引用配置 server { ... include /etc/nginx/conf.d/common/block-all-robots.conf; ... }
参考文献
The Web Robots Pages
Robots.txt File [2021 Examples] - Moz
How to set robots.txt globally in nginx for all virtual hosts - Server Fault