2

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.

Mr.
  • 9,429
  • 13
  • 58
  • 82
  • Unfortunately, dynamic modules are not as independent as many would like them to be. You can load a module only if the main binary file is aware of this module. And that is the case only when you use the same Nginx binary you built the module with. If you had typed `make install` being root, the `make` tool would've replaced your system Nginx binary file with your copy and everything would've worked. But juding by the shell prompt and lack of `sudo`, you ran `make install` without superuser privileges. As a result the system Nginx binary file, incompatible with your module, remained in place. – Ivan Tsirulev Jan 21 '17 at 22:31
  • @IvanTsirulev: i am sorry i wasn't clear enough, i was running the commands as a `root` user and that is why i didn't include the `sudo` command (yes, i know it is not a good practice). i will edit the post to make it clear. anyhow, the problem remains. do you have anything else in mind? – Mr. Jan 21 '17 at 22:44
  • Could you check if these two checksums are the same: `openssl sha1 /usr/sbin/nginx` and `openssl sha1 /tmp/nginx-1.10.2/objs/nginx`? – Ivan Tsirulev Jan 22 '17 at 09:09
  • You have to use all the same configure options that the nginx binary was compiled with., ie everything that nginx -V says. Thats typically the cause of that error is when those options dont match up. – Faisal Memon Jan 22 '17 at 18:30
  • @IvanTsirulev: i've updated the post. – Mr. Jan 27 '17 at 11:06
  • 1
    @FaisalMemon: i knew, and as i mentioned i am collection all the configuration parameters by copying the output of `nginx -V` command, and providing them to the `configure` command on the nginx source – Mr. Jan 27 '17 at 11:08
  • As you can see, `make install` didn't replace the system Nginx with the newly built one. And as already mentioned above, the system Nginx is incompatible with your module. So all you have to do is to manually replace the file: `sudo mv -f /tmp/nginx-1.10.2/objs/nginx /usr/sbin/nginx`. – Ivan Tsirulev Jan 27 '17 at 14:22
  • @IvanTsirulev: that was the sha output before `make install` (i will update the post to eliminate any future confusion). though, after it the sha is the same. – Mr. Jan 27 '17 at 15:47

0 Answers0