Sub topic 11
Enforcing Blocks on the Server and Verifying Crawlers
Assume you understand HTTP requests, the User-Agent header, basic web-server configuration, and how to read access logs. This chapter builds on robots.txt and explains what to do when a crawler ignores it.
Why server enforcement is needed
robots.txt is an advisory policy. A well-behaved crawler reads the file and follows its rules. Your web server still delivers the page if a different client requests it. A malicious client can also ignore the file completely.
Server enforcement checks a request before the application serves the response. Common enforcement points are:
- A web server such as nginx or Apache.
- A content delivery network (CDN).
- A web application firewall (WAF).
- Application middleware.
A server can return 403 Forbidden, rate-limit a client, or send the request to a review system. Blocking by User-Agent is easy, but it is not strong authentication because any client can copy another crawler's text.
Block named user agents with nginx
The following nginx configuration blocks requests whose User-Agent contains a listed token. Put the map in the http block. Put the if in the relevant server block.
# In the http block
map $http_user_agent $block_ai_crawler {
default 0;
~*GPTBot 1;
~*ClaudeBot 1;
~*CCBot 1;
~*Applebot-Extended 1;
}
# In the server block
if ($block_ai_crawler) {
return 403;
}The ~* operator performs a case-insensitive regular-expression match. The configuration blocks only the named tokens. It does not prove that the request came from the organization associated with that token.
You can also block paths instead of an entire host. For example, an internal members area might reject matching requests while public documentation remains available. Apply the narrowest rule that meets your policy.
Verify crawler identity
Use several signals when identity matters:
| Signal | What it tells you | Main weakness |
|---|---|---|
| User-Agent token | What the client claims to be | Easy to spoof |
| Source IP address | Where the connection came from | Proxies and published ranges change |
| Reverse DNS | A hostname associated with the IP | DNS alone is not proof |
| Forward DNS | Whether that hostname resolves back to the IP | Requires careful validation |
For an important allowlist, obtain the provider's current published IP ranges or verification method. Do not copy an IP range from an old blog post. If reverse DNS is used, resolve the client IP to a hostname, then resolve that hostname back to an address and confirm the original IP is included. Treat a failed or changed check as unverified.
Place this verification at the edge when possible. A CDN or WAF can inspect the connecting address before traffic reaches the origin. If a proxy sits in front of nginx, configure trusted proxy addresses correctly. Never trust an arbitrary X-Forwarded-For header from the public internet.
Monitor the result
A block is useful only if you can see whether it works. Log the timestamp, request path, status code, source IP, and User-Agent. Compare requests from named crawlers before and after deployment.
grep -Ei 'GPTBot|OAI-SearchBot|ChatGPT-User|ClaudeBot|PerplexityBot|CCBot|Applebot-Extended' access.log \
| awk '{print $1, $7, $9, $12}' \
| sort | uniq -c | sort -rnThe exact field positions depend on your log format. Confirm them with one raw log line before relying on this command. A 403 response shows that your rule matched. It does not prove that every request from that organization was identified correctly.
Exercise
Why is a User-Agent-only block insufficient for high-confidence crawler verification?
Show answer
A client can send a different or copied User-Agent. Stronger verification also checks the source IP and, where appropriate, the provider's documented IP ranges or verification process.