Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Varnish 4, Purging - I thought I had it all figured out

Well, I'll keep it simple, PURGE requests (or so I thought?) were pretty much all handled by literally:

acl purge {

    "localhost";

    "127.0.0.1";

}

and then

if (req.method == "PURGE") {
            if (!client.ip ~ purge) {
            return(synth(405, "This IP is not allowed to send PURGE requests."));
            }
            return (purge);
    }

I fairly certain both of the above statements are "correct", the thing I'm hung-up on is that if I sent a

curl -X PURGE http://domain.com/

or

curl -X PURGE http://domain.com/.*

and Varnish sends back 200 Purged well... the cache is purged? Even if it's just the homepage and not the entire cache (swear it was all using the above .* method) is and the above snippets of code are correct is there any particular reason http://domain.com (as in the actual homepage) isn't purged?

varnishncsa shows:

MYIP - - [16/Feb/2015:23:23:10 -0600] "PURGE http://domain.com/ HTTP/1.1" 200 241 "-" "curl/7.29.0"

I know I gotta be missing something silly but I can't figure it out?

like image 782
alturic Avatar asked Feb 17 '15 05:02

alturic


1 Answers

The official documentation says basically what you've done, but keep in mind PURGE != BAN, you can use regular expressions in BAN, but not in PURGE. With PURGE you delete all the Vary defined copies of one particular url.

In my tests with 4.0.2 it works as advised, I have the homepage cached, I do a curl -X PURGE http://localhost:8080/ and in varnishlog I see (among other things):

*   << Request  >> 65542     
-   Begin          req 65541 rxreq
-   Timestamp      Start: 1424188792.108573 0.000000 0.000000
-   Timestamp      Req: 1424188792.108573 0.000000 0.000000
-   ReqStart       ::1 60496
-   ReqMethod      PURGE
-   ReqURL         /

-   VCL_acl        MATCH purge "localhost"
-   VCL_return     purge
-   VCL_call       HASH
-   VCL_return     lookup
-   VCL_call       PURGE

And reloading I see a MISS & backend request (because it's not in the cache):

*   << BeReq    >> 65548     
-   Begin          bereq 65547 fetch
-   Timestamp      Start: 1424188815.112540 0.000000 0.000000
-   BereqMethod    GET
-   BereqURL       /
-   BereqProtocol  HTTP/1.1

-   VCL_call       BACKEND_RESPONSE
-   TTL            VCL 120 21600 0 1424188815
-   VCL_return     deliver

*   << Request  >> 65547     
-   Begin          req 65546 rxreq

-   ReqMethod      GET
-   ReqURL         /

-   VCL_return     hash
-   VCL_call       HASH
-   VCL_return     lookup
-   Debug          "XXXX MISS"
-   VCL_call       MISS
-   VCL_return     fetch
-   Link           bereq 65548 fetch

BTW Add "::1" to the list of ips in the purge acl just in case you are using ipv6. It would have returned a 405, but who knows.

like image 55
Jorge Nerín Avatar answered Oct 17 '22 08:10

Jorge Nerín