在server {} 塊中添加下面的配置
location =/robots.txt { default_type text/html; add_header Content-Type "text/plain; charset=UTF-8"; return 200 "User-Agent: *\nDisallow: /"; }
在線測試robots.txt是否生效
https://ziyuan.baidu.com/robots/index
robots.txt文件生產工具:http://tool.chinaz.com/robots/
其他網站參考:
https://www.tmall.com/robots.txt
https://www.jd.com/robots.txt
https://www.qq.com/robots.txt