How to Stop Aggressive AI Scraper Bots and Layer-7 Floods Using Cloudflare WAF and Nginx Rate Limiting on an NVMe VPS
← Back to all articles
Cybersecurity & WAF•8 min read•Published on 11/24/2026

How to Stop Aggressive AI Scraper Bots and Layer-7 Floods Using Cloudflare WAF and Nginx Rate Limiting on an NVMe VPS

Aggressive AI crawlers and Layer-7 HTTP floods can exhaust origin PHP-FPM workers, saturate NVMe IOPS, and inflate egress bandwidth costs in minutes. This engineering guide details how to neutralize malicious traffic at the edge with Cloudflare WAF custom expressions and enforce strict origin rate limiting in Nginx.

A
AZBrand Editorial TeamTechnical Research • AZBrand

Modern web infrastructure faces an unprecedented wave of automated traffic. Unlike traditional search engine indexing, today's aggressive AI training crawlers and headless scraping networks ignore robots.txt, hammer dynamic endpoints simultaneously, and mimic legitimate browser headers. Combined with Layer-7 HTTP floods, this traffic rapidly exhausts application worker pools (PHP-FPM, Node.js, Gunicorn) and degrades Time to First Byte (TTFB) even on high-throughput NVMe VPS instances.

To protect origin compute without degrading experience for real users or hurting SEO rankings, infrastructure teams need a two-tier defense: edge filtering with Cloudflare WAF paired with kernel- and socket-level rate limiting in Nginx.


Why Traditional IP Blocking Fails Against Distributed AI Crawlers

Relying on iptables, ufw, or fail2ban to block single /32 IPv4 addresses is largely ineffective against modern scraping infrastructure and Layer-7 DDoS botnets for four structural reasons:

  1. Residential Proxy Rotation: Commercial AI scrapers route requests through millions of compromised or leased residential ISP endpoints. A single scraping job may never reuse the same IP address twice within a 10-minute window.
  2. IPv6 /64 Subnet Hopping: Attackers operating from cloud providers or ISP allocations can cycle through trillions of IPv6 addresses within a single /64 prefix, bypassing naive per-IP counters.
  3. CGNAT Collateral Damage: Blocking entire mobile carrier or regional ISP ranges to stop a botnet inadvertently locks out thousands of legitimate human visitors behind Carrier-Grade NAT (CGNAT).
  4. Origin Socket Exhaustion: Even if fail2ban eventually bans an IP after parsing /var/log/nginx/access.log, the TLS handshake and initial HTTP floods have already consumed CPU cycles and disk I/O on your VPS.

Effective server hardening requires dropping bad requests before they reach your origin network interface, and enforcing stateless burst limits on anything that slips through.


Layer 1: Cloudflare WAF Custom Expression Rules

Before configuring your origin VPS, configure Cloudflare's Web Application Firewall (WAF) to drop known aggressive AI bots and issue Managed Challenges to spoofed crawlers or suspicious Autonomous System Numbers (ASNs).

Navigate to Security > WAF > Custom rules in your Cloudflare dashboard and implement the following two production rules.

Rule 1: Block Aggressive AI Scrapers Explicitly

While major search engines respect crawl-delay directives, many AI data-harvesting bots crawl aggressively without driving referral traffic. This expression matches known AI scraper User-Agents while leaving Googlebot and Bingbot untouched:

text
(http.user_agent contains "Bytespider" or http.user_agent contains "CCBot" or http.user_agent contains "GPTBot" or http.user_agent contains "ClaudeBot" or http.user_agent contains "PerplexityBot" or http.user_agent contains "Amazonbot" or http.user_agent contains "Meta-ExternalAgent" or http.user_agent contains "DataForSeoBot")
  • Action: Block
  • Engineering Note: If your business intentionally wants visibility in specific AI answer engines (e.g., OAI-SearchBot), omit that specific token from the expression while continuing to block pure training scrapers like Bytespider and CCBot.

Rule 2: Stop Spoofed Crawlers and Layer-7 Floods Without Hurting SEO

Attack scripts frequently spoof Googlebot in the User-Agent header to bypass naive security filters. Cloudflare validates legitimate search crawlers via reverse/forward DNS and cryptographic verification, exposing the cf.client.bot boolean.

Use this expression to immediately block spoofed search bots and challenge high-risk automated clients:

text
(not cf.client.bot and (http.user_agent contains "Googlebot" or http.user_agent contains "Bingbot" or http.user_agent contains "Applebot")) or (not cf.client.bot and (cf.threat_score gt 15 or http.request.version eq "HTTP/1.0" or http.user_agent eq "")) or (not cf.client.bot and ip.geoip.asnum in {14061 16276 24940 16509 15169} and http.request.uri.path contains "/wp-login.php" or http.request.uri.path contains "/api/")
  • Action: Managed Challenge (or split the first clause into a dedicated Block rule for spoofed Googlebot traffic).
  • Why it works: Verified Googlebot and Bingbot requests evaluate cf.client.bot as true, bypassing the rule cleanly. Meanwhile, headless Python/Go scrapers running on major cloud ASNs (DigitalOcean 14061, OVH 16276, Hetzner 24940, AWS 16509, GCP 15169) or sending legacy HTTP/1.0 floods hit a cryptographic browser challenge before reaching your VPS.

Critical Step: Prevent Direct-to-Origin Bypass

WAF rules are useless if attackers discover your VPS IPv4 address via historical DNS records and attack port 80/443 directly. On your NVMe VPS firewall (ufw or nftables) or AZBrand cloud firewall, restrict inbound HTTP/HTTPS traffic strictly to Cloudflare IPv4/IPv6 CIDR ranges, and enable Authenticated Origin Pulls in Cloudflare SSL/TLS settings.


Layer 2: Origin Hardening with Nginx Rate Limiting

Even with Cloudflare WAF active, sophisticated Layer-7 floods using valid TLS fingerprints and residential proxies can reach your origin. Configuring Nginx rate limiting using the leaky-bucket algorithm protects your application workers and NVMe storage queues.

Step 1: Restore Real Visitor IPs

Because traffic is proxied through Cloudflare, Nginx sees Cloudflare's edge IP as $remote_addr by default. If you enable rate limiting without restoring the real client IP, you will accidentally rate-limit Cloudflare's edge nodes and take your own site offline.

Create /etc/nginx/conf.d/cloudflare-realip.conf (populate with Cloudflare's published IP ranges) and set CF-Connecting-IP as the real IP header:

nginx
# /etc/nginx/conf.d/cloudflare-realip.conf
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 104.16.0.0/13;
set_real_ip_from 104.24.0.0/14;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 131.0.72.0/22;
set_real_ip_from 2400:cb00::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
set_real_ip_from 2a06:98c0::/29;
set_real_ip_from 2c0f:f248::/32;

real_ip_header CF-Connecting-IP;

Step 2: Production-Ready nginx.conf Rate-Limiting Snippet

Add the shared memory zone definitions inside your http {} block in /etc/nginx/nginx.conf, and apply tiered limits in your server block. Using $binary_remote_addr stores each IPv4 address in just 64 bytes of RAM—a 10m zone holds roughly 160,000 tracked IP states.

nginx
http {
    # General dynamic page rate limit: 10 requests/sec per IP
    limit_req_zone $binary_remote_addr zone=general_limit:20m rate=10r/s;

    # Strict zone for expensive endpoints (search, auth, APIs): 2 requests/sec
    limit_req_zone $binary_remote_addr zone=strict_api:10m rate=2r/s;

    # Concurrent connection limit per IP to mitigate slowloris/socket pinning
    limit_conn_zone $binary_remote_addr zone=conn_limit:10m;

    # Return 429 Too Many Requests instead of default 503
    limit_req_status 429;
    limit_conn_status 429;
    limit_req_log_level warn;

    server {
        listen 443 ssl http2;
        server_name example.com;

        # Standard application traffic with burst buffer for legitimate parallel asset loads
        location / {
            limit_req zone=general_limit burst=20 nodelay;
            limit_conn conn_limit 15;
            try_files $uri $uri/ /index.php?$args;
        }

        # Expensive database/compute routes: strict throttling without nodelay
        location ~ ^/(api/|search|wp-login\.php|xmlrpc\.php) {
            limit_req zone=strict_api burst=5;
            limit_conn conn_limit 5;
            include fastcgi_params;
            fastcgi_pass unix:/run/php/php8.3-fpm.sock;
        }

        # Bypass rate limiting for static assets already cached or lightweight
        location ~* \.(css|js|png|jpg|jpeg|webp|woff2|svg|ico)$ {
            expires 30d;
            add_header Cache-Control "public, immutable";
            access_log off;
        }
    }
}

Understanding burst and nodelay

  • burst=20 nodelay: Modern browsers open multiple concurrent requests when rendering a page. Without burst, legitimate visitors would hit 429 errors during initial page load. Adding nodelay serves up to 20 burst requests immediately while strictly enforcing the 10r/s refill rate—stopping sustained scraper loops cold.
  • Omitted nodelay on /api/ and /search: Queues excess requests up to burst=5 and paces them out at 2r/s, smoothing out micro-spikes against your database and NVMe read queues.
  • Zero-Log Static Assets: Disabling access_log on static files eliminates unnecessary NVMe write amplification during high-concurrency events.

Validate and reload Nginx safely:

bash
sudo nginx -t && sudo systemctl reload nginx

Performance Impact: Before vs. After WAF + Nginx Filtering

The following benchmark metrics reflect a typical 4 vCPU / 8 GB RAM NVMe Cloud VPS running a dynamic PHP/PostgreSQL stack during a sustained 1,200 RPS combined AI scraper and Layer-7 HTTP flood:

Infrastructure MetricUnprotected Origin VPS (Before)Cloudflare WAF + Nginx Rate Limiting (After)Operational Impact
Edge Requests Blocked0% (All hit origin)89.4% (Dropped/Challenged at Edge)Majority of attack never touches VPS NIC
Origin CPU Utilization98% – 100% (Saturated)14% – 22%Normal compute headroom restored
PHP-FPM / App Workers100% Exhausted (Queue full)12% ActiveZero 502 Bad Gateway / 504 Timeout errors
Origin Egress Bandwidth480 Mbps sustained38 Mbps92% reduction in bandwidth overhead
NVMe Disk IOPS (Logs/DB)18,500 IOPS (Heavy contention)1,100 IOPSEliminates database lockups and log bloat
Legitimate User TTFB4,200 ms – Timeout68 msFull responsiveness restored for real visitors

Actionable Verification Checklist

After deploying your Cloudflare WAF rules and Nginx rate limiting configuration, verify enforcement without locking out valid monitoring or SEO bots:

  1. Verify Spoofed Bot Blocking: Test with curl -A "Googlebot/2.1" https://yourdomain.com from a non-Google IP. You should receive a 403 or Cloudflare Managed Challenge response.
  2. Test Nginx 429 Enforcement: Run a quick burst against a protected endpoint (bypassing edge cache with a random query string) using hey or a loop and inspect /var/log/nginx/error.log for limiting requests, excess: entries.
  3. Confirm Origin Isolation: Attempt a direct curl --resolve yourdomain.com:443:<YOUR_VPS_IP> https://yourdomain.com from an external machine. The connection must time out at the firewall level.

Pairing edge threat intelligence with deterministic Nginx rate limiting transforms how your infrastructure handles hostile traffic. On high-speed compute platforms like AZBrand NVMe Cloud VPS backed by Cybersecurity WAF, this dual-layer architecture ensures your CPU cores, memory, and storage IOPS remain dedicated to paying customers—not uninvited AI scrapers.

Topics:#cloudflare waf rules#block ai scraper bots#nginx rate limiting vps#layer 7 ddos protection#server hardening
Was this article helpful?Your feedback helps our engineering team improve technical guides.

Related Architecture Guides

Continue exploring cloud engineering, telecommunications, and infrastructure articles.

View all →