WordPress.org

Ready to get started?Download WordPress

Forums

W3 Total Cache
Varnish PURGE - Varnish as proxy (4 posts)

  1. armetiz
    Member
    Posted 2 years ago #

    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: https://www.varnish-cache.org/docs/trunk/tutorial/purging.html

    acl purge {
            "localhost";
            "192.168.55.0"/24;
    }
    
    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") {
                    purge;
                    error 200 "Purged.";
            }
    }
    
    sub vcl_miss {
            if (req.request == "PURGE") {
                    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 {
        hash_data(req.url);
        if (req.http.host) {
            hash_data(req.http.host);
        } else {
            hash_data(server.ip);
        }
        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..

    So,
    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.

    Also,
    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 ?

    Armetiz.

    http://wordpress.org/extend/plugins/w3-total-cache/

  2. Frederick Townes
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  3. armetiz
    Member
    Posted 1 year ago #

    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 domain.fr/articleA - 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.
    Thomas.

  4. Frederick Townes
    Member
    Plugin Author

    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic