Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cosimo/varnish-geoip
Varnish VCL "plugin" that geolocates client IP addresses (requires geoip)
https://github.com/cosimo/varnish-geoip
Last synced: about 2 months ago
JSON representation
Varnish VCL "plugin" that geolocates client IP addresses (requires geoip)
- Host: GitHub
- URL: https://github.com/cosimo/varnish-geoip
- Owner: cosimo
- Created: 2010-01-30T13:57:59.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2016-02-15T10:34:54.000Z (over 8 years ago)
- Last Synced: 2024-07-01T04:48:27.889Z (3 months ago)
- Language: C
- Homepage:
- Size: 30.3 KB
- Stars: 51
- Watchers: 13
- Forks: 14
- Open Issues: 4
-
Metadata Files:
- Readme: README
Awesome Lists containing this project
README
Varnish Geo-IP VCL
===========================Last updated: 28/05/2013
Cosimo Streppone
Opera Software ASAHere you will find a VCL config file for Varnish (http://varnish-cache.org)
This VCL will transparently add a HTTP request header with Geo-IP information
depending on the client IP address that made the request.*** WARNING ***
This VCL consists of C code. Your Varnish might explode. YMMV.
Don't use it in production if you don't know what you're doing.
We are using it in production, but we _don't_ know what we're doing :).Why would you want this?
------------------------
So your backend application can just read a HTTP header and figure out
where the client comes from, city, country and latitude/longitude.
Of course this doesn't come for free. You need the city edition of Geo-IP.The rewritten header is "X-Geo-IP".
X-Geo-IP header content
-----------------------the `X-Geo-IP` header will differ depending on which function
you decide to apply, and what GeoIP database you are using, Country or City
edition.In case of simple country lookup, you will have:
X-Geo-IP: country:US
whereas a failed lookup will return `country:A6`. That is an internal
convention we adopted, of course YMMV.In case of City database, the header will look like:
X-Geo-IP: city:Rome, country:IT, lat:44.2134, lon:12.241, ip:1.2.3.4
(numbers are made up), while in the lookup failed case, you will have:
X-Geo-IP: city:, country:A6, lat:0.0, lon:0.0, ip:1.2.3.4
The invalid/internal IP case is covered by the geoip library itself, so
it should be reported as unknown IP.Requirements
------------- gcc, make
- a recent perl, with `prove'Instructions
-------------1) Run 'make && make test'
You should see "All tests successful" at the end of the execution2) Install the generated geoip.vcl in /etc/varnish/
3) At the top of your main VCL file, add the following line:
include "/etc/varnish/geoip.vcl"
and then in your vcl_recv() add:
C{
vcl_geoip_set_header(sp);
}C4) If you run Debian, look here:
http://www.streppone.it/cosimo/blog/2011/11/how-to-start-up-varnish-with-a-custom-cc_command-on-debian/
for instructions on how to specify a custom "cc_command" in
the Varnish init script.5) Restart Varnish
6) ?
7) Profit !!