Not sure I've got varnish configured correctly

Ed Bloom ed at themesforge.com
Sat Apr 30 01:14:14 CEST 2011


Hi folks,

Hope I'm on the right list. I have Varnish setup and running correctly with
a good hitrate (i think) 1011 Cache hits - 13 misses
I've setup a test Linode VPS configured as follows:

Ubuntu 10.10
512MB RAM
PHP-FPM
NGINX 1.0 (8080)
Varnish (80)

I've got WordPress running the latest W3 Total Cache development version
with Page Caching (enhanced) working correctly.

My default.vcl is posted below. I've assigned 128MB memory to Varnish.

Prior to running Varnish I was getting about 40 reqs/sec running the follow
bench test

ab -n 1000 -c 100 http://staging2.themesforge.com/

Post Varnish install I'm getting the same or slightly less. I've tried the
bench from a few different servers and getting similar results.

Has anyone any ideas where I might be going wrong?

Thanks,

Ed

default.vcl

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

acl purge {
        "127.0.0.1";
}

sub vcl_recv {
  # Add a unique header containing the client address
  remove req.http.X-Forwarded-For;
  set    req.http.X-Forwarded-For = client.ip;

# Let's make sure we aren't compressing already compressed formats.
    if (req.http.Accept-Encoding) {
        if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|mp3|mp4|m4v)(\?.*|)$") {
            remove req.http.Accept-Encoding;
        } elsif (req.http.Accept-Encoding ~ "gzip") {
            set req.http.Accept-Encoding = "gzip";
        } elsif (req.http.Accept-Encoding ~ "deflate") {
            set req.http.Accept-Encoding = "deflate";
        } else {
            remove req.http.Accept-Encoding;
        }
    }

        if (req.request == "PURGE") {
                if (!client.ip ~ purge) {
                        error 405 "Not allowed.";
                }
                return(lookup);
        }
if (req.url ~ "^/$") {
               unset req.http.cookie;
            }

}

sub vcl_hit {
        if (req.request == "PURGE") {
                set obj.ttl = 0s;
                error 200 "Purged.";
        }
}
sub vcl_miss {
        if (req.request == "PURGE") {
                error 404 "Not in cache.";
        }
if (!(req.url ~ "wp-(login|admin)")) {
                        unset req.http.cookie;
                }
    if (req.url ~
"^/[^?]+.(jpeg|jpg|png|gif|ico|js|css|txt|gz|zip|lzma|bz2|tgz|tbz|html|htm)(\?.|)$")
{
       unset req.http.cookie;
       set req.url = regsub(req.url, "\?.$", "");
    }
    if (req.url ~ "^/$") {
       unset req.http.cookie;
    }
}
sub vcl_fetch {
        if (req.url ~ "^/$") {
                unset beresp.http.set-cookie;
        }
if (!(req.url ~ "wp-(login|admin)")) {
                        unset beresp.http.set-cookie;
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20110430/f9d8bf63/attachment-0003.html>


More information about the varnish-misc mailing list