1

I need to purge or ban cache that has been modified by an unsafe request. I found a solution that appears to work for varnish 3.0; however I am on varnish 4. It seems this is no longer the correct syntax.

Varnish purge on POST or PUT

sub vcl_recv {
if ( req.request == "POST" || req.request == "PUT" ) {
    ban("req.url == " + req.url);
    return(pass);
    }
}

It's giving me an error

Jun 26 17:43:21 test varnishd[2127]: Symbol not found: 'req.request' (expected type BOOL):
Jun 26 17:43:21 test varnishd[2127]: ('/etc/varnish/default.vcl' Line 13 Pos 10)
Jun 26 17:43:21 test varnishd[2127]:     if ( req.request == "POST" || req.request == "PUT" ) {
Jun 26 17:43:21 test varnishd[2127]: ---------###########--------------------------------------
Jun 26 17:43:21 test varnishd[2127]: Running VCC-compiler failed, exited with 2

What can I do to make varnish purge/ban unsafe requests?

Thank You.

pl3bs
  • 25
  • 3
  • Are you ever going to have to scale Varnish to >1 instance? Keeping varnish in sync with the backend without a shared cache pool is going to be challenging. – Jason Martin Jun 27 '16 at 02:08
  • We use https, so in front of varnish is nginx terminating and proxy to the backend. On each backend server we will have varnish in front of another nginx. So I don't think this is an issue. – pl3bs Jun 29 '16 at 15:39

1 Answers1

0

In Varnish 4, req.request became req.method. https://www.varnish-cache.org/docs/4.0/whats-new/upgrading.html

Jason Martin
  • 4,865
  • 15
  • 24
  • Thanks, I figured it out. All appears to be functioning correctly, but will put it through another week of testing before going live on a site. – pl3bs Jun 29 '16 at 15:40