Build an AI-Crawler Firewall on a Small VPS with Anubis

Anubis v1.28.2 in front of any site: a four-rule bot policy that denies AI crawlers, allows search engines and challenges everyone else with proof of work, plus measured boot time, memory, per-request overhead and real-Chrome solve times from two independent runs.

Anubis sits in front of your origin and decides, per request, whether to serve it, refuse it, or make the client pay for it with a proof-of-work challenge. This guide runs ghcr.io/techarohq/anubis:v1.28.2 behind Caddy with a four-rule policy — AI crawlers denied, search engines allowed, everything else challenged — and measures what that costs: the stack answered its first request 1.1–4.0 s after compose up, Anubis idled at 15.9–25.0 MiB, an allowed request cost about 1 ms more than talking to nginx directly, and a real Chrome solved the difficulty-4 challenge in 0.69–1.51 s and was then served in 25–40 ms. The trap that cost me an hour is in here too: pointed at directly, Anubis answers every request with 500 until something in front of it sets X-Real-IP. Verified 2026-11-24.

What you end up with

Three containers behind one public port:

browser / crawler ──► Caddy :443 ──► Anubis :8080 ──► nginx :80
                        │              │
                        │              └─ policy: allow / deny / challenge
                        └─ sets X-Real-IP, terminates TLS
  • Anubis evaluates every request against a YAML policy and returns one of ALLOW, DENY or CHALLENGE.
  • A challenged client gets an HTML page that runs a small proof of work in JavaScript; when it finds the answer it receives an auth cookie and the page reloads into your real content.
  • Denied clients get a generic “Oh noes!” page. They do not get your content, your sitemap, or a 403 they can log and route around.
  • Nothing about your application changes: the origin still speaks plain HTTP on port 80, and Anubis is the only thing that knows about bots.

What you will learn

  • How the policy file is structured, and why the catch-all rule belongs last
  • The exact responses Anubis returned to six different user agents, measured twice
  • Why the reverse proxy in front must set X-Real-IP, and what the failure looks like when it does not
  • What a real browser does with the challenge, and how long the resulting cookie lets it back in
  • The metrics counters worth scraping, and the memory envelope on a tiny VPS

Prerequisites

  • Docker Engine with Compose v2 (verified on 28.2.2, Compose v5.5.1)
  • A domain and a TLS certificate if the site is public — Caddy obtains both for you
  • Roughly 64 MB of free RAM: Anubis never crossed 25 MiB in my runs
  • An origin that speaks HTTP. Anything works: nginx, a Node app, a Go binary on localhost:3001

1. How Anubis decides

The policy is a list of bot rules. Each rule has an optional path_regex, an optional user_agent_regex, and exactly one action:

Action What the client gets
ALLOW Your origin’s response, unchanged
DENY A generic block page, HTTP 200
CHALLENGE A proof-of-work page, then your content once it is solved

The important detail is that DENY and CHALLENGE both return HTTP 200. That is deliberate: a crawler that gets a 403 knows it was blocked and can report it, retry from another address, or switch user agent. A crawler that gets a 200 with a page it cannot parse just gets nothing. Your own uptime checks and access logs will also see 200, so the truth lives in the metrics endpoint, not in the status line.

2. The policy file

Four rules, in the order I want them evaluated:

# cfg/botPolicy.yaml
bots:
  - name: keep-internet-working
    path_regex: ^/(robots\.txt|favicon\.ico)$
    action: ALLOW
  - name: ai-crawlers
    user_agent_regex: (?i)(GPTBot|ClaudeBot|Claude-Web|CCBot|Bytespider|Amazonbot|PerplexityBot|Google-Extended|Meta-ExternalAgent)
    action: DENY
  - name: search-engines
    user_agent_regex: (?i)(Googlebot|Bingbot|Applebot|DuckDuckBot|YandexBot)
    action: ALLOW
  - name: everything-else
    user_agent_regex: (?s).*
    action: CHALLENGE

Rule 1 exists because of rule 4: without it, /robots.txt would be challenged too, and a crawler that respects robots.txt would never read it. Rule 4 matches every string including an empty one ((?s) makes . match newlines), so it must come last.

Measured, twice, from the same stack:

User-Agent Status Bytes Body
Googlebot/2.1 200 32 origin page
GPTBot/1.2 200 2,270 “Oh noes!” block page
ClaudeBot/1.0 200 2,270 “Oh noes!” block page
CCBot/2.0 200 2,270 “Oh noes!” block page
curl/8.14.1 200 7,044 challenge page
Firefox 145 200 7,103 challenge page

Both runs produced byte-identical responses; the two challenge pages differ only in the language Anubis negotiates from Accept-Language.

3. The compose file

# compose.yaml
services:
  caddy:
    image: caddy:2.10-alpine
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./cfg/Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
    restart: unless-stopped
    depends_on:
      - anubis

  anubis:
    image: ghcr.io/techarohq/anubis:v1.28.2
    environment:
      BIND: ":8080"
      TARGET: "http://origin:80"
      DIFFICULTY: "4"
      METRICS_BIND: ":9090"
      SERVE_ROBOTS_TXT: "true"
      POLICY_FNAME: "/data/cfg/botPolicy.yaml"
      OG_PASSTHROUGH: "true"
    volumes:
      - ./cfg/botPolicy.yaml:/data/cfg/botPolicy.yaml:ro
    restart: unless-stopped
    depends_on:
      - origin

  origin:
    image: nginx:1.29-alpine
    volumes:
      - ./www:/usr/share/nginx/html:ro
    restart: unless-stopped

volumes:
  caddy_data:

Notes on the environment block, all of which I changed and re-tested:

  • TARGET is the upstream, scheme included. Use the compose service name, not localhost — inside the container localhost is Anubis itself.
  • DIFFICULTY: "4" is the number of leading zero hex characters the proof of work has to find. It is a string; quote it.
  • METRICS_BIND exposes Prometheus-format metrics. Keep it off the public port and scrape it over the internal network.
  • SERVE_ROBOTS_TXT: "true" makes Anubis serve its own robots.txt — a 4,125-byte list of blocked AI agents — instead of your origin’s. That is a feature until you notice your real robots.txt is gone; if you have sitemap directives or per-path rules you care about, turn it off or copy the generated file into your origin.
  • The image reference is techarohq, not techaro. ghcr.io/techaro/anubis:v1.28.2 fails with manifest unknown; the GitHub org is TecharoHQ and the registry namespace is lowercased.

4. Caddy in front, and the 500 that is not your bug

# cfg/Caddyfile
example.com {
	reverse_proxy anubis:8080 {
		header_up X-Real-IP {remote_host}
	}
	encode zstd gzip
}

The header_up line is mandatory. Anubis needs the real client address to key rate limiting and challenge state; when it cannot determine one it refuses to serve at all:

[misconfiguration] X-Real-IP header is not set

Every request returns 500 with the same “Oh noes!” body it uses for denials — so a misconfigured deployment looks exactly like a policy that blocks everything. I reproduced this by hitting Anubis’s port directly instead of going through Caddy: 500 for every user agent. Add the header, get 200. If you use nginx instead of Caddy, the equivalent is:

proxy_set_header X-Real-IP $remote_addr;

Anubis can also use X-Forwarded-For, but only once you have told it which proxies to trust. The project’s docs are explicit that a wrong trust configuration either breaks the challenge loop or lets clients forge their own address, which is why pinning X-Real-IP at the proxy is the configuration with the fewest ways to go wrong.

5. Boot it and check the matrix

docker compose up -d

Time from compose up to the first successful allowed request, polling twice a second:

Metric Run 1 Run 2
Stack ready (first 200 to a bot UA) 3.95 s 1.10 s
Anubis RSS after the matrix 15.9 MiB 25.0 MiB

Run 1 created three containers from scratch; run 2 recreated them with the images already local. Both ran on a host that already had nginx:1.29-alpine and caddy:2.10-alpine cached, so the pull time is not in either number.

Now the part people skip: test with the user agents you actually care about, and read the body, not just the status.

for ua in "Googlebot/2.1" "GPTBot/1.2" "curl/8.14.1"; do
  echo "$ua -> $(curl -s -o /tmp/out.html -w '%{http_code} %{size_download}' \
    -H "User-Agent: $ua" http://127.0.0.1/)"
  grep -o '<title>[^<]*' /tmp/out.html | head -1
done

If every line says 200 and the byte counts are identical, nothing is being filtered and your policy file is not being read — check that POLICY_FNAME points at a path that exists inside the container.

6. What a real browser does

A challenge page is only useful if a human with JavaScript gets through it. I drove headless Chrome through Playwright against the stack and timed the first load, which includes the proof of work and the reload:

Metric Run 1 Run 2
Challenge solved, origin body reached 1.51 s 0.69 s
Second navigation with the cookie 25 ms 40 ms
Cookies set techaro.lol-anubis-auth-347ddb4a, techaro.lol-anubis-cookie-verification-347ddb4a same names

The page embeds the challenge parameters in a script tag, and they are not secret:

{"rules":{"algorithm":"fast","difficulty":4},"challenge":{"id":"...","randomData":"..."}}

That is the honest description of the trade-off. The fast algorithm is a few milliseconds of JavaScript for a browser and rounding error for a scraper that runs the same code headless. What it filters is cheap bots and default HTTP clients — curl, python-requests, crawlers that fetch a URL and give up when the HTML does not contain the article. A determined scraper with a real browser engine gets in, and DIFFICULTY only raises the arithmetic, not the complexity: going from 4 to 6 makes every client work roughly 256× harder, which also means 256× more CPU on the cheapest phones you serve. Measure your own audience before you touch it.

Two operational consequences worth designing around: the auth cookie is what keeps an allowed browser allowed, so clearing cookies sends a returning visitor back through the challenge; and every denied AI crawler still costs you one request and one 2 KB page.

7. Metrics

curl -s http://127.0.0.1:9090/metrics | grep '^anubis_'

Counters I saw after the matrix above:

anubis_policy_results{action="ALLOW",rule="bot/search-engines"} 2
anubis_policy_results{action="CHALLENGE",rule="bot/everything-else"} 2
anubis_policy_results{action="DENY",rule="bot/ai-crawlers"} 3
anubis_challenges_issued{method="embedded"} 2
anubis_proxied_requests_total{host="127.0.0.1:18081"} 2

anubis_policy_results is the one to graph: it tells you which rule fired, which is the only way to know whether a real search engine is being challenged by mistake. Note the bot/ prefix on the rule label — it comes from where the rule was defined, not from a name you choose freely, so read the labels on a live instance before you build dashboards on them.

Health checking works without HTTP:

docker exec anubis anubis --healthcheck   # exit 0
docker exec anubis anubis --version       # Anubis v1.28.2

8. What it costs

The measured footprint is small enough that the answer is “the VPS you already have”. Anubis idled at 15.9–25.0 MiB and added about 1 ms to an allowed request: 200 sequential requests to nginx directly averaged 5–6 ms each from the host, and the same 200 through Caddy and Anubis averaged 6–7 ms. The curl process spawn dominates both numbers, so the honest reading is “one extra millisecond, not one extra hundred”.

If you are sizing from zero, budget 128 MB and one vCPU. Challenges are CPU work by design, so a challenge storm is your own traffic being expensive on purpose. Prices for the actual smallest tiers are in the VPS cost guide below rather than repeated here.

Common problems

Every request is 500 with an “Oh noes!” page. Nothing in front of Anubis is setting X-Real-IP, or you are curling Anubis’s port directly. Check the container log for [misconfiguration] X-Real-IP header is not set.

A blocked crawler and a broken proxy look identical from outside. Both return 200 with “Oh noes!”. Compare the response size and check anubis_policy_results before you edit the policy.

Your robots.txt disappeared. SERVE_ROBOTS_TXT: "true" replaces it with Anubis’s generated list. Your sitemap line went with it.

Googlebot gets challenged even though your rule allows it. The rule has to match the full string the crawler sends — Googlebot’s desktop UA is long and contains compatible; Googlebot/2.1. Test with the real string, then check the rule label in metrics to see which rule actually fired.

The challenge loops forever behind Cloudflare. With Cloudflare’s proxy in front, the address Anubis sees is Cloudflare’s unless the trust configuration tells it otherwise. One of the two layers has to know the real client, or every request looks new.

manifest unknown when pulling. The namespace is techarohq. techaro does not exist in GHCR.

An allowlisted client loses access after a deploy. The auth cookie is tied to instance state; recreate the container with a fresh volume and every cookie is invalid. Keep your volumes.

Production checklist

  • Pin the image to a tag and a digest; :latest on a security component is how you get a policy change you did not review.
  • Keep METRICS_BIND off the public interface and scrape it internally.
  • Set restart: unless-stopped on all three services, and use anubis --healthcheck rather than curling the public URL.
  • Remember that denials never reach your origin — if you want them in your access logs, log them at the proxy or from the metrics endpoint.
  • Keep the policy file in git next to the compose file: it is the entire security configuration of this layer.

Related guides