diff --git a/README.md b/README.md index 1bf43e5..9721cea 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,28 @@ Description 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). -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 make @@ -33,5 +54,37 @@ http { $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 + "iso_code": + "US" + "names": + { + "de": + "USA" + "en": + "United States" + } + } + } + +$ mmdblookup --file /usr/share/GeoIP/GeoIP2-Country.mmdb --ip 8.8.8.8 country names en + + "United States" +``` diff --git a/config b/config index 8314ff6..f3b982f 100644 --- a/config +++ b/config @@ -7,9 +7,21 @@ ngx_feature_libs=-lmaxminddb if [ $ngx_found = yes ]; then ngx_addon_name=ngx_http_geoip2_module - HTTP_MODULES="$HTTP_MODULES ngx_http_geoip2_module" - NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_geoip2_module.c" - CORE_LIBS="$CORE_LIBS -lmaxminddb" + module_src="$ngx_addon_dir/ngx_http_geoip2_module.c" + + 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 cat << END $0: error: the geoip2 module requires the maxminddb library.