Repository navigation
Howto Block or slow down crawlers
Goal: decide per client how much it costs to get in — from "nothing" to "no".
All of it is one stock nginx map; the gate only reads the result.
$pow_decision |
Effect |
|---|---|
allow |
pass, no challenge |
deny |
403, no challenge offered |
deny:<status> |
another 4xx/5xx status; deny:444 closes the connection |
challenge |
proof-of-work at pow_gate_difficulty
|
challenge:<N> |
proof-of-work at difficulty N for this client |
challenge:js |
only prove JavaScript runs; no measurable work |
challenge:nojs / challenge:nojs:<secs>
|
wait page without JavaScript (default 2 s, 1–30 s) |
verify:<name> |
verified good bot, else challenge |
An empty or unrecognised value is treated as challenge.
map $http_user_agent $pow_decision {
default challenge; # normal browsers
~*(gptbot|ccbot|bytespider) deny; # declared AI crawlers
~*(python|curl|go-http|scrapy) challenge:2000000; # tools pay 4× more
~*(lynx|w3m|links|elinks) challenge:nojs; # text browsers
~*(googlebot|bingbot) verify:search_engines;
}Things to know:
-
denyonly stops honest bots. A crawler that lies about its User-Agent lands indefaultand is challenged — which is the point of the gate. -
challenge:nojsis the weakest tier. A headless browser simply waits. It is reachable only for clients yourmapsends there; never make it the default. -
A cheaper clearance never unlocks a stricter one. A client cleared at
challenge:jsis challenged again where the policy demands real work.
Any nginx variable can feed the map. By network, with the optional GeoIP2 module (examples/asn-policy.conf):
map "$pow_network_tier:$http_user_agent" $pow_decision {
default challenge;
~*:(gptbot|bytespider|ccbot) deny;
~^elevated: challenge:2000000;
}One signal is rarely enough to act on. Give each a weight, let the module add them up, and decide on the total:
map $http_accept_language $w_no_language { default 0; "" 30; }
map $http_user_agent $w_tool { default 0; ~*(python|curl|scrapy) 40; }
map $pow_gate_score $pow_decision {
default challenge;
"~^\d{3,}$" deny; # 100 and up
~^[5-9]\d$ challenge:2000000; # 50–99
}
location / {
pow_gate on;
pow_gate_weights $w_no_language $w_tool;
pow_gate_decision $pow_decision;
}Negative weights lower the score. A complete include is in examples/scoring.conf.
location /search/ {
pow_gate_policy search;
pow_gate_difficulty 2000000;
pow_gate_endpoint /search/.pow/;
proxy_pass http://backend;
}Give such a location its own pow_gate_endpoint: the endpoint that issues a
clearance must resolve to the same policy and difficulty as the content it
protects.
Ready-made map includes for AI crawlers, search engines and automation tools
are in the repository: Use the bundled rules.
A solved challenge buys a clearance for pow_gate_clearance_ttl. Cap what a
cleared client can do with ordinary limit_req / limit_conn —
examples/regular-traffic-limits.conf
is a complete include that starts in dry-run mode.
Check the effect in the logs: pow=deny,
pow=challenge and the difficulty= each request was given.
map checks exact strings first and then regexes in file order, so list the
stricter patterns above the broader ones.
Getting started
Policy
- Let verified search engines through
- Block or slow down crawlers
- Tune difficulty and clearance lifetime
- Exclude paths and APIs
- Use the bundled rules
- Keep link previews working
Deployment
Operations