1

I'm new to configuring varnish. I am trying to replicate a varnish setup I made on AWS onto another server. Here's the scenario:

I have 2 servers serving web content (Web1 and Web2), which is a load-balanced pair. We have Web1 running and configured correctly and right now I just have Web2 pointing to Web1 via Varnish.

Here's the content of /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"

And here's the content of my /etc/varnish/default.vcl (note that I have substituted the host's ip address here). I currently have a bare VCL and this one is working:

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

sub vcl_recv {
}

Now if I start adding a "grace period" setting inside vcl_recv like so, varnish refuses to start:

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

sub vcl_recv {
    set req.grace = 24h;
}

If I attempt to add a vcl_fetch, it flat out refuses to work either:

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

sub vcl_recv {
}

sub vcl_fetch {
}

I'm not sure what I'm missing. It might be something obvious but I do not have sufficient experience with this yet to realize that.

I have something more complex working on our AWS server, something of this sort, and it is working:

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";
    }
}

So I don't understand why the same configuration won't work on this other server.

Update:

Doing Carlos Abalde's suggestion of running in debug mode, I now see the following error:

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

I don't understand how vcl_fetch is not recognized. Here's my Varnish version info:

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

If Varnish is not starting, you could try to run it manually in foreground and then check for errors in the stdout: sudo varnishd -F -f /path/to/your.vcl.

  • Thank you so much, this has been very valuable. I'm seeing a VCC compiler error now. This should point me to the right direction. I do not know how I can upvote you (cause I have low rep). – Chuck Cerrillo Feb 15 '15 at 9:58
0

Did a bit more digging and the version information gave me some clues. I found a similar issue here:

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

Basically I'm using a Varnish version 3 config on a Varnish 4 installation. Looks like I will have to rewrite my VCL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.