• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

dev-bin/H03-Feb-2020-9268

lib/Apache/H03-Feb-2020-2718

maxmind-db/H03-Feb-2020-

src/H03-May-2022-683558

t/H03-Feb-2020-1,234891

.clang-formatH A D03-Feb-2020106 65

.gitignoreH A D03-Feb-2020429 4342

.gitmodulesH A D03-Feb-202093 43

.perltidyallrcH A D03-Feb-2020213 1211

.tidyallrcH A D03-Feb-2020133 65

.travis.ymlH A D03-Feb-20201.9 KiB5554

CONTRIBUTING.mdH A D03-Feb-2020190 64

Changes.mdH A D03-Feb-20201.6 KiB4834

LICENSEH A D03-Feb-202011.1 KiB203169

Makefile.PLH A D03-Feb-2020788 4029

Makefile.amH A D03-Feb-2020114 63

README.mdH A D03-Feb-20209.8 KiB273189

TESTING.mdH A D03-Feb-20201.6 KiB7345

bootstrapH A D03-Feb-202043 52

configure.acH A D03-Feb-20201.4 KiB5349

cpanfileH A D03-Feb-2020321 1312

README.md

1# MaxMind DB Apache Module #
2
3This module allows you to query MaxMind DB files from Apache 2.2+ using the
4`libmaxminddb` library.
5
6## Requirements ##
7
8This module requires Apache 2.2 or 2.4 to be installed, including any
9corresponding "dev" package, such as `apache2-dev` on Ubuntu. You should have
10`apxs` or `apxs2` in your `$PATH`.
11
12You also must install the [libmaxminddb](https://github.com/maxmind/libmaxminddb)
13C library.
14
15## Installation ##
16
17### From a Named Release Tarball (Recommended) ###
18
19**NOTE:** These instructions are for installation from the _named_ `.tar.gz`
20tarballs on the [Releases](https://github.com/maxmind/mod_maxminddb/releases)
21page (e.g. `mod_maxminddb-*.tar.gz`).
22
23To install the module from a tarball, run the following commands from the
24directory with the extracted source:
25
26    ./configure
27    make install
28
29To use another Apache installation, specify a path to the right apxs binary:
30
31    ./configure --with-apxs=/foo/bar/apxs
32
33### From a GitHub "Source Code" Archive / Git Repo Clone (Achtung!) ###
34
35**NOTE:** These instructions are for installation from the GitHub "Source
36Code" archives also available on the
37[Releases](https://github.com/maxmind/mod_maxminddb/releases) page (e.g.
38`X.Y.Z.zip` or `X.Y.Z.tar.gz`), as well as installation directly from a clone
39of the Git repo. Installation from these sources are possible but will
40present challenges to users not comfortable with manual dependency resolution.
41
421. Ensure the build tools `automake`, `autoconf` and `libtool` are installed.
432. Extract the archive and switch into the directory containing the extracted
44   source.
453. Run `./bootstrap`. Many users will experience challenges here as there are
46   several dependencies that need to be present before this can complete
47   successfully.
484. Run:
49
50        ./configure
51        make install
52
53To use another Apache installation, specify a path to the right apxs binary:
54
55    ./configure --with-apxs=/foo/bar/apxs
56
57## Usage ##
58
59To use this module, you must first download or create a MaxMind DB file. We
60provide [free GeoLite2 databases](https://dev.maxmind.com/geoip/geoip2/geolite2)
61as well as [commercial GeoIP2 databases](https://www.maxmind.com/en/geoip2-databases).
62
63After installing this module and obtaining a database, you must now set up the
64module in your Apache configuration file (e.g., `/etc/apache2/apache2.conf`)
65or in an `.htaccess` file. You must set `MaxMindDBEnable` to enable the
66module, `MaxMindDBFile` to specify the database to use, and `MaxMindDBEnv` to
67bind the desired lookup result to an environment variable.
68You can also enable `MaxMindDBSetNotes` if you wish the environment variables
69to also be set as Apache notes.
70
71This module uses the client IP address for the lookup. This is not always what
72you want. If you need to use an IP address specified in a header (e.g., by
73your proxy frontend),
74[mod_remoteip](https://httpd.apache.org/docs/current/mod/mod_remoteip.html) may
75be used to set the client IP address.
76
77Manually setting the client IP address is also possible. See
78[Client IP address lookup control](#client-ip-address-lookup-control).
79
80## Directives ##
81
82All directives may appear either in your server configuration or an
83`.htaccess` file. Directives in `<Location>` and `<Directory>` blocks will
84also apply to sub-locations and subdirectories. The configuration will be
85merged with the most specific taking precedence. For instance, a conflicting
86directive set for a subdirectory will be used for the subdirectory rather
87than the directive set for the parent location.
88
89Similarly, the main server configuration may set defaults that will be merged
90into the configuration provided by individual virtual hosts. However, please
91note that currently no configuration merging is performed between server/vhost
92and directory configurations.
93
94### `MaxMindDBEnable` ###
95
96This directive enables or disables the MaxMind DB lookup. Valid settings are
97`On` and `Off`.
98
99    MaxMindDBEnable On
100
101### `MaxMindDBFile` ###
102
103This directive associates a name placeholder with a MaxMind DB file on the
104disk. You may specify multiple databases, each with its own name.
105
106    MaxMindDBFile COUNTRY_DB /usr/local/share/GeoIP/GeoLite2-Country.mmdb
107    MaxMindDBFile CITY_DB    /usr/local/share/GeoIP/GeoLite2-City.mmdb
108
109The name placeholder can be any string that Apache parses as a word. We
110recommend sticking to letters, numbers, and underscores.
111
112### `MaxMindDBEnv` ###
113
114This directive assigns the lookup result to an environment variable. The first
115parameter after the directive is the environment variable. The second
116parameter is the name of the database followed by the path to the desired data
117using map keys or 0-based array indexes separated by `/`.
118
119    MaxMindDBEnv COUNTRY_CODE COUNTRY_DB/country/iso_code
120    MaxMindDBEnv REGION_CODE  CITY_DB/subdivisions/0/iso_code
121
122### `MaxMindDBNetworkEnv` ###
123
124This directive assigns the network associated with the IP address to an
125environment variable. The network will be in CIDR format. This directive
126may only be used once per database.
127
128    MaxMindDBNetworkEnv COUNTRY_DB COUNTRY_NETWORK
129    MaxMindDBNetworkEnv CITY_DB    CITY_NETWORK
130
131### `MaxMindDBSetNotes` ###
132
133This directive enables or disables the setting of Apache notes alongside the
134environment variables set via `MaxMindDBEnv`. Valid settings are `On` and `Off`.
135It defaults to `Off`.
136
137    MaxMindDBSetNotes On
138
139## Exported Environment Variables ##
140
141In addition to the environment variable specified by `MaxMindDBEnv`, this
142module exports `MMDB_ADDR`, which contains the IP address used for lookups by
143the module. This is primarily intended for debugging purposes.
144If `MaxMindDBSetNotes` is `On`, all environment variables are also exported as
145Apache notes.
146
147## Client IP address lookup control ##
148
149In case you want supply your own value for the IP address to lookup, it may be
150done by setting the environment variable `MMDB_ADDR`.
151This can be done, for instance, with
152[ModSecurity](https://github.com/SpiderLabs/ModSecurity/) in (real) phase 1.
153Note that mod_setenvif and mod_rewrite cannot be used for this as they are
154running after this module. For most usages,
155[mod_remoteip](https://httpd.apache.org/docs/current/mod/mod_remoteip.html)
156is an easier alternative.
157
158## Examples ##
159
160These examples show how to export data from the database into environment
161variables.
162
163### ASN Database ###
164
165    <IfModule mod_maxminddb.c>
166        MaxMindDBEnable On
167        MaxMindDBFile ASN_DB /usr/local/share/GeoIP/GeoLite2-ASN.mmdb
168
169        MaxMindDBEnv MM_ASN ASN_DB/autonomous_system_number
170        MaxMindDBEnv MM_ASORG ASN_DB/autonomous_system_organization
171
172        MaxMindDBNetworkEnv ASN_DB ASN_DB_NETWORK
173    </IfModule>
174
175### City Database ###
176
177    <IfModule mod_maxminddb.c>
178        MaxMindDBEnable On
179        MaxMindDBFile CITY_DB /usr/local/share/GeoIP/GeoLite2-City.mmdb
180
181        MaxMindDBEnv MM_COUNTRY_CODE CITY_DB/country/iso_code
182        MaxMindDBEnv MM_COUNTRY_NAME CITY_DB/country/names/en
183        MaxMindDBEnv MM_CITY_NAME CITY_DB/city/names/en
184        MaxMindDBEnv MM_LONGITUDE CITY_DB/location/longitude
185        MaxMindDBEnv MM_LATITUDE CITY_DB/location/latitude
186
187        MaxMindDBNetworkEnv CITY_DB CITY_DB_NETWORK
188    </IfModule>
189
190### Connection-Type Database ###
191
192    <IfModule mod_maxminddb.c>
193        MaxMindDBEnable On
194        MaxMindDBFile CONNECTION_TYPE_DB /usr/local/share/GeoIP/GeoIP2-Connection-Type.mmdb
195
196        MaxMindDBEnv MM_CONNECTION_TYPE CONNECTION_TYPE_DB/connection_type
197
198        MaxMindDBNetworkEnv CONNECTION_TYPE_DB CONNECTION_TYPE_DB_NETWORK
199    </IfModule>
200
201### Domain Database ###
202
203    <IfModule mod_maxminddb.c>
204        MaxMindDBEnable On
205        MaxMindDBFile DOMAIN_DB /usr/local/share/GeoIP/GeoIP2-Domain.mmdb
206
207        MaxMindDBEnv MM_DOMAIN DOMAIN_DB/domain
208
209        MaxMindDBNetworkEnv DOMAIN_DB DOMAIN_DB_NETWORK
210    </IfModule>
211
212### ISP Database ###
213
214    <IfModule mod_maxminddb.c>
215        MaxMindDBEnable On
216        MaxMindDBFile ISP_DB /usr/local/share/GeoIP/GeoIP2-ISP.mmdb
217
218        MaxMindDBEnv MM_ASN ISP_DB/autonomous_system_number
219        MaxMindDBEnv MM_ASORG ISP_DB/autonomous_system_organization
220        MaxMindDBEnv MM_ISP ISP_DB/isp
221        MaxMindDBEnv MM_ORG ISP_DB/organization
222
223        MaxMindDBNetworkEnv ISP_DB ISP_DB_NETWORK
224    </IfModule>
225
226### Blocking by Country ###
227
228This example shows how to block users based on their country:
229
230    MaxMindDBEnable On
231    MaxMindDBFile DB /usr/local/share/GeoIP/GeoLite2-Country.mmdb
232    MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code
233
234    SetEnvIf MM_COUNTRY_CODE ^(RU|DE|FR) BlockCountry
235    Deny from env=BlockCountry
236
237Note that at least the "Deny" or "Allow" directive (or "Require" directive in
238Apache 2.4 and above) must be applied within a `<Directory>`, `<Location>` or
239`<Files>` container.
240
241## Data Output Format ##
242
243All data is provided as a string bound to the specified Apache environment
244variable. Floating point numbers are provided to five digits after the decimal
245place. All integers types except 128-bit integers are provided as decimal.
246128-bit integers are returned as hexadecimal. Booleans are returned as "0" for
247false and "1" for true.
248
249Note that data stored as the "bytes" type in a MaxMind DB database can contain
250null bytes and may end up truncated when stored in an environment variable. If
251you really need to access this data, we recommend using [one of our
252programming language
253APIs](https://dev.maxmind.com/geoip/geoip2/downloadable/#MaxMind_APIs) instead.
254
255## Support ##
256
257Please report all issues with this code using the [GitHub issue
258tracker](https://github.com/maxmind/mod_maxminddb/issues).
259
260If you are having an issue with a commercial MaxMind database that is not
261specific to this module, please see [our support
262page](https://www.maxmind.com/en/support).
263
264## Versioning ##
265
266The MaxMind DB Apache module uses [Semantic Versioning](https://semver.org/).
267
268## Copyright and License ##
269
270This software is Copyright (c) 2013-2020 by MaxMind, Inc.
271
272This is free software, licensed under the Apache License, Version 2.0.
273