date: 2018-09-19 21:16:03 +0800 title: “http.nobots”

sitename: “Caddy中文文档”

http.nobots

nobots保护你的网站免受网络爬虫和机器人。

完整文档

示例

通过User-Agent禁止机器人

  1. nobots "bomb.gz" {
  2. "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
  3. "Googlebot/2.1 (+http://www.google.com/bot.html)"
  4. "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
  5. "Googlebot-News"
  6. "Googlebot-Image/1.0"
  7. "Googlebot-Video/1.0"
  8. "compatible; Mediapartners-Google/2.1; +http://www.google.com/bot.html"
  9. "Mediapartners-Google"
  10. "AdsBot-Google (+http://www.google.com/adsbot.html)"
  11. "AdsBot-Google-Mobile-Apps"
  12. "APIs-Google (+https://developers.google.com/webmasters/APIs-Google.html)"
  13. }

它会发送bomb.gz到指令块中列出的Google机器人。

使用正则表达式禁止机器人

  1. nobots "bomb.gz" {
  2. regexp "bingbot"
  3. }

它会发送bomb.gz给所有包含bingbot的用户代理。

混合字符串和正则表达式

  1. nobots "bomb.gz" {
  2. "msnbot-media/1.1 (+http://search.msn.com/msnbot.htm)"
  3. regexp "bingbot"
  4. }

它会发送bomb.gz给所有包含bingbot的用户代理,以及和上面一致的字符串的用户代理。

指定不保护的网址

  1. nobots "bomb.gz" {
  2. "Googlebot"
  3. public "^/public"
  4. public "^/[a-z]{,5}/public"
  5. }

它会发送bomb.gz给user agent为Googlebot,且不是访问public关键字定义的网址的请求。