nginx does not come with support for geoip2
. on the nginx documentation there is a reference for a geoip2 3d party module, so i thought to give it a try, but i guess there is something that i am missing.
here are some details of the machine i am working on:
$ cat /etc/*release* | grep -i dist
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"
$ dpkg -l | grep -i nginx
ii nginx 1.10.2-1~xenial amd64 high performance web server
these are the step that i took in order to compile geoip2
module:
$ cd /tmp
/tmp$ wget https://github.com/maxmind/libmaxminddb/releases/download/1.2.0/libmaxminddb-1.2.0.tar.gz
/tmp$ tar xvzf libmaxminddb-1.2.0.tar.gz
/tmp$ apt-get install dh-autoreconf build-essential automake
/tmp$ cd libmaxminddb*
/tmp/libmaxminddb-1.2.0$ ./configure
/tmp/libmaxminddb-1.2.0$ make check
/tmp/libmaxminddb-1.2.0$ make install
/tmp/libmaxminddb-1.2.0$ ldconfig
/tmp/libmaxminddb-1.2.0:$ cd ..
/tmp$ wget https://github.com/leev/ngx_http_geoip2_module/archive/2.0.tar.gz -O ngx_http_geoip2_module-2.0.tar.gz
/tmp$ tar xvzf ngx_http_geoip2_module*.tar.gz
/tmp$ VERSION=`dpkg -l | grep -i nginx | awk '{print $3}' | cut -d - -f 1`
/tmp$ wget https://nginx.org/download/nginx-${VERSION}.tar.gz
/tmp$ tar xvzf nginx-${VERSION}.tar.gz
/tmp$ cd nginx*
/tmp/nginx-1.10.2$ nginx -V # finding configuration flags
/tmp/nginx-1.10.2$ ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-file-aio --with-threads --with-ipv6 --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed' --add-dynamic-module=/tmp/ngx_http_geoip2_module-2.0
/tmp/nginx-1.10.2$ make
/tmp/nginx-1.10.2$ make install
and these are the steps i did to dynamically load geoip2
module in nginx
:
$ mv /tmp/nginx-1.10.2/objs/ngx_http_geoip2_module.so /etc/nginx/modules/
# placing a configuration
$ cat /etc/nginx/conf.d/http_geoip.conf
geoip2 /usr/share/GeoIP/GeoIP2-City.mmdb {
$geoip2_data_city_name default=NA city names zh-CN;
$geoip2_data_country_name default=NA country names zh-CN;
$geoip2_data_country_code default=NA country is_code;
$geoip2_data_status default=NA subdivisions 0 names zh-CN;
$geoip2_data_zip default=NA postal code;
}
$ cat -n /etc/nginx/nginx.conf | grep -i load_module
4 load_module modules/ngx_http_geoip2_module.so;
when i restart nginx
service i get the following error:
nginx: [emerg] module "/etc/nginx/modules/ngx_http_geoip2_module.so" is not binary compatible in /etc/nginx/nginx.conf:4
does any one have a lead?
UPDATE:
all of the commands above were executed under a root
user, and thus sudo
commands do not appear in the snippets above.
UPDATE 2:
per to the comments, i'm adding the sha1 of the nginx binaries before executing make install
:
# openssl sha1 /usr/sbin/nginx && openssl sha1 /tmp/nginx-1.10.2/objs/nginx
SHA1(/usr/sbin/nginx)= bef34e8fc1366cd831a3c61b0773af14c75f63d8
SHA1(/tmp/nginx-1.10.2/objs/nginx)= bd955d6b372f803c1527a8abf91f40fe9b3ffa89
and this is the same after executing make install
# openssl sha1 /usr/sbin/nginx && openssl sha1 /tmp/nginx-1.10.2/objs/nginx
SHA1(/usr/sbin/nginx)= bd955d6b372f803c1527a8abf91f40fe9b3ffa89
SHA1(/tmp/nginx-1.10.2/objs/nginx)= bd955d6b372f803c1527a8abf91f40fe9b3ffa89
the sha digest is different, indicating on a different binaries. i guess it should be different if some changes where introduced and the compilation results in a new different binary.
i can see that when configure
command is executed (as specified above) in the nginx
directory, it outputs that it found the geoip2
as dynamic module. here is the output:
configuring additional dynamic modules
adding module in /tmp/ngx_http_geoip2_module-2.0
checking for MaxmindDB library ... found
+ ngx_geoip2_module was configured
any ideas?
SOLVED: the problem was resolved when i repeated the steps on a fresh new ubuntu machine.