an example of Varnish and Lighttpd

Lighttpd on server 192.168.123.248 vhost config:

[...]
simple-vhost.server-root = "/var/web"
simple-vhost.default-host = "test.lo"
simple-vhost.document-root = "/www"
$HTTP["host"] =~ "^(www\.)?test\.lo$" {
        server.document-root = "/var/web/www"
}
$HTTP["host"] =~ "^blog\.test\.lo$" {
        server.document-root = "/var/web/blog"
}
[...]

Varnish on server 192.168.123.249 VCL file:

backend test {
set backend.host = "192.168.123.248";
set backend.port = "80";
}

acl purge {
"localhost";
"127.0.0.1";
}

sub vcl_recv {
if (req.http.host ~ "^(www|blog\.)?test\.lo$") {
set req.backend = test;
}

else {
error 404 "Unknown virtual host";
}
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
error 405 "Not allowed.";
}
}
if (req.http.Cache-Control ~ "no-cache") {
pass;
}
if (req.request != "GET" && req.request != "HEAD") {
pipe;
}
if (req.http.Expect) {
pipe;
}
if (req.http.Authenticate || req.http.Cookie) {
pass;
}
lookup;
}

sub vcl_pipe {
pipe;
}

sub vcl_pass {
pass;
}

sub vcl_hash {
set req.hash += req.url;
set req.hash += req.http.host;
set req.hash += req.http.cookie;
hash;
}

sub vcl_hit {
if (req.request == "PURGE") {
set obj.ttl = 0s;
error 200 "Purged.";
}
if (!obj.cacheable) {
pass;
}
deliver;
}

sub vcl_miss {
if (req.request == "PURGE") {
error 404 "Not in cache.";
}
fetch;
}

sub vcl_fetch {
if (!obj.valid) {
error;
}
if (!obj.cacheable || obj.http.Set-Cookie|| \
        obj.http.Pragma ~ "no-cache" || \
        obj.http.Cache-Control ~ "no-cache" || \
        obj.http.Cache-Control ~ "private") {
pass;
}
if (req.request == "GET" && req.url ~ "\.(txt|js)$") {
set obj.ttl = 3600s;
}
else {
set obj.ttl = 30d;
}
insert;
}

sub vcl_deliver {
deliver;
}

sub vcl_timeout {
discard;
}

sub vcl_discard {
discard;
}

Above is just a simple example, it works for me currently.
Many people want to see the performance comparison between varnish and squid. Sorry but for now I couldn’t give that, maybe one day;)
I’m afraid that there’s going to be a variety of troubles to shooting, yeah, definitely.

Printed from: http://dotimes.com/iscale/2007/12/an-example-of-varnish-and-lighttpd.html .
© Cowyn Li 2010.

2 Comments   »

  1. Benedikt says:

    How is your experience with Varnish? You can feel the difference?

  2. cowyn says:

    Hi Benedikt,
    Sorry for the laaaaaate benchmark, it’s here, http://dotimes.com/iscale/2008/03/benchmark-caching-of-varnish-and-squid.html :)

RSS feed for comments on this post , TrackBack URI

Leave a Comment