Feature: nginx dynamic module support

This commit is contained in:
Lee Valentine 2016-02-10 20:43:08 +00:00
parent eb8a26df11
commit 0373635e22
2 changed files with 69 additions and 4 deletions

View file

@ -7,7 +7,28 @@ Description
First install [libmaxminddb](https://github.com/maxmind/libmaxminddb) as described in its [README.md First install [libmaxminddb](https://github.com/maxmind/libmaxminddb) as described in its [README.md
file](https://github.com/maxmind/libmaxminddb/blob/master/README.md#installing-from-a-tarball). file](https://github.com/maxmind/libmaxminddb/blob/master/README.md#installing-from-a-tarball).
Compile nginx: #### Download nginx source
```
wget http://nginx.org/nginx-VERSION.tar.gz
tar zxvf nginx-VERSION.tar.gz
cd nginx-VERSION
```
##### To build as a dynamic module (nginx 1.9.11+):
```
./configure --add-dynamic-module=/path/to/ngx_http_geoip2_module
make
make install
```
This will produce ```objs/ngx_http_geoip2_module.so```. It can be copied to your nginx module path manually if you wish.
Add the following line to your nginx.conf:
```
load_module modules/ngx_http_geoip2_module.so;
```
##### To build as a static module:
``` ```
./configure --add-module=/path/to/ngx_http_geoip2_module ./configure --add-module=/path/to/ngx_http_geoip2_module
make make
@ -33,5 +54,37 @@ http {
$geoip2_data_city_name default=London city names en; $geoip2_data_city_name default=London city names en;
} }
.... ....
fastcgi_param COUNTRY_CODE $geoip2_data_country_code;
fastcgi_param COUNTRY_NAME $geoip2_data_country_name;
fastcgi_param CITY_NAME $geoip2_data_city_name;
....
} }
``` ```
To find the path of the data you want (eg: city names en), use the [mmdblookup tool](https://maxmind.github.io/libmaxminddb/mmdblookup.html):
```
$ mmdblookup --file /usr/share/GeoIP/GeoIP2-Country.mmdb --ip 8.8.8.8
{
"country":
{
"geoname_id":
6252001 <uint32>
"iso_code":
"US" <utf8_string>
"names":
{
"de":
"USA" <utf8_string>
"en":
"United States" <utf8_string>
}
}
}
$ mmdblookup --file /usr/share/GeoIP/GeoIP2-Country.mmdb --ip 8.8.8.8 country names en
"United States" <utf8_string>
```

18
config
View file

@ -7,9 +7,21 @@ ngx_feature_libs=-lmaxminddb
if [ $ngx_found = yes ]; then if [ $ngx_found = yes ]; then
ngx_addon_name=ngx_http_geoip2_module ngx_addon_name=ngx_http_geoip2_module
HTTP_MODULES="$HTTP_MODULES ngx_http_geoip2_module" module_src="$ngx_addon_dir/ngx_http_geoip2_module.c"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_geoip2_module.c"
CORE_LIBS="$CORE_LIBS -lmaxminddb" if test -n "$ngx_module_link"; then
ngx_module_type=HTTP
ngx_module_name="$ngx_addon_name"
ngx_module_incs=
ngx_module_deps=
ngx_module_srcs="$module_src"
ngx_module_libs="$ngx_feature_libs"
. auto/module
else
HTTP_MODULES="$HTTP_MODULES $ngx_addon_name"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $module_src"
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
fi
else else
cat << END cat << END
$0: error: the geoip2 module requires the maxminddb library. $0: error: the geoip2 module requires the maxminddb library.