Using GeoIP Functionality in Varnish

Ken Brownfield kb+varnish at
Tue Mar 16 20:21:13 CET 2010

I think what would work for you is to add only the C{} block from the top of the plugin.vcl to the top of your VCL, and do something like the following where you need to (vcl_recv() presumably):

	if (get_country_code) {
		char *country = (*get_country_code)(VRT_IP_string(sp, VRT_r_server_ip(sp)));
		if (!strncmp(country, "US", 2))
			VRT_l_req_url(sp, "/us/", vrt_magic_string_end);

Note that GeoIP is only accessible via C{} blocks, not VCL directly.

 * No guarantees ;)
 * You can remove the extra "char *country" step if you want; I did it for readability
 * Assumes replacing the URL with "/us/" instead of prepending to the existing URL
 * The GeoIP plugin on the twiki could use some love; it seems overly complicated and limited.

On Mar 16, 2010, at 9:22 AM, Sebastian Cabrera wrote:

> Hi everybody,
> 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?
> 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/"
> }
> ?
> thanks for your help,
> regards,
> Sebastian

More information about the varnish-misc mailing list