EUR
european

EUR

usa

USD

Ex. VAT Ex. VAT 0%

How to block AI crawlers with nginx

AI companies and other organizations crawl websites with automated bots. Some of them collect pages for AI model training and web datasets, others fetch pages to answer user questions in AI search. If you do not want your content used for training, or the extra requests put load on your server, you can control these bots at the web server level.

On shared hosting, you usually cannot edit the nginx configuration. On a VPS or dedicated server, you have the server-level access needed to apply these rules directly in nginx without installing additional software.

In this tutorial you will:

  • allow or deny AI bots in robots.txt;
  • block AI training crawlers in nginx by User-Agent with a 403 response;
  • rate-limit AI search bots and return 429 when they exceed the limit;
  • check the result with curl and the nginx logs.

The steps were tested on Ubuntu 26.04 LTS with nginx 1.28.3.

Which AI bots visit your site

AI bots fall into three groups. The group decides how you treat the bot.

Group Bots What they do
Training and data collection GPTBot (OpenAI), ClaudeBot (Anthropic), meta-externalagent (Meta), CCBot (Common Crawl) Collect pages for AI model training; CCBot collects web data for the open Common Crawl dataset
Search OAI-SearchBot (OpenAI), Claude-SearchBot (Anthropic), PerplexityBot (Perplexity) Index pages so the site appears in AI search answers
User requests ChatGPT-User (OpenAI), Claude-User (Anthropic), Perplexity-User (Perplexity) Open a page when a user asks the AI assistant about it

For many sites, a sensible approach is to block training crawlers and allow search bots. Your site signals that its content should not be used for training, while it can still appear in AI search results with a link. OpenAI handles GPTBot and OAI-SearchBot independently, so you can deny one and allow the other. Meta works the same way: blocking meta-externalagent does not cover Meta's other crawlers, such as Meta-WebIndexer for Meta AI search and Meta-ExternalFetcher for user requests.

Info

Google-Extended is not a separate crawler or HTTP User-Agent. It is a robots.txt product token that controls how Google may use crawled content for certain generative AI products. Google-Extended cannot be blocked in nginx by User-Agent, only in robots.txt.

Before you start

You need:

  • a VPS or dedicated server with root or sudo access;
  • access to the server's nginx configuration;
  • nginx as the web server. If it is not installed yet, run:

sudo apt update sudo apt install -y nginx curl

If your site is on shared hosting, you may not have access to the nginx configuration required for Steps 2 and 3. You can still use robots.txt from Step 1.

The commands in this tutorial are for Ubuntu. On other Linux distributions, package commands and nginx configuration paths may differ.

nginx starts automatically after installation. Check that the site responds:

curl -I http://localhost/

The response should have a 200 status code.

In the examples below, the site is the default nginx site: the configuration file is /etc/nginx/sites-available/default and the site root is /var/www/html.

Warning

If your site uses HTTPS or several server blocks, apply the rules to the server block that handles your site's traffic. Do not replace your existing server configuration with the example from this tutorial, only add the lines it shows.

Step 1. Set rules in robots.txt

robots.txt tells compliant crawlers which parts of the site they may crawl. It is a policy signal, not an access control mechanism: a bot that ignores robots.txt can still request the page. That is why the following steps also block bots in nginx.

If your site already has a robots.txt with rules for User-agent: * or other bots, do not replace it. Add the AI bot blocks from the example below to it and merge the rules for User-agent: * into one block.

Create or open the file in the site root:

sudo nano /var/www/html/robots.txt

Add the following content:

# AI training and data collection bots: deny User-agent: GPTBot Disallow: / User-agent: ClaudeBot Disallow: / User-agent: CCBot Disallow: / User-agent: meta-externalagent Disallow: / User-agent: Google-Extended Disallow: / # AI search bots: allow, so the site appears in AI answers User-agent: OAI-SearchBot Allow: / User-agent: Claude-SearchBot Allow: / User-agent: PerplexityBot Allow: / User-agent: * Allow: /

A bot follows the group with its own name, so the specific groups override the general User-agent: * rule for those bots.

Save the file and check that the site serves it:

curl -s http://localhost/robots.txt

Bots do not apply robots.txt changes instantly. OpenAI says it can take about 24 hours for its search results to reflect a robots.txt update.

Warning

Bots that open pages at a user's request behave differently from automatic crawlers. OpenAI says robots.txt rules may not apply to ChatGPT-User, and Perplexity says Perplexity-User generally ignores robots.txt, while Anthropic says its bots, including Claude-User, honor robots.txt directives. Check each provider's current documentation. The rate limit from Step 3 gives you additional server-side control over these bots.

Step 2. Block AI training crawlers in nginx

Create a separate file for the bot rules. On Ubuntu's default nginx setup, files in /etc/nginx/conf.d/ are included inside the http block. The variables and the rate limit zone defined there are available to all server blocks, but the blocking and the rate limit work only in the server and location blocks where you use them.

sudo nano /etc/nginx/conf.d/ai-bots.conf

Add a map that marks requests from training crawlers:

# 1 = block the request, 0 = let it through map $http_user_agent $block_ai_bot { default 0; ~*GPTBot 1; ~*ClaudeBot 1; ~*CCBot 1; ~*meta-externalagent 1; }

The ~* prefix means a case-insensitive match, so the rule works for any User-Agent string that contains the bot name.

Info

User-Agent matching is not authentication. Any client can send a fake User-Agent string. See the Limitations section for how to verify bots by IP address.

Before editing the site configuration, make a backup copy:

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak

Open the site configuration:

sudo nano /etc/nginx/sites-available/default

In the server block, add a separate location for robots.txt and a check in location /:

location = /robots.txt { try_files $uri =404; } location / { if ($block_ai_bot) { return 403; } try_files $uri $uri/ =404; }

The separate location keeps robots.txt accessible, so compliant bots can read the blocking rules before requesting other pages.

The if block with return is a safe pattern in nginx. Do not add other directives inside this if.

Step 3. Rate-limit AI search bots

Search bots and user request bots are allowed on the site, but they can still send many requests in a short time. A rate limit keeps their load under control without permanently blocking them.

Add the following to the end of /etc/nginx/conf.d/ai-bots.conf:

# Limit key: IP address for AI bots, empty string for everyone else (an empty key is not limited) map $http_user_agent $ai_limit_key { default ""; ~*ChatGPT-User $binary_remote_addr; ~*Claude-User $binary_remote_addr; ~*Perplexity-User $binary_remote_addr; ~*PerplexityBot $binary_remote_addr; ~*OAI-SearchBot $binary_remote_addr; ~*Claude-SearchBot $binary_remote_addr; } limit_req_zone $ai_limit_key zone=ai_bots:10m rate=30r/m; limit_req_status 429;

What these lines do:

  • requests from the listed bots get a key equal to their IP address; all other requests get an empty key and are not counted for this rate limit;
  • rate=30r/m sets an average processing rate of 30 requests per minute for each bot IP address;
  • limit_req_status 429 returns 429 Too Many Requests instead of the default 503 when the limit is exceeded.

map and limit_req_zone work only at the http level. Keep them in /etc/nginx/conf.d/ai-bots.conf and do not move them into the server block, or nginx will report an error.

In /etc/nginx/sites-available/default, add the limit_req line to location /. The final server block looks like this:

server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.html index.htm index.nginx-debian.html; server_name _; location = /robots.txt { try_files $uri =404; } location / { limit_req zone=ai_bots burst=5 nodelay; if ($block_ai_bot) { return 403; } try_files $uri $uri/ =404; } }

burst=5 nodelay allows up to 5 requests to exceed the configured rate temporarily, and nodelay processes them immediately. Requests beyond the burst are rejected with 429. This is why the test in Step 4 returns six 200 responses before the 429 responses.

Check the configuration and apply it:

sudo nginx -t sudo systemctl reload nginx

nginx -t should report that the syntax is ok and the test is successful.

Tip

30 requests per minute is only an example. Choose a value based on your site's traffic, page size and server capacity.

Step 4. Verify the configuration with curl

Send requests with different User-Agent strings using curl. The -A option sets the User-Agent, and -w '%{http_code}' prints only the response code.

Training crawlers should get 403 on pages and 200 on robots.txt:

curl -s -o /dev/null -w '%{http_code}\n' -A "GPTBot" http://localhost/ curl -s -o /dev/null -w '%{http_code}\n' -A "GPTBot" http://localhost/robots.txt curl -s -o /dev/null -w '%{http_code}\n' -A "ClaudeBot" http://localhost/ curl -s -o /dev/null -w '%{http_code}\n' -A "ClaudeBot" http://localhost/robots.txt

A regular browser and an allowed search bot should get 200:

curl -s -o /dev/null -w '%{http_code}\n' -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/131.0.0.0" http://localhost/ curl -s -o /dev/null -w '%{http_code}\n' -A "Mozilla/5.0 (compatible; PerplexityBot/1.0; +https://perplexity.ai/perplexitybot)" http://localhost/

Results of the test run:

User-Agent Path Response
GPTBot, ClaudeBot, CCBot, meta-externalagent / 403
GPTBot, ClaudeBot, CCBot, meta-externalagent /robots.txt 200
Regular browser (Chrome) / 200
PerplexityBot / 200

If your site uses HTTPS, repeat the checks against your HTTPS address, for example https://example.com/, and make sure the rules are in the server block that handles HTTPS traffic.

To check the rate limit, send 15 requests in a row as ChatGPT-User, then 15 as a regular browser:

for i in $(seq 1 15); do curl -s -o /dev/null -w '%{http_code} ' -A "ChatGPT-User/1.0" http://localhost/; done; echo for i in $(seq 1 15); do curl -s -o /dev/null -w '%{http_code} ' -A "Mozilla/5.0 Chrome/131.0.0.0" http://localhost/; done; echo

Result:

200 200 200 200 200 200 429 429 429 429 429 429 429 429 429 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200

The bot got 6 successful responses: the first request is accepted within the current rate allowance, and up to five more are accepted within the burst. After that, requests get 429. The browser was not limited.

Step 5. Watch the bots in the logs

The access log shows every request with its User-Agent and response code:

sudo tail -n 20 /var/log/nginx/access.log

Example lines:

::1 - - [...] "GET / HTTP/1.1" 429 178 "-" "...ChatGPT-User/1.0..." ::1 - - [...] "GET / HTTP/1.1" 200 615 "-" "...Chrome/131.0.0.0"

Requests stopped by the rate limit also appear in the error log:

sudo tail -n 20 /var/log/nginx/error.log

[error] 3099#3099: *19 limiting requests, excess: 5.980 by zone "ai_bots", client: ::1, server: _, request: "GET / HTTP/1.1", host: "localhost"

To see which AI bots visit your site and how often, filter the access log by bot name:

sudo grep -iE "GPTBot|ClaudeBot|CCBot|meta-externalagent|OAI-SearchBot|Claude-SearchBot|PerplexityBot|ChatGPT-User|Claude-User|Perplexity-User" /var/log/nginx/access.log

If your server uses a custom log format or a different log path, the output will look different.

Limitations

robots.txt is a policy signal, not an access control mechanism. Blocking by User-Agent in nginx stops only bots that introduce themselves honestly. Any program can send a request with someone else's User-Agent, or with no bot name at all. This configuration does not stop scrapers that do not identify themselves as the blocked bots.

OpenAI, Anthropic and Perplexity publish the IP addresses of their bots as JSON lists:

All three lists have the same format: a prefixes array with ipv4Prefix entries. You can use them to check whether a request with a bot's User-Agent really came from that company. If you use IP-based verification or filtering, check the published lists regularly because they can change.

nginx rules are one layer of protection. For stronger protection against abusive traffic, add firewall or WAF rules and IP-based filtering.

Conclusion

Your site now treats AI bots in different ways. Training crawlers read the ban in robots.txt and get 403 on all other pages. Search bots and user request bots can still visit the site, so your pages can appear in AI answers, but the rate limit keeps their load under control. Requests from regular visitors are not subject to the AI bot rate limit.

All of this needs access to the nginx configuration, which you have on a VPS or dedicated server. With root or sudo access, you decide yourself how your web server treats AI bots and can change the rules as the bots and your traffic change.

VAT

  • Other

    Ex. VAT

    0%
  • austria

    Austria

    20%
  • Belgium

    Belgium

    21%
  • Bulgaria

    Bulgaria

    20%
  • Croatia

    Croatia

    25%
  • Cyprus

    Cyprus

    19%
  • Czech Republic

    Czech Republic

    21%
  • Denmark

    Denmark

    25%
  • Estonia

    Estonia

    22%
  • France

    France

    20%
  • Finland

    Finland

    24%
  • Germany

    Germany

    19%
  • Greece

    Greece

    24%
  • Hungary

    Hungary

    27%
  • Ireland

    Ireland

    23%
  • Italy

    Italy

    22%
  • Latvia

    Latvia

    21%
  • Lithuania

    Lithuania

    21%
  • Luxembourg

    Luxembourg

    17%
  • Malta

    Malta

    18%
  • Netherlands

    Netherlands

    21%
  • Poland

    Poland

    23%
  • Portugal

    Portugal

    23%
  • Romania

    Romania

    19%
  • Slovakia

    Slovakia

    20%
  • Slovenia

    Slovenia

    22%
  • Spain

    Spain

    21%
  • Sweden

    Sweden

    25%
  • USA

    USA

    0%
european
states
  • kingdom
  • germany
  • Español
  • French
  • Italiano
  • Poland
  • ukraine
  • Русский
  • Other
  • Austria
  • Belgium
  • Bulgaria
  • Croatia
  • Cyprus
  • Czech Republic
  • Denmark
  • Estonia
  • Finland
  • France
  • Germany
  • Greece
  • Hungary
  • Ireland
  • Italy
  • Latvia
  • Lithuania
  • Luxembourg
  • Malta
  • Netherlands
  • Poland
  • Portugal
  • Romania
  • Slovakia
  • Slovenia
  • Spain
  • Sweden
  • USA