Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

In my server, I have varnish setup. I use wordpress and installed w3 total cache plugin. I have set that plugin to purge my varnish (varnish 3) cache. But its not working! In my syslog, there are some errors like show below... please help me!

    Mar 22 21:29:40 kadupul varnishd[3755]: CLI telnet 113.59.222.126 58833 77.81.240.177 6082 Rd GET / HTTP/1.1
    Mar 22 21:29:40 kadupul varnishd[3755]: CLI telnet 113.59.222.126 58833 77.81.240.177 6082 Wr 101 Unknown request. Type 'help' for more info. all comm$
    Mar 22 21:29:40 kadupul varnishd[3755]: CLI telnet 113.59.222.126 58833 77.81.240.177 6082 Rd Host: 77.81.240.177:6082
    Mar 22 21:29:40 kadupul varnishd[3755]: CLI telnet 113.59.222.126 58833 77.81.240.177 6082 Wr 101 Unknown request. Type 'help' for more info. all comm$
    Mar 22 21:29:40 kadupul varnishd[3755]: CLI telnet 113.59.222.126 58833 77.81.240.177 6082 Rd User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:11.$
    Mar 22 21:29:40 kadupul varnishd[3755]: CLI telnet 113.59.222.126 58833 77.81.240.177 6082 Wr 101 Unknown request. Type 'help' for more info. all comm$
    Mar 22 21:29:40 kadupul varnishd[3755]: CLI telnet 113.59.222.126 58833 77.81.240.177 6082 Rd Accept: text/html,application/xhtml+xml,application/xml;$
    Mar 22 21:29:40 kadupul varnishd[3755]: CLI telnet 113.59.222.126 58833 77.81.240.177 6082 Wr 101 Unknown request. Type 'help' for more info. all comm$
    Mar 22 21:29:40 kadupul varnishd[3755]: CLI telnet 113.59.222.126 58833 77.81.240.177 6082 Rd Accept-Language: en-us,en;q=0.5
    Mar 22 21:29:40 kadupul varnishd[3755]: CLI telnet 113.59.222.126 58833 77.81.240.177 6082 Wr 101 Unknown request. Type 'help' for more info. all comm$
    Mar 22 21:29:40 kadupul varnishd[3755]: CLI telnet 113.59.222.126 58833 77.81.240.177 6082 Rd Accept-Encoding: gzip, deflate
    Mar 22 21:29:40 kadupul varnishd[3755]: CLI telnet 113.59.222.126 58833 77.81.240.177 6082 Wr 101 Unknown request. Type 'help' for more info. all comm$
    Mar 22 21:29:40 kadupul varnishd[3755]: CLI telnet 113.59.222.126 58833 77.81.240.177 6082 Rd Connection: keep-alive
    Mar 22 21:29:40 kadupul varnishd[3755]: CLI telnet 113.59.222.126 58833 77.81.240.177 6082 Wr 101 Unknown request. Type 'help' for more info. all comm$
    Mar 22 21:30:01 kadupul CRON[3782]: (root) CMD (env MAILTO= SHELL=/bin/bash /usr/local/sbin/bfd -q)

My default.vcl (I have also added the ip 77.81.240.177 as the varnish server in the w3 total cache plugin) :

backend default {
    .host = "77.81.240.177";
    .port = "8080";
}

acl purge {
    "localhost";
    "127.0.0.1";
    "77.81.240.177";
}

sub vcl_recv {

    # Add a unique header containing the client address
    remove req.http.X-Forwarded-For;
    #set    req.http.X-Forwarded-For = client.ip;
    set    req.http.X-Forwarded-For = req.http.rlnclientipaddr; 

   if (req.request == "PURGE") {
     if (!client.ip ~ purge) {
       error 405 "Not allowed.";
     }
     return(lookup);
   }
  if (req.http.Accept-Encoding) {
#revisit this list
    if (req.url ~ "\.(gif|jpg|jpeg|swf|flv|mp3|mp4|pdf|ico|png|gz|tgz|bz2)(\?.*|)$") {
      remove req.http.Accept-Encoding;
    } elsif (req.http.Accept-Encoding ~ "gzip") {
      set req.http.Accept-Encoding = "gzip";
    } elsif (req.http.Accept-Encoding ~ "deflate") {
      set req.http.Accept-Encoding = "deflate";
    } else {
      remove req.http.Accept-Encoding;
    }
  }
  if (req.url ~ "\.(gif|jpg|jpeg|swf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") {
    unset req.http.cookie;
    set req.url = regsub(req.url, "\?.*$", "");
  }
  #if (req.url ~ "(\?|&)(utm_(campaign|medium|source|term)|adParams|client|cx|eid|fbid|feed|ref(id|src)?|v(er|iew))=”) {
  #  set req.url = regsub(req.url, “\?.*$”, “”);
  #}
  if (req.http.cookie) {
    if (req.http.cookie ~ "(wordpress_|wp-settings-)") {
      return(pass);
    } else {
      unset req.http.cookie;
    }
  }
}

sub vcl_fetch {
  if (req.url ~ "wp-(login|admin)" || req.url ~ "preview=true" || req.url ~ "xmlrpc.php") {
    return (hit_for_pass);
  }
  if ( (!(req.url ~ "(wp-(login|admin)|login)")) || (req.request == "GET") ) {
    unset beresp.http.set-cookie;
   set beresp.ttl = 2h;
  }
  if (req.url ~ "\.(gif|jpg|jpeg|swf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") {
    set beresp.ttl = 30d;
  } #else {
   # set beresp.do_esi = true;
  #}
}

sub vcl_deliver {
# multi-server webfarm? set a variable here so you can check
# the headers to see which frontend served the request
#   set resp.http.X-Server = "server-01";
   if (obj.hits > 0) {
     set resp.http.X-Cache = "HIT";
   } else {
     set resp.http.X-Cache = "MISS";
   }
}
sub vcl_hit {
  if (req.request == "PURGE") {
    set obj.ttl = 0s;
    error 200 "OK";
  }
}

sub vcl_miss {
  if (req.request == "PURGE") {
    error 404 "Not cached";
  }
}
share|improve this question
1  
You're going to need to provide more information, what version of varnish are you running, and have you created the required ACL to allow content purging in the varnish VCL? –  Oneiroi Mar 22 '12 at 16:27
    
@Oneiroi I just added my default.vcl –  EApubs Mar 22 '12 at 16:32
    
@Oneiroi Sorry i forgot... Im using varnish 3 –  EApubs Mar 22 '12 at 16:55

1 Answer 1

up vote 1 down vote accepted

Assuming Varnish3

if (req.request == "PURGE") {
 if (!client.ip ~ purge) {
   error 405 "Not allowed.";
 }
 return(lookup);
}

This block is incorrect, it will trigger a 405 error when a client not allowed to purge attempts to do so, but there is nothing in there to actually purge if a valid client attempts to do so, instead it will return content from cache.

        if (req.request == "PURGE") {
                if (!client.ip ~ purge) {
                        error 405 "Not allowed.";
                }
                ban("req.url ~ "+req.url);
                error 200 "Purged";
        }

This block should do what you need it to do.

share|improve this answer
    
Still not working my friend –  EApubs Mar 22 '12 at 17:08
    
Assuming you have run a reload to rebuild the vcl: run varnishlog @ the varnish server, and run through a purge request manually using curl from an approved client box, see what it comes back with. –  Oneiroi Mar 22 '12 at 17:14
    
Can you please tell me exactly how to do it? –  EApubs Mar 22 '12 at 17:15
    
curl -X http://site.com/uri/to/purge ... whilst having varnishlog open I suggest you reading the documentation for varnish. –  Oneiroi Mar 22 '12 at 22:19
1  
correction: curl -X PURGE http://site.com/uri/to/purge –  Oneiroi Mar 23 '12 at 10:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.