Tuesday, 7 April 2015

GeoIP with Varnish and Maxmind

Before I get into this I need to point out what seems to be a common misconception. GeoIP is not a great way to tell where a user is located. It isn't too bad for country, but if you want anything more granular, it will lead you down a path of horrible disappointment.

Secondly, GeoIP isn't language... it isn't!
Language is language and you can't determine language from location.

I had to point out those things because at RG we went down the path of GeoIP was king. This was, in spite of the engineers repeatedly pointing out that it wasn't accurate, and not useful for language anyway.

If you are reading this, and someone, particularly management suggested that this works you probably should point out that there are a significant number of users that this won't work for. The largest portion of these are possibly blackberry users. Yes, blackberry isn't the leading  horse in the smart phone race, but in certain countries like Indonesia they are prolific. Their geoIP location ends up being somewhere in the middle of the ocean. There is no way to get a street address from there!

Ok now that is over there are certainly some uses for determining a users geoIP. Serving up content based on country, particularly if you are serving up content that can be consumed by for example someone inside of China. One may have to filter out content that would cause a firewall block.

The secret to getting geoIP to work properly in varnish is by harnessing the ability of varnish to use inline C. You read that right, inline C, right in a varnish .vcl configuration file.This will really come in handy if your development team use C in any manner already.


The best way of course to utilize this is to understand the documentation, then you can properly implement the addition.

It is probably easier to also set a header that will be accessible to your front-end code, even if you don't use it straight away, you will never know when that kind of thing will be a feature request.

No comments:

Post a Comment