我刚开始配置清漆。我正在尝试将我在AWS上做的清漆安装复制到另一台服务器上。下面是一个场景:
我有两个服务器为web内容提供服务(Web1和Web2),这是一个负载平衡的对。我们已经正确地运行和配置了Web1,现在我只需要通过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的内容(请注意,这里我已经替换了主机的ip地址)。我目前有一个裸露的VCL,这个正在工作:
backend default {
.host = "xxx.xxx.xxx.xxx";
.port = "80";
}
sub vcl_recv {
}现在,如果我开始像这样在vcl_recv中添加一个“宽限期”设置,清漆拒绝启动:
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服务器上,我有一些更复杂的东西在工作,而且它正在工作:
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";
}
}所以我不明白为什么相同的配置不能在另一台服务器上工作。
执行Carlos关于在调试模式下运行的建议,我现在看到以下错误:
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发布于 2015-02-15 10:09:30
做了更多的调查,版本信息给了我一些线索。我在这里发现了一个类似的问题:
https://stackoverflow.com/questions/23284764/varnish-wont-recognize-req-grace-variable
基本上,我是使用一个清漆版本3配置在一个清漆4安装。看来我得重写我的VCL了。
发布于 2015-02-13 20:51:07
如果Varnish没有启动,您可以尝试在前台手动运行它,然后检查stdout:sudo varnishd -F -f /path/to/your.vcl中的错误。
https://serverfault.com/questions/667277
复制相似问题