目的: 每兩秒容許1個來自header頭包含Baiduspider等的爬蟲類請求html
http {nginx
map $http_user_agent $is_limited_bot { "~Baiduspider" 1; "~OtherSpider" 2; default ""; } limit_req_zone $is_limited_bot zone=botzone:10m rate=30r/m; server { ... location / { ... limit_req zone=botzone burst=5; } }
}curl
測試: curl -I http://example.com -A OtherSpideride
Nginx官方文檔:http://nginx.org/en/docs/http/ngx_http_limit_req_module.html
中文相關解釋:http://storysky.blog.51cto.com/628458/642970/測試