-
Notifications
You must be signed in to change notification settings - Fork 25
/
README
144 lines (103 loc) · 3.4 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
==========
geoip-vmod
==========
---------------------------
Varnish GeoIP Module
---------------------------
:Author: Lee Doolan
SYNOPSIS
========
import geoip;
DESCRIPTION
===========
This Varnish module lets you add VCL that sets the request header
X-GeoIP based on the geolocalization of the given IP address.
Requires GeoIP library (on Debian install libgeoip-dev).
INSTALLATION
============
The source tree is based on autotools to configure the building, and
does also have the necessary bits in place to do functional unit tests
using the varnishtest tool.
Install the GeoIP library headers::
apt-get install libgeoip-dev pkg-config
To check out the current development source::
git clone git://github.com/leed25d/geoip-vmod.git
cd geoip-vmod; ./autogen.sh
Usage:
./configure VARNISHSRC=DIR
VARNISHSRC is the directory of the Varnish source tree for which to
compile your vmod. Both the VARNISHSRC and VARNISHSRC/include
will be added to the include search paths for your module.
Make targets:
make - builds the vmod
make install - installs your vmod in VMODDIR
make check - runs the unit tests in src/tests/*.vtc
In your VCL you could then use this vmod like the following. This
sets the request header X-GeoIP to the requestor's geo (or Unknown).
,----
| import geoip;
|
| sub vcl_recv {
| set req.http.X-Forwarded-For = client.ip;
| set req.http.X-GeoIP = geoip.country_code(req.http.X-Forwarded-For);
| }
`----
,----
| import geoip;
|
| sub vcl_recv {
| set req.http.X-GeoIP = geoip.country_code_from_ip(client.ip);
| }
`----
If the given IP is invalid, or cannot be found in the database, the returned
country code is "AA", which is an invalid country code used in this module
to indicate an error.
FUNCTIONS
=========
country_code
------------
Prototype
STRING country_code(STRING)
Returns the country code (or "AA", if the given IP is invalid, a country
code can not be found).
country_code_from_ip
--------------------
Prototype
STRING country_code_from_ip(IP)
Just like country_code, but takes an IP as argument instead of a string.
organization
------------
STRING organization(STRING)
Returns the organization (or "Unknown organization" if the given IP is
invalid, an organization can not be found or the organization database could
not be found).
organization_from_ip
--------------------
STRING organization_from_ip(IP]
Just like organization, but takes an IP as argument instead of a string.
region
------
STRING region(STRING)
Returns the region (or "Unknown region" if the given IP is invalid, an
region can not be found or the region database could not be found).
region_from_ip
--------------
STRING region_from_ip(STRING)
Just like region, but takes an IP as argument instead of a string.
HISTORY
=======
Manpage based on the libvmod-example by Varnish Software and tHauke Lampe's
own GeoIP Vmod on https://github.com/lampeh/libvmod-geoip
CREDITS
=======
The idea for this varnish module and the proof of concept and the
initial implementation are all due to David Newhall II
Lee Doolan, the maintainer, added libtool configuration details,
added thread safety, added SCM (git). Stability patch provided by Varnish
Software.
COPYRIGHT
=========
This document is licensed under the same license as the
libvmod-example project. See LICENSE for details.
* Copyright (c) 2011 Livejounal
* Copyright (c) 2012 Varnish Software