6

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?

alturic
  • 53
  • 2
  • 8

1 Answers1

2

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.

Jorge Nerín
  • 766
  • 6
  • 8
  • 1
    See, that's the thing I do curl -X PURGE http://domain.com/ (varnish is on 80) and it comes back 200 Purged as the reponse but I can't seem to find anything purged. Even if it worked as a literal match the actual index.php file (homepage) SHOULD be purged, no? – alturic Feb 17 '15 at 17:24
  • 1
    Can't edit comments, but even if I did curl -X PURGE http://localhost/ everything (curl output, varnishlog, etc) all seem to show a 200 response but the page isn't being purged. Additional question, varnish is "dumb" when it comes to the actual purge lookup/response so if I do a purge for http://localhost/non-existant-file it normally will still show 200 right? It doesn't like first check to see if the cache exists before returning a purge reply right? – alturic Feb 17 '15 at 17:44
  • Yes, that's correct, if you are allowed to purge you'll get a 200 always. You have to be careful about passing the right hostname (-H "Host: domain.com"), and the same path ("/" != "/index.php") so it can purge the correct object. The check is that later a GET request for the object results in a MISS. – Jorge Nerín Feb 17 '15 at 21:27