Using GeoIP Functionality in Varnish

Cosimo Streppone cosimo at
Tue Mar 16 20:54:01 CET 2010

In data 16 marzo 2010 alle ore 17:22:53, Sebastian Cabrera  
<scabrera-varnish at> ha scritto:

> On a Website i want to have the posibility to do some rewriting due to
> the Country he's comming from. So if someone visits the Mainpage
> ( from US i want to have him visiting
> Does anyone have any experiences with that? How can i do this?

Maybe you could be interested at this code,

We're *not* using it in production yet.
However, we're using a very similar one,

And it proved very useful and stable since we
increased the default sess_workspace to 128k.

> I just downloaded and installed the GeoIP Plugin from the varnish wiki
> (, but how can i use it?
> Is there any possibility to do something like
> if (get_country_code(client.ip) == "US") {
>     set req.url = "/us/"
> }

No, but you can use "C{ }C" blocks.

AFAIK the most common approach is to use HTTP headers as a sort
of "temporary storage", hence the need of upping sess_workspace.

The inline C code writes a new header, say "X-GeoIP-Country",
and then you can say:

     sub vcl_recv {
             /* "sp" is the varnish session data structure */
         if (req.http.X-GeoIP-Country ~ "us") {
             set req.url = "/us/";

Have fun :)


More information about the varnish-misc mailing list