Support » Plugin: W3 Total Cache » [Plugin: W3 Total Cache] Varnish PURGE – Varnish as proxy

  • Hi there,
    I’m using Varnish & W3TC.

    I want to be able to purge Varnish from W3TC.

    Here the VCL which is advice for PURGE on Varnish website:

    acl purge {
    sub vcl_recv {
            # allow PURGE from localhost and 192.168.55...
            if (req.request == "PURGE") {
                    if (!client.ip ~ purge) {
                            error 405 "Not allowed.";
                    return (lookup);
    sub vcl_hit {
            if (req.request == "PURGE") {
                    error 200 "Purged.";
    sub vcl_miss {
            if (req.request == "PURGE") {
                    error 200 "Purged.";

    As you can see, PURGE on Varnish 3.0 is based on hash definition because PURGE operation is on hit / miss.

    Also, the default VCL for hash sub-routine is :

    sub vcl_hash {
        if ( {
        } else {
        return (hash);

    As you can see, the hash operation is based on the HTTP Host or IP. Because, +99% of our HTTP Clients use domain.tld, the hash is really based on HTTP Host.

    The problem is, that W3TC use Varnish servers IP to send the PURGE HTTP Request.
    Example :
    – Send HTTP Purge to http://w.x.y.z/my-post (Where w.x.y.z) is a Varnish IP.

    In this case, Varnish try to get object from cache using the w.x.y.z & my-post.
    This couldn’t work..

    W3TC to be more generic have to deal with the Varnish IP because an IT could have many Varnish server. But, It should deal also with the “WordPress Address” define in the general panel of WP Admin.

    Here an functional example with cURL in CLI.
    – curl -X PURGE -x http://w.x.y.z:80 http://domain.tld/my-post

    PS : I could use “domain.tld” inside Varnish server declaration. But in this case, what about an IT with 1 or + Varnish server with a Load Balancer before Varnish cluster ?


Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Frederick Townes


    Sorry, I don’t have time to troubleshoot your VCL right now. But I’m going to start including the bits you need in terms of VCL in upcoming releases of W3TC to help people get started.

    Thanks for your reply,
    I don’t think that the problem come from VCL..
    As I have said, I think that W3TC have to take care of Domain Mapping configuration.

    In many case, Varnish Proxy is like any “anonymous” Internet client.

    If the solution is to change the VCL to “rewritte” domain.tld/fr/articleA to – It makes no sens..
    And what about SaaS Reverse Proxy like Cloudflare where I can’t change the Proxy configuration ?

    Thank you for your time.

    Plugin Author Frederick Townes


    You can rewrite in your VCL if you like.

    If you want to submit a bug submission form we can correspond via email and you can check out the next release early.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: W3 Total Cache] Varnish PURGE – Varnish as proxy’ is closed to new replies.