Skip to main content

Cache / Proxy

Varnish Cache Blocklist Tutorial

Block VPN and proxy IPs in Varnish Cache using VCL ACL blocks populated from a TXT/CSV blocklist file, filtering traffic before it hits your backend.

Supported formats: TXT (one IP/CIDR per line) CSV

Steps

  1. 1

    Download the blocklist

    Fetch the TXT blocklist from your AntiProxies dashboard.

  2. 2

    Generate VCL ACL block

    Convert the flat IP list into a Varnish ACL block using a shell script. The generated .vcl file is then included by your main VCL.

  3. 3

    Add sub vcl_recv logic

    In your main VCL vcl_recv subroutine, check the client IP against the ACL and return a 403 synthetic response for matches.

  4. 4

    Reload Varnish VCL

    Use varnishadm vcl.load and vcl.use to hot-reload the new VCL without restarting Varnish or dropping connections.

Need the blocklist files?

Download free sample data or subscribe for daily-updated lists.

Free Sample

Generated ACL file

VCL ACL block – included by the main VCL. Add your blocked IPs here.

/etc/varnish/blocklists/antiproxies.vcl
acl blocked_ips {
    "1.2.3.4";
    "5.6.7.0"/24;
    "10.0.0.1";
    "192.168.100.0"/22;
}

Main VCL – block in vcl_recv

Include the ACL and deny matching clients with a synthetic 403 response.

/etc/varnish/default.vcl
vcl 4.1;

include "/etc/varnish/blocklists/antiproxies.vcl";

backend default {
    .host = "127.0.0.1";
    .port = "3000";
}

sub vcl_recv {
    if (client.ip ~ blocked_ips) {
        return (synth(403, "Access denied"));
    }
}

sub vcl_synth {
    if (resp.status == 403) {
        set resp.http.Content-Type = "text/plain; charset=utf-8";
        synthetic("Access denied");
        return (deliver);
    }
}

Frequently asked questions

Can Varnish hot-reload without dropping cached objects?
Yes. vcl.load compiles a new VCL label and vcl.use activates it. The object store is not affected – cached content remains valid.
Does client.ip work correctly behind a CDN?
Only if Varnish is the first hop. If it sits behind another proxy, use the beresp.http.X-Forwarded-For or set up PROXY protocol so client.ip holds the real IP.

Want to see what's in the database?

Download once, query as many times as you need. €99/year for all 22 databases, unlimited servers, and a full year of monthly updates. No usage limits, no per-query fees, no data leaving your servers.

30-day money-back guarantee
All databases included
Monthly updates