Mailing List Archive

purge_url
I will stop bothering the helpful guys at the irc for a minute and ask a question here ;)

My VCL conf looks like this:
sub vcl_recv {
#Change the host header to www.mysite.com
if(req.http.host == "10.1.1.54" || req.http.host == "test.mysite.com") {
set req.http.host = "www.mysite.com";
}

#Purge specified files from acl purge.
#Purge = Delete the specified url from the cache
if(req.request == "PURGE") {
if(client.ip ~ purge) {
purge_url(req.url);
}
}

sub vcl_miss {
#set http version 1.1
set bereq.proto = "HTTP/1.1";

if (req.request == "PURGE") {
error 404 "The url could not be found in the cache.";
}
}

sub vcl_hit {
if (req.request == "PURGE") {
set obj.ttl = 0s;
error 200 "Purged successfully!";
}
}

}
# End of VCL Conf

I receive a 404 error "The url could not be found in the cache." when I try to PURGE the url.
PURGE http://www.mysite.com/data/hello.gif HTTP/1.1

This is the varnishlog when I try to purge:

12 RxRequest c PURGE
12 RxURL c /data/hello.gif
12 RxProtocol c HTTP/1.1
12 VCL_call c recv
12 VCL_acl c MATCH purge "84.xx.xx.xx"
12 VCL_return c lookup
12 VCL_call c hash
12 VCL_return c hash
12 Debug c "Hash: /data/hello.gif#10.1.1.54:80#"
12 VCL_call c miss
0 Debug "VCL_error(404, The url could not be found in the cache.)"
12 VCL_return c error
12 Length c 453
12 TxProtocol c HTTP/1.0
12 TxStatus c 404
12 TxResponse c Not Found
12 TxHeader c Server: Varnish
12 TxHeader c Retry-After: 0
12 TxHeader c Content-Type: text/html; charset=utf-8
12 TxHeader c Content-Length: 453
12 TxHeader c Date: Thu, 13 Dec 2007 11:34:50 GMT
12 TxHeader c X-Varnish: 1188471893
12 TxHeader c Age: nan
12 TxHeader c Via: 1.1 varnish
12 TxHeader c Connection: keep-alive

When I try to request it with GET i receive:

12 ReqStart c 84.xx.xx.xx 32162 1188471894
12 RxRequest c GET
12 RxURL c /data/hello.gif
12 RxProtocol c HTTP/1.1
12 RxHeader c Host: www.mysite.com
12 RxHeader c User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; sv-SE; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11
12 RxHeader c Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
12 RxHeader c Accept-Language: sv,en-us;q=0.7,en;q=0.3
12 RxHeader c Accept-Encoding: gzip,deflate
12 RxHeader c Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
12 RxHeader c Keep-Alive: 300
12 RxHeader c Connection: keep-alive
12 RxHeader c Cookie:__utma=75765975.864378540.1197378455.1197453843.1197535348.6;
12 VCL_call c recv
12 VCL_return c lookup
12 VCL_call c hash
12 VCL_return c hash
12 Debug c "Hash Match: /data/hello.gif#www.mysite.com#"
12 Hit c 1188471893
12 VCL_call c hit
12 VCL_return c deliver
12 Length c 905
12 VCL_call c deliver
12 VCL_return c deliver
12 TxProtocol c HTTP/1.1
12 TxStatus c 200
12 TxResponse c OK
12 TxHeader c Server: Zeus/4.3
12 TxHeader c Content-Type: image/gif
12 TxHeader c Content-Language: sv-SE
12 TxHeader c Content-Length: 905
12 TxHeader c Date: Thu, 13 Dec 2007 11:37:26 GMT
12 TxHeader c X-Varnish: 1188471894 1188471893
12 TxHeader c Age: 43
12 TxHeader c Via: 1.1 varnish
12 TxHeader c Connection: keep-alive

The strange thing is that the host is different in PURGE Match and GET Match. I have used the same host on both requests. Does it have anything to do with the vcl code where Im changing the hostheader?

/ Erik
purge_url [ In reply to ]
On Thu, Dec 13, 2007 at 12:02:38PM +0100, Erik wrote:
> I will stop bothering the helpful guys at the irc for a minute and ask a question here ;)
>
> My VCL conf looks like this:
> sub vcl_recv {
> #Change the host header to www.mysite.com
> if(req.http.host == "10.1.1.54" || req.http.host == "test.mysite.com") {
> set req.http.host = "www.mysite.com";
> }
>
> #Purge specified files from acl purge.
> #Purge = Delete the specified url from the cache
> if(req.request == "PURGE") {
> if(client.ip ~ purge) {
> purge_url(req.url);
> }
> }

I would change this part to:

if(req.request == "REPURGE") {
if(client.ip ~ purge) {
purge_url(req.url);
error 200 "Repurged."
}
}

If you are sending a regexp purge, you will always get a miss, unless
you accidentally don't use any regexp special characters - which does
not make sence. In any case, I recommend using a different request for
normal purge and regexp purge, but supporting both in the VCL.

Bye,

--
Anders.
purge_url [ In reply to ]
Erik <duja at torlen.net> writes:
> [redacted]
>
> sub vcl_recv {
> if (req.http.host == "10.1.1.54" || req.http.host == "test.mysite.com") {
> set req.http.host = "www.mysite.com";
> }
>
> if (req.request == "PURGE") {
> if (client.ip ~ purge) {
> purge_url(req.url);
> }
> }
> }
>
> sub vcl_miss {
> if (req.request == "PURGE") {
> error 404 "The url could not be found in the cache.";
> }
> }
>
> sub vcl_hit {
> if (req.request == "PURGE") {
> set obj.ttl = 0s;
> error 200 "Purged successfully!";
> }
> }

You are mixing two different purge mechanisms. I think what you want
is listed in the EXAMPLES section in the vcl(7) manual page.

Also, the PURGE request you showed did not include a Host: header at
all, so your host normalization code never kicked in, and you tried to
purge a different document from the one you later requested.

DES
--
Dag-Erling Sm?rgrav
Senior Software Developer
Linpro AS - www.linpro.no