清漆vcl_fetch不起作用

我是新configuration清漆。 我正在尝试将我在AWS上制作的清漆设置复制到另一台服务器上。 这是一个场景:

我有2个服务器提供Web内容(Web1和Web2),这是一个负载平衡的对。 我们有Web1运行和configuration正确,现在我只是Web2通过光油指向Web1。

这里是/ etc / sysconfig / varnish的内容:

NFILES=131072 MEMLOCK=82000 RELOAD_VCL=1 DAEMON_OPTS="-a :80 \ -T localhost:6082 \ -f /etc/varnish/default.vcl \ -u varnish -g varnish \ -S /etc/varnish/secret \ -s file,/var/lib/varnish/varnish_storage.bin,1G" 

这里是我的/etc/varnish/default.vcl的内容(注意,我已经在这里replace了主机的IP地址)。 我目前有一个裸VCL,这是工作:

 backend default { .host = "xxx.xxx.xxx.xxx"; .port = "80"; } sub vcl_recv { } 

现在,如果我开始在vcl_recv中添加“宽限期”设置,varnish拒绝启动:

 backend default { .host = "xxx.xxx.xxx.xxx"; .port = "80"; } sub vcl_recv { set req.grace = 24h; } 

如果我尝试添加一个vcl_fetch,它将拒绝工作:

 backend default { .host = "xxx.xxx.xxx.xxx"; .port = "80"; } sub vcl_recv { } sub vcl_fetch { } 

我不知道我错过了什么。 这可能是显而易见的,但我没有足够的经验,但尚未意识到这一点。

我有一些更复杂的工作在我们的AWS服务器,这种types的,它的工作:

 sub vcl_recv { set req.grace = 24h; if (!req.backend.healthy) { unset req.http.Cookie; } if (req.url ~ "(?i)\.(svg|png|gif|jpeg|jpg|ico|swf|css|js|html|htm)(\?[a-z0-9]+)?$") { unset req.http.Cookie; } set req.http.Cache-Control = "public; max-age=31557600"; if (req.http.Accept-Encoding) { if (req.http.Accept-Encoding ~ "gzip") { set req.http.Accept-Encoding = "gzip"; } else if (req.http.Accept-Encoding ~ "deflate") { set req.http.Accept-Encoding = "deflate"; } else { unset req.http.Accept-Encoding; } } } sub vcl_fetch { set beresp.grace = 24h; unset beresp.http.pragma; set beresp.http.Max-Age = 31557600; set beresp.http.Cache-Control = "public, max-age=31557600"; unset beresp.http.Set-Cookie; } sub vcl_deliver { if (obj.hits > 0) { set resp.http.X-Cache = "HIT"; } else { set resp.http.X-Cache = "MISS"; } } 

所以我不明白为什么相同的configuration将无法在其他服务器上工作。

更新:

做卡洛斯·阿巴德的build议在debugging模式下运行,我现在看到以下错误:

 Message from VCC-compiler: VCL sub's named 'vcl*' are reserved names. ('input' Line 28 Pos 5) sub vcl_fetch { ----#########-- Valid vcl_* methods are: none vcl_recv vcl_pipe vcl_pass vcl_hash vcl_purge vcl_miss vcl_hit vcl_deliver vcl_synth vcl_backend_fetch vcl_backend_response vcl_backend_error vcl_init vcl_fini Running VCC-compiler failed, exited with 2 VCL compilation failed 

我不明白如何识别vcl_fetch。 这是我的清漆版本信息:

 varnishd (varnish-4.0.2 revision bfe7cd1) Copyright (c) 2006 Verdens Gang AS Copyright (c) 2006-2014 Varnish Software AS 

如果Varnish没有启动,可以尝试在前台手动运行它,然后检查stdout中的错误: sudo varnishd -F -f /path/to/your.vcl

有更多的挖掘和版本信息给了我一些线索。 我在这里发现了类似的问题:

https://stackoverflow.com/questions/23284764/varnish-wont-recognize-req-grace-variable

基本上我在Varnish 4安装上使用Varnish版本3configuration。 看起来我将不得不重写我的VCL。