Coder Social home page Coder Social logo

varnish-geoip-plugin's Introduction

Geocoding Incoming Requests

This package contains the source for a little library used through inline C in Varnish for converting IPs to "Lat,Long" or "City, Region, Country" to be used for custom hashes, backends, translation, etc.

It uses, and relies on the MaxMind GeoIP library available from:

http://www.maxmind.com/app/c

The site includes instructions on how to build the GeoIP library, which must be installed prior to using the library and inline C.

Building

To build the plugin, be sure the GeoIP library is installed and use the following:

$ ./configure
$ make
$ make check
$ sudo make install

The configure script will attempt to find GeoIP, and will also attempt to find the GeoIP City database which is also required. The configure script will search for either the paid version 'GeoIPCity.dat' or the Lite version 'GeoLiteCity.dat' in a few standard locations. If your database is not found, you can tell the configure script exactly where to find it by doing:

$ GEOIP_CITY_DATA=/path/to/data ./configure

make install will install the plugin and it's required files into $(prefix)/lib/varnish/plugins where $(prefix) is customizable by passing --prefix=/usr/local to configure

Making use of the library

If you follow the above steps, and everything goes smoothly, you should end up with geoip_plugin.vcl in $(prefix)/lib/varnish/plugins which can be included in your VCL file like so:

include "$(prefix)/lib/varnish/plugins/geoip_plugin.vcl";

Including geoip_plugin.vcl will define a new sub in your VCL file that must be used, called geocode_and_lookup which can be called in the VCL like so:

call geocode_and_lookup;

This sub will attempt to geocode the client's IP address and if successful, define 2 headers X-GeoIP-LatLong and X-GeoIP-City. If geocoding cannot be done, the header X-GeoIP-Unavailable will be set to '1'.

The format of the headers is as follows:

X-GeoIP-LatLong: -12.900919,10.200939
X-GeoIP-City: Brooklyn, NY, US, 11219

In the case of X-GeoIP-LatLong, an empty string, will be substituted if the information is unavailable.

geocode_and_lookup finishes with return(lookup), as the name indicates, therefore is only valid in places where calling lookup is appropriate.

Note: Varnish will fail to load your VCL if you include the plugin, but do not make use of it. If you do not make a call to geocode_and_lookup do not use the include line.

When the loaded VCL makes use of geoip_plugin.vcl you should see "GeoIP plugin loaded." upon starting varnishd.

varnish-geoip-plugin's People

Contributors

apg avatar

Watchers

william avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.