Skip to content

Commit 0373635

Browse files
committed
Feature: nginx dynamic module support
1 parent eb8a26d commit 0373635

File tree

2 files changed

+69
-4
lines changed

2 files changed

+69
-4
lines changed

README.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,28 @@ Description
77
First install [libmaxminddb](https://github.com/maxmind/libmaxminddb) as described in its [README.md
88
file](https://github.com/maxmind/libmaxminddb/blob/master/README.md#installing-from-a-tarball).
99

10-
Compile nginx:
10+
#### Download nginx source
11+
```
12+
wget http://nginx.org/nginx-VERSION.tar.gz
13+
tar zxvf nginx-VERSION.tar.gz
14+
cd nginx-VERSION
15+
```
16+
17+
##### To build as a dynamic module (nginx 1.9.11+):
18+
```
19+
./configure --add-dynamic-module=/path/to/ngx_http_geoip2_module
20+
make
21+
make install
22+
```
23+
24+
This will produce ```objs/ngx_http_geoip2_module.so```. It can be copied to your nginx module path manually if you wish.
25+
26+
Add the following line to your nginx.conf:
27+
```
28+
load_module modules/ngx_http_geoip2_module.so;
29+
```
30+
31+
##### To build as a static module:
1132
```
1233
./configure --add-module=/path/to/ngx_http_geoip2_module
1334
make
@@ -33,5 +54,37 @@ http {
3354
$geoip2_data_city_name default=London city names en;
3455
}
3556
....
57+
58+
fastcgi_param COUNTRY_CODE $geoip2_data_country_code;
59+
fastcgi_param COUNTRY_NAME $geoip2_data_country_name;
60+
fastcgi_param CITY_NAME $geoip2_data_city_name;
61+
....
3662
}
3763
```
64+
65+
To find the path of the data you want (eg: city names en), use the [mmdblookup tool](https://maxmind.github.io/libmaxminddb/mmdblookup.html):
66+
67+
```
68+
$ mmdblookup --file /usr/share/GeoIP/GeoIP2-Country.mmdb --ip 8.8.8.8
69+
70+
{
71+
"country":
72+
{
73+
"geoname_id":
74+
6252001 <uint32>
75+
"iso_code":
76+
"US" <utf8_string>
77+
"names":
78+
{
79+
"de":
80+
"USA" <utf8_string>
81+
"en":
82+
"United States" <utf8_string>
83+
}
84+
}
85+
}
86+
87+
$ mmdblookup --file /usr/share/GeoIP/GeoIP2-Country.mmdb --ip 8.8.8.8 country names en
88+
89+
"United States" <utf8_string>
90+
```

config

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,21 @@ ngx_feature_libs=-lmaxminddb
77

88
if [ $ngx_found = yes ]; then
99
ngx_addon_name=ngx_http_geoip2_module
10-
HTTP_MODULES="$HTTP_MODULES ngx_http_geoip2_module"
11-
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_geoip2_module.c"
12-
CORE_LIBS="$CORE_LIBS -lmaxminddb"
10+
module_src="$ngx_addon_dir/ngx_http_geoip2_module.c"
11+
12+
if test -n "$ngx_module_link"; then
13+
ngx_module_type=HTTP
14+
ngx_module_name="$ngx_addon_name"
15+
ngx_module_incs=
16+
ngx_module_deps=
17+
ngx_module_srcs="$module_src"
18+
ngx_module_libs="$ngx_feature_libs"
19+
. auto/module
20+
else
21+
HTTP_MODULES="$HTTP_MODULES $ngx_addon_name"
22+
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $module_src"
23+
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
24+
fi
1325
else
1426
cat << END
1527
$0: error: the geoip2 module requires the maxminddb library.

0 commit comments

Comments
 (0)