Varnish 运行 VCC 编译器失败

Varnish 运行 VCC 编译器失败

我目前正在安装一台新服务器,我想使用 varnish 作为缓存系统。我关注本教程使用 apache 进行设置。

当我重新启动 varnish 服务时,它给出了这个错误:

* 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

有什么办法可以解决这个问题吗?(我在 Ubuntu 11.04 上使用最新版本的 varnish)

** 编辑添加 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);
}

答案1

您的问题在清除行中……引号使用不当

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

应该是

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

相关内容