Skip to content

Instantly share code, notes, and snippets.

@sourcec0de
Last active August 29, 2015 14:01
Show Gist options
  • Save sourcec0de/c3d64bc15497b860112d to your computer and use it in GitHub Desktop.
Save sourcec0de/c3d64bc15497b860112d to your computer and use it in GitHub Desktop.
Purge all cache from varnish - found here http://mesmor.com/2012/02/29/varnish-purge-all-cache/

Clear all

curl -X BAN http://<VarnishServerIP>/

Clear specific cached file.

curl -X BAN http://<VarnishServerIP>/static/images.png
if (req.request == "BAN") {
    if (!client.ip ~ ClearCache) {
        error 405 "Not allowed.";
    }

    # This option is to clear any cached object containing the req.url
    ban("req.url ~ "+req.url);

    # This option is to clear any cached object matches the exact req.url
    # ban("req.url == "+req.url);

    # This option is to clear any cached object containing the req.url 
    # AND matching the hostname.
    # ban("req.url ~ "+req.url+" && req.http.host == "+req.http.host);

    error 200 "Cached Cleared Successfully.";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment