Varnish 无法识别 req.hash

Varnish 无法识别 req.hash

我在 Redhat 上安装了 Varnish 3.0.2,添加 vcl_hash 部分后,服务 varnish 启动失败。我执行了 varnishd,然后使用 vcl.load 加载了 vcl

vcl.load default default.vcl

Message from VCC-compiler:
Unknown variable 'req.hash'
At: ('input' Line 24 Pos 9)
    set req.hash += req.url;
--------########------------

Running VCC-compiler failed, exit 1

猫默认.vcl

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

sub vcl_recv {
  if( req.url ~ "\.(css|js|jpg|jpeg|png|swf|ico|gif|jsp)$" ) {
    unset req.http.cookie;
  }
}

sub vcl_hash {
  set req.hash += req.url;
  set req.hash += req.http.host;
  if( req.httpCookie == "JSESSIONID" ) {
    set req.http.X-Varnish-Hashed-On = regsub( req.http.Cookie, "^.*?JSESSIONID=([a-zA-z0-9]{32}\.[a-zA-Z0-9]+)([\s$\n])*.*?$", "\1" );
    set req.hash += req.http.X-Varnish-Hashed-On;
  }
  return(hash);
}

可能出了什么问题?

答案1

直接引自https://www.varnish-cache.org/docs/3.0/installation/upgrade.html#req-hash-is-replaced-with-hash-data

在 Varnish 3.x 中,req.hash被 替换为hash_data

您不再使用 += 附加到哈希表,因此:

set req.hash += req.url;

变成

hash_data(req.url);

相关内容