NodexVPS
Deploy VPS
Linux Guides10 min read

How to Block AI Crawlers That Overload Your Server (Nginx, Apache and robots.txt)

CPU at 100% and hardly any visitors? AI crawlers may be reading your whole site. Here's how to find them in your access log, decide which bots to allow, and block or slow down the rest with robots.txt, Nginx, Apache and fail2ban without hurting your Google rankings.

NodexVPS Team
A server under a swarm of bot icons, with a shield letting only a few through and a green check mark

The graph makes no sense. CPU sits at 100% at three in the morning, the site feels sluggish, and your analytics say you had a few dozen visitors all night. Then you open the access log and find the real crowd: thousands of requests from GPTBot, Bytespider, ClaudeBot, Meta-ExternalAgent and a few names you've never seen, reading every page, every tag archive and every search result your site can produce.

That's AI crawlers at work. They collect web pages to train language models and to answer questions in AI chat and search tools. Many behave well. Some don't, and on a small server even the polite ones can eat a surprising share of your CPU and bandwidth.

This guide isn't about blocking AI on principle. It's about getting your server back under control: find out which bots are really hitting you, decide which ones you want, and then block or slow down the rest with robots.txt, Nginx or Apache, and fail2ban, without hurting your Google rankings.

Step 1: Find Out Who Is Really Visiting

Don't block anything yet. First see what the log says. This lists the 20 busiest user agents in your Nginx access log:

sudo awk -F'"' '{print $6}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -20

On Apache, use /var/log/apache2/access.log instead. Both use the same log format by default, so the command works on either. To see how much of today's traffic comes from well-known AI crawlers:

sudo grep -ciE 'gptbot|claudebot|ccbot|bytespider|meta-externalagent|amazonbot|perplexitybot' /var/log/nginx/access.log
sudo wc -l < /var/log/nginx/access.log

The first number is the AI crawler requests, the second is all requests. Requests aren't the whole story, though. A bot that downloads your images and PDFs costs more than one that reads small pages. This adds up the bytes sent to each user agent:

sudo awk -F'"' '{split($3, a, " "); bytes[$6] += a[2]} END {for (u in bytes) printf "%8.1f MB  %s\n", bytes[u]/1048576, u}' /var/log/nginx/access.log | sort -rn | head -15

And because some scrapers don't announce themselves at all, check which IP addresses send the most requests:

sudo awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -15

If one address or one small range sends tens of thousands of requests with an ordinary browser user agent, that's a scraper in disguise. Keep it in mind for step 5.

Step 2: Decide Which Bots You Actually Want

This is the step most guides skip, and it's where people hurt themselves. "AI bots" are not one thing. Roughly, they do three different jobs:

  • Training crawlers collect pages to train future models. Blocking them costs you no visitors.
  • Search crawlers build the index that AI search and chat tools quote from, often with a link back to your site. Blocking them can mean your site stops showing up in those answers.
  • User fetchers load one page because a person just asked an AI tool to read it. They're closer to a visitor than a crawler, and they don't crawl your whole site.
CompanyTrainingSearch / answersFetch for a user
OpenAIGPTBotOAI-SearchBotChatGPT-User
AnthropicClaudeBotClaude-SearchBotClaude-User
Perplexity–PerplexityBotPerplexity-User
GoogleGoogle-Extended (robots.txt only)Googlebot–
AppleApplebot-Extended (robots.txt only)Applebot–
MetaMeta-ExternalAgent–Meta-ExternalFetcher
ByteDanceBytespider––
Common CrawlCCBot––
AmazonAmazonbot––

Two rows need special care. Never block Googlebot or Bingbot unless you want to vanish from search. Google's AI training is controlled by a separate name, Google-Extended. It isn't a crawler of its own, it's a robots.txt setting that Googlebot respects, so it only works in robots.txt and never shows up in your logs. Applebot-Extended works the same way.

Crawler names change from time to time, so check each company's crawler documentation once in a while. A sensible starting point for most sites: block the training crawlers, allow the search crawlers and user fetchers, and rate-limit everyone else.

Step 3: Ask Nicely With robots.txt

The big, well-known crawlers read robots.txt and follow it. It's the gentlest fix, and the only way to opt out of Google's and Apple's AI training without touching their search crawlers. Add a group like this to the robots.txt in your site's root folder:

# AI training crawlers: not here, thanks
User-agent: GPTBot
User-agent: ClaudeBot
User-agent: CCBot
User-agent: Google-Extended
User-agent: Applebot-Extended
User-agent: Meta-ExternalAgent
User-agent: Bytespider
User-agent: Amazonbot
Disallow: /

# Everyone else, including search engines
User-agent: *
Allow: /

Check that it's really being served with curl https://example.com/robots.txt. On WordPress, a real robots.txt file in the site folder replaces the one WordPress generates on the fly, so if you already had rules in a plugin, copy them in.

Two honest warnings. robots.txt is a request, not a lock: some crawlers ignore it, and Bytespider has a reputation for doing exactly that. And well-behaved bots cache the file, so it can take a day or so before the traffic drops. If the load is hurting you right now, go straight on to step 4.

Step 4: Block Them at the Web Server

A block in Nginx works whether the bot reads robots.txt or not, and it costs your server almost nothing: no PHP, no database, just a tiny 403 response. Create a file in the http section, which on Ubuntu and Debian means /etc/nginx/conf.d/ai-bots.conf:

map $http_user_agent $block_ai_bot {
    default 0;
    ~*(GPTBot|ClaudeBot|CCBot|Bytespider|Meta-ExternalAgent|Amazonbot) 1;
}

Then add one line to each server block you want to protect, for example in /etc/nginx/sites-available/example.com:

server {
    ...
    if ($block_ai_bot) { return 403; }
    ...
}

Test the config and reload:

sudo nginx -t && sudo systemctl reload nginx

Now check it does what you expect. A blocked bot should get 403, a normal browser should still get 200:

curl -s -o /dev/null -w "%{http_code}\n" -A "GPTBot/1.2" https://example.com/
curl -s -o /dev/null -w "%{http_code}\n" -A "Mozilla/5.0" https://example.com/

On Apache

Put this in the site's virtual host or in its .htaccess. It needs mod_rewrite, which you can turn on with sudo a2enmod rewrite:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_USER_AGENT} (GPTBot|ClaudeBot|CCBot|Bytespider|Meta-ExternalAgent|Amazonbot) [NC]
    RewriteRule .* - [F,L]
</IfModule>

Then sudo apachectl configtest && sudo systemctl reload apache2.

Step 5: Rate-Limit the Rest

Blocking by name only catches bots that tell the truth about who they are. Rate limiting catches the rest, and it's a good safety net even for bots you allow: they can still read your site, just not 50 pages a second. This setup limits anything that calls itself a bot, crawler or spider to one request every two seconds per IP address, while leaving Google, Bing and real visitors alone. Add it to /etc/nginx/conf.d/ai-bots.conf:

map $http_user_agent $bot_limit_key {
    default "";
    ~*(Googlebot|bingbot) "";
    ~*(bot|crawler|spider|scraper) $binary_remote_addr;
}

limit_req_zone $bot_limit_key zone=bots:10m rate=30r/m;
limit_req_status 429;

Nginx checks the patterns from top to bottom and stops at the first match, so Google and Bing land on the empty value, and an empty key is never limited. Turn the limit on in your server block:

location / {
    limit_req zone=bots burst=10 nodelay;
    # ...your existing proxy_pass, try_files or PHP settings
}

Reload Nginx again. Bots that go too fast now get 429 Too Many Requests, which well-written crawlers understand as "slow down".

Scrapers that pretend to be browsers

For traffic that uses a normal browser user agent but behaves like a machine, as you found in step 1, a general limit per IP helps too. Use a looser limit so real visitors never notice it:

limit_req_zone $binary_remote_addr zone=perip:10m rate=10r/s;
location / {
    limit_req zone=perip burst=40 nodelay;
    limit_req zone=bots burst=10 nodelay;
    ...
}

If the scraping is so heavy that even this isn't enough, look at Anubis. It's an open-source tool that sits in front of your site and asks each new visitor's browser to solve a small puzzle before letting it in. People barely notice it, but it makes mass scraping expensive.

Step 6: Ban the Worst Offenders With fail2ban

Bots that keep hammering after they get 429s are wasting your server's time with every request. fail2ban can block them at the firewall instead, so Nginx doesn't even see them. It already ships with a filter that reads Nginx's rate-limit messages. Install it and add a jail:

sudo apt install fail2ban

Create /etc/fail2ban/jail.d/nginx-limit-req.local:

[nginx-limit-req]
enabled  = true
port     = http,https
logpath  = /var/log/nginx/error.log
findtime = 10m
maxretry = 20
bantime  = 1h
sudo systemctl restart fail2ban
sudo fail2ban-client status nginx-limit-req

Any address that runs into the limit 20 times in 10 minutes is now banned for an hour. Keep maxretry generous so a busy office behind one IP address never gets caught. If you also run a firewall, our guide to setting up a firewall on Ubuntu shows how fail2ban and UFW fit together.

Step 7: Make Sure You Didn't Block Google

After any change like this, check that search engines still get in:

  • Search your log for Googlebot over the next day and make sure its requests get 200, not 403 or 429: sudo grep Googlebot /var/log/nginx/access.log | awk '{print $9}' | sort | uniq -c
  • Use the URL Inspection tool in Google Search Console to test a page live.
  • Watch your Search Console crawl stats for a week. A sudden drop means something is catching Googlebot.

One more trick from scrapers: some fake the Googlebot user agent, knowing most people won't block it. A real Googlebot address always resolves back to a Google host name. Check an address from your log like this:

host 66.249.66.1

A real one answers with a name ending in googlebot.com or google.com. If an address claims to be Googlebot and resolves to something else, it's fair game for your firewall.

Lighten the Load Even for Bots You Allow

Whatever you decide to let in, you can make each visit cheaper:

  • Turn on a page cache. A cached page is served straight from memory or disk without PHP or the database. For WordPress, a caching plugin or Nginx FastCGI cache makes crawler traffic almost free.
  • Close the endless pages. Crawlers love filter combinations, calendar archives and internal search results, which can produce millions of near-identical URLs. Add Disallow lines for them in robots.txt, such as /?s= or /search/.
  • Keep an eye on bandwidth. If images and downloads are the big cost, consider a plan with more transfer. NodexVPS has unmetered bandwidth VPS plans for exactly this.

If the crawl load has already pushed your server over the edge and visitors see errors, our guide to fixing 502 Bad Gateway in Nginx covers the PHP-FPM and memory side of the problem.

Quick Checklist

  • Read the access log first: busiest user agents, bytes per bot, busiest IP addresses.
  • Split the bots into training crawlers, search crawlers and user fetchers, then decide.
  • robots.txt: block training crawlers, including Google-Extended and Applebot-Extended, which only work there.
  • Nginx map + return 403, or an Apache RewriteRule, for bots that ignore robots.txt.
  • Rate-limit anything that calls itself a bot, plus a loose per-IP limit for disguised scrapers.
  • fail2ban to ban the addresses that keep hitting the limit.
  • Never block Googlebot or Bingbot, and confirm in your log and Search Console afterwards.

Put together, this usually takes a server from "pinned at 100% all night" to quiet within a day, and you stay in control of who reads your content. If your sites need more headroom, a website VPS from NodexVPS gives you dedicated CPU, full root access and room to set all of this up your way.

Recent Insights

Start Your NodexVPS Today

Save 50% with yearly billing.