1

I'm currently installing a new server and i want to use varnish for cache system. I follow this tutorial to set up with apache.

When i restart the varnish service it give me this error :

* Stopping HTTP accelerator varnishd                                                                                                                      [fail] 
 * Starting HTTP accelerator varnishd                                                                                                                  [fail] 
SMF.s0: filename: /var/lib/varnish//varnish_storage.bin size 1024 MB.
Message from VCC-compiler:
Expected ';' got '('
(program line 174), at
('input' Line 27 Pos 22)
purge("req.url ~ " req.url " && req.http.host == " req.http.host);
---------------------#------------------------------------------------------------
Running VCC-compiler failed, exit 1

Any idea to solve this ? (i use the last version of varnish on a Ubuntu 11.04)

** EDIT add default.vcl **

backend apache {
    .host = "127.0.0.1";
    .port = "8008";
}
acl purge {
    "localhost";
    "127.0.0.1";
}
sub vcl_recv {
    // Strip cookies for static files:
    if (req.url ~ "\.    (jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$") {
            unset req.http.Cookie;
            return(lookup);
    }
    // Remove has_js and Google Analytics __* cookies.
    set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[a-z]+|has_js)=[^;]*", "");
    // Remove a ";" prefix, if present.
    set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
    // Remove empty cookies.
    if (req.http.Cookie ~ "^\s*$") {
            unset req.http.Cookie;
    }
    if (req.request == "PURGE") {
            if (!client.ip ~ purge) {
                    error 405 "Not allowed.";
            }
            purge("req.url ~ " req.url " && req.http.host == " req.http.host);
            error 200 "Purged.";
    }
}
sub vcl_hash {
  if (req.http.Cookie) {
    set req.hash += req.http.Cookie;
  }
}
sub vcl_fetch {
    // Strip cookies for static files:
    if (req.url ~ "\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$") {
            unset beresp.http.set-cookie;
    }
    // Varnish determined the object was not cacheable
    if (!beresp.cacheable) {
            set beresp.http.X-Cacheable = "NO:Not Cacheable";
    } elsif(req.http.Cookie ~"(UserID|_session)") {
        // You don't wish to cache content for logged in users
            set beresp.http.X-Cacheable = "NO:Got Session";
            return(pass);
    }  elsif ( beresp.http.Cache-Control ~ "private") {
             // You are respecting the Cache-Control=private header from the backend
            set beresp.http.X-Cacheable = "NO:Cache-Control=private";
            return(pass);
    } elsif ( beresp.ttl < 1s ) {
            // You are extending the lifetime of the object artificially
            set beresp.ttl   = 300s;
            set beresp.grace = 300s;
            set beresp.http.X-Cacheable = "YES:Forced";
    }  else {
            // Varnish determined the object was cacheable
            set beresp.http.X-Cacheable = "YES";
    }
    return(deliver);
}
3
  • helps if you should your varnish config
    – Mike
    Aug 26, 2011 at 12:49
  • the default.vcl or varnish file ? Both configurate something
    – Awea
    Aug 26, 2011 at 12:52
  • looks like your error is in the vcl file
    – Mike
    Aug 26, 2011 at 12:55

1 Answer 1

1

Your issue is in the purge line.. bad use of quotes

purge("req.url ~ " req.url " && req.http.host == " req.http.host);

should be like

purge(req.url ~ req.url && req.http.host == req.http.host);
1
  • 1
    it give me another error but i'm going to debug by myself, thanks for your help :)
    – Awea
    Aug 26, 2011 at 13:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .