Sub topic 11
Enforcing Blocks on the Server and Verifying Crawlers
This chapter assumes you can write and test a robots.txt file, which the earlier chapters cover. It also assumes you can read an nginx configuration and a combined-format access log, and run short Python scripts. You will learn to enforce a block at the web server, to check whether a request that claims to be a crawler really is one, and to avoid several mistakes that quietly undo your policy.
Why enforcement is a separate step
robots.txt is a request. A well-behaved crawler reads it and complies. A crawler that ignores it still receives your pages unless the server refuses to send them. Server-side enforcement fills that gap. It does so in two ways:
- Refuse by claimed identity. The server looks at the
User-Agentheader and returns an error to names you have decided to block. - Verify real identity. The server, or your log analysis, checks whether the connecting IP address belongs to the operator the user agent claims.
The User-Agent header is text the client chooses. Anyone can send GPTBot in it, and anyone can send a browser string instead. A user-agent block therefore stops only crawlers that are honest about their name. In that sense it is a stronger form of robots.txt: it works on honest crawlers that ignore the file. It does not stop a determined scraper.
Some tokens cannot be blocked on the server
Not every name in your robots.txt appears in requests. Google-Extended and Applebot-Extended are robots.txt control tokens only. Google and Apple fetch the pages with their ordinary crawlers (Googlebot and Applebot) and then use your token to decide whether the content may feed AI training. No request ever arrives with a Google-Extended user agent, so a server rule matching that string never fires.
For these two, robots.txt is the only control. A server-level block would have to target Googlebot or Applebot themselves, which would remove you from search results. Don't do that to enforce a training opt-out.
The crawlers that do send their own user agent, and so can be matched on the server, include GPTBot, OAI-SearchBot, ChatGPT-User, ClaudeBot, PerplexityBot, and CCBot.
Blocking by user agent in nginx
The map below sets a flag when the User-Agent contains a listed token. A location / block then returns 403 when the flag is set.
# In the http block
map $http_user_agent $block_ai_crawler {
default 0;
~*GPTBot 1;
~*ClaudeBot 1;
~*CCBot 1;
}
server {
listen 80;
server_name example.com;
root /var/www/html;
# Always let crawlers read the rules
location = /robots.txt {
try_files $uri =404;
}
location / {
if ($block_ai_crawler) {
return 403;
}
try_files $uri $uri/ =404;
}
}Three details matter here.
- Case-insensitive matching. The
~*prefix makes the regular expression case-insensitive. Operators sometimes change the capitalization or add version numbers, such asGPTBot/1.1, so match the token rather than the whole string. - Keep robots.txt reachable. The exact-match
location = /robots.txthas priority overlocation /, so blocked crawlers can still read your rules. Crawlers generally treat a 4xx response for robots.txt as "no restrictions". If you returned 403 for that file, you would remove your own opt-out and your Disallow lines would stop working. ifinsidelocation. Usingiffor a plainreturnis one of the safe uses of nginx'sifdirective. Avoid putting other directives inside it.
After editing, run nginx -t to check the syntax, reload the service, and test with a spoofed header:
# Should print 403
curl -s -o /dev/null -w "%{http_code}\n" -A "Mozilla/5.0 (compatible; GPTBot/1.1)" https://example.com/articles/guide
# Should print 200
curl -s -o /dev/null -w "%{http_code}\n" -A "Mozilla/5.0" https://example.com/articles/guide
# Should print 200 even for the blocked agent
curl -s -o /dev/null -w "%{http_code}\n" -A "GPTBot" https://example.com/robots.txtBlocking user-initiated fetchers
ChatGPT-User fetches a page when a person asks ChatGPT to open it. OpenAI notes that robots.txt rules may not apply to actions a user starts, so a robots.txt Disallow for this agent is not a dependable control. If your policy is to refuse these fetches, enforce it on the server by adding ~*ChatGPT-User 1; to the map.
This is a policy choice. A person who asked the assistant to read your page then gets an error instead of your content. Decide it on purpose.
Verifying that a crawler is who it says
A user agent proves nothing. Two kinds of verification work, depending on what the operator publishes.
- Published IP ranges. OpenAI publishes JSON lists of address ranges for GPTBot, OAI-SearchBot, and ChatGPT-User. A request that claims to be GPTBot from an address outside the GPTBot list is an imitation.
- Reverse and forward DNS. Google documents a two-step check for Googlebot. Look up the hostname for the connecting IP, confirm it ends in
googlebot.comorgoogle.com, then resolve that hostname and confirm it returns the original IP. The forward step is needed because anyone who controls the reverse DNS for their own address can make it say anything.
The DNS check from a shell looks like this:
# Step 1: reverse lookup of the connecting IP
host 66.249.66.1
# 1.66.249.66.in-addr.arpa domain name pointer crawl-66-249-66-1.googlebot.com.
# Step 2: forward lookup of that hostname must return the same IP
host crawl-66-249-66-1.googlebot.com
# crawl-66-249-66-1.googlebot.com has address 66.249.66.1For the published-range method, here is a Python script that loads a list of prefixes and classifies log lines. It embeds a small sample list so it runs as shown. The addresses come from ranges reserved for documentation (192.0.2.0/24 and 2001:db8::/32). In real use, download the current file from the operator and pass its contents in.
import ipaddress
import json
SAMPLE_RANGES = '{"prefixes": [{"ipv4Prefix": "192.0.2.0/24"}, {"ipv6Prefix": "2001:db8::/32"}]}'
LOG_LINES = [
'192.0.2.10 - - [29/Nov/2026:09:00:01 +0000] "GET /a HTTP/1.1" 200 512 "-" "Mozilla/5.0; compatible; GPTBot/1.1"',
'203.0.113.5 - - [29/Nov/2026:09:00:02 +0000] "GET /b HTTP/1.1" 200 734 "-" "Mozilla/5.0; compatible; GPTBot/1.1"',
'203.0.113.9 - - [29/Nov/2026:09:00:03 +0000] "GET /c HTTP/1.1" 200 201 "-" "Mozilla/5.0 (Windows NT 10.0)"',
]
def load_networks(raw):
networks = []
for entry in json.loads(raw)["prefixes"]:
prefix = entry.get("ipv4Prefix") or entry.get("ipv6Prefix")
if prefix:
networks.append(ipaddress.ip_network(prefix))
return networks
def is_listed(ip_text, networks):
ip = ipaddress.ip_address(ip_text)
return any(ip in net for net in networks)
networks = load_networks(SAMPLE_RANGES)
for line in LOG_LINES:
ip = line.split(" ", 1)[0]
if "GPTBot" not in line:
continue
verdict = "verified" if is_listed(ip, networks) else "SPOOFED"
print(ip, verdict)
# 192.0.2.10 verified
# 203.0.113.5 SPOOFEDThe IP lists change over time, so fetch and cache the file on a schedule instead of copying addresses into your configuration once.
What to do with a spoofed request
You have several options, and the right one depends on cost and risk:
- Log and ignore. A fake GPTBot gains nothing more than any anonymous visitor would. If your pages are public, this is often enough.
- Block the address. Add the offending IP or range to a deny list. This works until the scraper changes address.
- Challenge or rate-limit. A web application firewall or CDN can throttle traffic that claims to be a bot but fails verification.
- Allow only verified crawlers. For a crawler you want, such as a search bot, accept the user agent only when the IP is on the published list. Imitators that would otherwise get the same access are refused.
The last option needs the IP lists inside the server layer. In nginx, a geo block can hold the ranges, and a map can combine its result with the user agent. Many sites do this at the CDN instead, where bot verification is built in.
Correction: use the required diagram fence format.
Common mistakes
- Blocking robots.txt itself. A blanket 403 on every path for a blocked agent hides your rules, as described above.
- Targeting a token that never appears. A rule for
Google-Extendedin nginx matches nothing. Check your access log to see which names really appear before writing a rule. - Matching too loosely. A pattern such as
~*botblocks search engines and monitoring tools along with the AI crawlers. Match specific tokens. - Blocking an agent your robots.txt allows. If robots.txt allows OAI-SearchBot for AI search visibility but the server map returns 403 for it, the file says yes while the server says no. Keep the two layers consistent with your policy.
- Trusting IP lists without refreshing them. Operators add and remove ranges. A stale list will reject real crawlers.
- Caching the 403. If a CDN caches the error response without varying on
User-Agent, ordinary visitors may receive the 403. Test through the CDN as well as the origin.
Summary table
| Control | Stops honest crawlers | Stops crawlers that ignore robots.txt | Stops spoofed user agents |
|---|---|---|---|
| robots.txt | Yes | No | No |
| User-agent block on the server | Yes | Yes, if they send their real name | No |
| IP range or DNS verification | Yes | Yes | Yes, for operators that publish ranges |
| Authentication | Yes | Yes | Yes |
Exercise
Your robots.txt disallows GPTBot, and your access log still shows requests with "GPTBot" in the user agent. You check them against OpenAI's published GPTBot ranges and none of the source IPs is listed. What does this tell you, and what is one reasonable response?
Show answer
The requests are almost certainly not from OpenAI. Someone is sending the GPTBot name without using OpenAI's addresses, so robots.txt compliance is not the issue. Reasonable responses include returning 403 for the GPTBot user agent on the server, blocking or rate-limiting the offending addresses, or simply logging them if your pages are public anyway.
Exercise
A teammate adds ~*Google-Extended 1; to the nginx map to stop Google using the site for AI training. Why will this have no effect, and where should the control go instead?
Show answer
Google-Extended is a robots.txt token, not a user agent. Google fetches pages with its normal Googlebot user agent, so no request contains the string "Google-Extended" and the map never matches. The control belongs in robots.txt, in a User-agent: Google-Extended group with the Disallow rules you want.