Take the 2-minute tour ×

I have a varnish installation to cache (MANY) images that my service serves. It is about 200 images of around 4k per second and varnish happily serves them according to the following rule:

if (req.request == "GET" && req.url ~ "\.(css|gif|jpg|jpeg|bmp|png|ico|img|tga|wmf)$") {
            remove req.http.cookie;

Now, the thing is that I recently added another service on the same server that creates thumbnails to serve but it does not add a specific extension. The files are of the following filename pattern:


where xx are numbers, so xxxxxxxxx.xx could be 6482364283.73 (two numbers at the end) (actually this is the timestamp so I can keep extra info in the filename)

That has the side effect that varnish does not cache them and I see them constantly being served by apache itself.

Even though I can change the format from now on to create thumbs ending in .jpg, is there a way to change the vcl file of my varnish daemon to either cache everything under a directory (the thumbnails directory) or everything with two numbers at its extension?

Let me know if I can provide any additional info !


share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

A slight modification to your existing rule will do the trick:

if (req.request == "GET" && req.url ~ "^/thumbnails/") {
        remove req.http.cookie;

Or you could make the regex \.\d{2}$ if you wanted to cache everything ending with two digits.

share|improve this answer
Thanks a lot @womble!! It obviously worked. Now I think the problem is just hardware-related as I see a lot of LRU nuked when I do varnishstat. There are quite a few thumbnails (7 million), over one third of them used quite frequently, and they don't fit in the 8GB assigned to varnish :) –  pataroulis Aug 4 '12 at 18:04
That's an easy problem to solve -- RAM is cheap. –  womble Aug 4 '12 at 21:36
Ram is cheap but bringing down a production server to add it, is not usually, thus the whole workaround. (until I get a new one that is. Next one will have 96GB of course!) Thanks again! –  pataroulis Sep 13 '12 at 11:53
add comment

Think it's easier to go with matching thumbnails directory.

req.url ~ "\thumbnails\?.*" should be quite close.

I recommend you to read more about regular expressions and Varnish.

share|improve this answer
I don't know what you're trying to achieve with that regex, but I doubt you really want to match against a tab in the URL. –  womble Aug 3 '12 at 10:52
add comment

Your Answer


