Giter Club home page Giter Club logo

ngx_http_geoip2_module's People

Contributors

calio avatar cloudwindy avatar cvhoang avatar defanator avatar guizmaii avatar hnakamur avatar leev avatar mohamedlamineallal avatar oschwald avatar qleein avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ngx_http_geoip2_module's Issues

Will not compile against nginx 1.11.3

It looks like the signature for ngx_http_get_forwarded_addr changed between 1.11.1 and 1.11.3 and the latest release (1.1) will not compile against it.

Build Failure:

ngx_http2_geoip2_module/ngx_http_geoip2_module.c: In function ‘ngx_http_geoip2_variable’:
ngx_http2_geoip2_module/ngx_http_geoip2_module.c:147:44: error: too few arguments to function ‘ngx_http_get_forwarded_addr’
                                            gcf->proxies, gcf->proxy_recursive);
                                            ^
In file included from src/http/ngx_http.h:39:0,
                 from ngx_http2_geoip2_module/ngx_http_geoip2_module.c:10:
src/http/ngx_http_core_module.h:542:11: note: declared here
 ngx_int_t ngx_http_get_forwarded_addr(ngx_http_request_t *r, ngx_addr_t *addr,
           ^
make[1]: *** [objs/addon/ngx_http2_geoip2_module/ngx_http_geoip2_module.o] Error 1
make[1]: *** Waiting for unfinished jobs....

I was able to get a successful build by changing the call to:

        (void) ngx_http_get_forwarded_addr(r, &addr, xfwd, NULL,
                                           gcf->proxies, gcf->proxy_recursive, NULL);

but I have yet to test and I haven't dug into what that new parameter does.

Undefined symbol "ngx_stream_complex_value"

Hi, I am not sure if this is the right place to ask this question. For a long while now, I have been unable to load into Nginx the dynamic module ngx_stream_geoip2_module.so with the following error in the nginx log:

nginx: [emerg] dlopen() "/usr/local/libexec/nginx/ngx_stream_geoip2_module.so" failed (/usr/local/libexec/nginx/ngx_stream_geoip2_module.so: Undefined symbol "ngx_stream_complex_value") in /usr/local/etc/nginx/nginx.conf:9
nginx: configuration file /usr/local/etc/nginx/nginx.conf test failed

I run www/nginx-devel port on FreeBSD, and when I tried building/using your module, I've always got this error (it persisted through a few updates already). All the other modules I tried so far work without problem and I wonder what is missing.

Thanks in advance.

NGINX Error - MaxMind DB file contains invalid metadata

I've set up NGINX (compiled from source with --add-module=/path/to/ngx_http_geoip2_module) + PHP-FPM. Before I did this I followed the instructions for Installing Libmaxminddb and everything seemed to work out ok.

I then attempted to setup GEOIP functionality so I added the following to the NGINX configuration file (nginx.conf)

http {
    ...
    geoip2 /etc/maxmind-country.mmdb {
        $geoip2_data_country_code default=US country iso_code;
        $geoip2_data_country_name country names en;
    }

    geoip2 /etc/maxmind-city.mmdb {
        $geoip2_data_city_name default=London city names en;
    }
    ....
}

However, when I start NGINX I get the following error:

nginx: [emerg] MMDB_open("/root/src/maxmind/maxminddb/GeoLite2-Country.mmdb") failed - The MaxMind DB file contains invalid metadata

Any indication as to what may be wrong? Is there something else I'm supposed to setup to get this working properly?

Note: I'm on Ubuntu 12.04 64-bit Desktop

Issues with non string values

I am having problems getting the lat, long, and metro_code values from the geoip2 module, but I am not sure if it's a bug or if I am doing something wrong.

Is there a specific way I should be getting these values or is there something else going on?

versions
# nginx-1.7.4
# ngx_http_geoip2_module 
# =>  bd530bc Added support for using multiple maxmind databases
# libmaxminddb => 1.0.1 - 2014-09-03 
# geoipupdate-2.0.2 from source with latest db update as of 11-SEP-2014
# Debian 7.6 (wheezy)

In /etc/nginx/nginx.conf

http {
...
    geoip2 /usr/local/share/GeoIP/GeoIP2-City.mmdb {
        $geoip2_city_name city names en;
        $geoip2_continent_code default=NA continent code;
        $geoip2_continent_name continent names en;
        $geoip2_country_code default=US country iso_code;
        $geoip2_country_name country names en;
        $geoip2_lat location latitude;
        $geoip2_long location longitude;
        $geoip2_metro_code location metro_code;
        $geoip2_time_zone location time_zone;
        $geoip2_state_code subdivisions iso_code iso_code;
        $geoip2_state_name subdivisions names names en;
  }

  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
}

site config snip

location /geoip/test {
  try_files $uri @unicorn;
}

location @unicorn {
  error_log /var/log/nginx/unicorn_location.log debug;
  proxy_pass http://unicorn;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $http_host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_redirect off;

  # set geoip2 headers
  proxy_set_header GEOIP2_CONTINENT_CODE $geoip2_continent_code;
  proxy_set_header GEOIP2_CONTINENT_NAME $geoip2_continent_name;
  proxy_set_header GEOIP2_COUNTRY_CODE $geoip2_country_code;
  proxy_set_header GEOIP2_COUNTRY_NAME $geoip2_country_name;
  proxy_set_header GEOIP2_CITY_NAME $geoip2_city_name;
  proxy_set_header GEOIP2_LATITUDE $geoip2_latitude;
  proxy_set_header GEOIP2_LONGITUDE $geoip2_longitude;
  proxy_set_header GEOIP2_METRO_CODE $geoip2_metro_code;
  proxy_set_header GEOIP2_TIME_ZONE $geoip2_time_zone;
  proxy_set_header GEOIP2_STATE_CODE $geoip2_state_code;
  proxy_set_header GEOIP2_STATE_NAME $geoip2_state_name;
}

Everything but latitude, longitude, and metro_code works (all non string return values). I have tried interpolating variables in multiple spots (single/double quotes, set, etc) without luck. Setting default values of anything but quoted longitude/latitude double's causes 500 errors.

Request data from the backend server
# BACKEND REQUEST DATA (missing lat, long, and metro_code, but has location time_zone)
REMOTE_ADDR                   =>  127.0.0.1
REQUEST_METHOD                =>  GET
REQUEST_PATH                  =>  /geoip/test
SERVER_PROTOCOL               =>  HTTP/1.0
HTTP_VERSION                  =>  HTTP/1.0
HTTP_X_FORWARDED_FOR          =>  70.112.69.240
HTTP_HOST                     =>  geoip2-test
HTTP_X_REAL_IP                =>  70.112.69.240
HTTP_GEOIP2_CONTINENT_CODE    =>  NA
HTTP_GEOIP2_CONTINENT_NAME    =>  North America
HTTP_GEOIP2_COUNTRY_CODE      =>  US
HTTP_GEOIP2_COUNTRY_NAME      =>  United States
HTTP_GEOIP2_CITY_NAME         =>  Austin
HTTP_GEOIP2_TIME_ZONE         =>  America/Chicago
HTTP_GEOIP2_STATE_CODE        =>  TX
HTTP_GEOIP2_STATE_NAME        =>  Texas
HTTP_CONNECTION               =>  close
HTTP_ACCEPT                   =>  */*
HTTP_ACCEPT_LANGUAGE          =>  en-us
HTTP_ACCEPT_ENCODING          =>  gzip, deflate
mmdblookup on the server
%> mmdblookup --file /usr/local/share/GeoIP/GeoIP2-City.mmdb --ip 70.112.69.240 country names en

  "United States" <utf8_string>

$> mmdblookup --file /usr/local/share/GeoIP/GeoIP2-City.mmdb --ip 70.112.69.240 location latitude

  30.320500 <double>

$> mmdblookup --file /usr/local/share/GeoIP/GeoIP2-City.mmdb --ip 70.112.69.240 location metro_code

  635 <uint16>
%> nginx -V

nginx version: nginx/1.7.4
built by gcc 4.7.2 (Debian 4.7.2-5)
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --pid-path=/var/run/nginx.pid --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-http_addition_module --with-http_geoip_module --with-http_gzip_static_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --add-module=/root/source/ngx_http_geoip2_module --add-module=/root/source/echo-nginx-module-0.56
debug log for completeness
%> cat /var/log/nginx/geoip2_debug.log
2014/09/12 01:01:44 [debug] 12303#0: *7 rewrite phase: 3
2014/09/12 01:01:44 [debug] 12303#0: *7 post rewrite phase: 4
2014/09/12 01:01:44 [debug] 12303#0: *7 generic phase: 5
2014/09/12 01:01:44 [debug] 12303#0: *7 generic phase: 6
2014/09/12 01:01:44 [debug] 12303#0: *7 generic phase: 7
2014/09/12 01:01:44 [debug] 12303#0: *7 access phase: 8
2014/09/12 01:01:44 [debug] 12303#0: *7 access phase: 9
2014/09/12 01:01:44 [debug] 12303#0: *7 post access phase: 10
2014/09/12 01:01:44 [debug] 12303#0: *7 try files phase: 11
2014/09/12 01:01:44 [debug] 12303#0: *7 http init upstream, client timer: 0
2014/09/12 01:01:44 [debug] 12303#0: *7 epoll add event: fd:11 op:3 ev:80002005
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "X-Forwarded-For: "
2014/09/12 01:01:44 [debug] 12303#0: *7 http script var: "70.112.69.240"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "
"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "Host: "
2014/09/12 01:01:44 [debug] 12303#0: *7 http script var: "geoip2-stage"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "
"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "X-Real-IP: "
2014/09/12 01:01:44 [debug] 12303#0: *7 http script var: "70.112.69.240"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "
"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "GEOIP2_CONTINENT_CODE: "
2014/09/12 01:01:44 [debug] 12303#0: *7 http script var: "NA"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "
"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "GEOIP2_CONTINENT_NAME: "
2014/09/12 01:01:44 [debug] 12303#0: *7 http script var: "North America"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "
"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "GEOIP2_COUNTRY_CODE: "
2014/09/12 01:01:44 [debug] 12303#0: *7 http script var: "US"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "
"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "GEOIP2_COUNTRY_NAME: "
2014/09/12 01:01:44 [debug] 12303#0: *7 http script var: "United States"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "
"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "GEOIP2_CITY_NAME: "
2014/09/12 01:01:44 [debug] 12303#0: *7 http script var: "Austin"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "
"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: ""
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: ""
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: ""
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: ""
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: ""
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: ""
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "GEOIP2_TIME_ZONE: "
2014/09/12 01:01:44 [debug] 12303#0: *7 http script var: "America/Chicago"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "
"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "GEOIP2_STATE_CODE: "
2014/09/12 01:01:44 [debug] 12303#0: *7 http script var: "TX"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "
"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "GEOIP2_STATE_NAME: "
2014/09/12 01:01:44 [debug] 12303#0: *7 http script var: "Texas"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "
"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: "Connection: close
"
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: ""
2014/09/12 01:01:44 [debug] 12303#0: *7 http script copy: ""
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy header: "Accept-Encoding: gzip, deflate"
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy header: "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy header: "Accept-Language: en-us"
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy header: "Cache-Control: max-age=0"
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy header: "DNT: 1"
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy header: "User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53"
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy header:
"GET /geoip/test HTTP/1.0
X-Forwarded-For: 70.112.69.240
Host: geoip2-stage
X-Real-IP: 70.112.69.240
GEOIP2_CONTINENT_CODE: NA
GEOIP2_CONTINENT_NAME: North America
GEOIP2_COUNTRY_CODE: US
GEOIP2_COUNTRY_NAME: United States
GEOIP2_CITY_NAME: Austin
GEOIP2_TIME_ZONE: America/Chicago
GEOIP2_STATE_CODE: TX
GEOIP2_STATE_NAME: Texas
Connection: close
Accept-Encoding: gzip, deflate
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us
Cache-Control: max-age=0
DNT: 1
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53

"
2014/09/12 01:01:44 [debug] 12303#0: *7 http cleanup add: 0000000002657258
2014/09/12 01:01:44 [debug] 12303#0: *7 get rr peer, try: 1
2014/09/12 01:01:44 [debug] 12303#0: *7 socket 12
2014/09/12 01:01:44 [debug] 12303#0: *7 epoll add connection: fd:12 ev:80002005
2014/09/12 01:01:44 [debug] 12303#0: *7 connect to unix:/var/www/geoip2-stage/shared/tmp/sockets/unicorn.socket, fd:12 #8
2014/09/12 01:01:44 [debug] 12303#0: *7 connected
2014/09/12 01:01:44 [debug] 12303#0: *7 http upstream connect: 0
2014/09/12 01:01:44 [debug] 12303#0: *7 posix_memalign: 00000000026096A0:128 @16
2014/09/12 01:01:44 [debug] 12303#0: *7 http upstream send request
2014/09/12 01:01:44 [debug] 12303#0: *7 chain writer buf fl:1 s:692
2014/09/12 01:01:44 [debug] 12303#0: *7 chain writer in: 0000000002657290
2014/09/12 01:01:44 [debug] 12303#0: *7 writev: 692
2014/09/12 01:01:44 [debug] 12303#0: *7 chain writer out: 0000000000000000
2014/09/12 01:01:44 [debug] 12303#0: *7 event timer add: 12: 60000:1410501764404
2014/09/12 01:01:44 [debug] 12303#0: *7 http finalize request: -4, "/geoip/test?" a:1, c:3
2014/09/12 01:01:44 [debug] 12303#0: *7 http request count:3 blk:0
2014/09/12 01:01:44 [debug] 12303#0: *7 http finalize request: -4, "/geoip/test?" a:1, c:2
2014/09/12 01:01:44 [debug] 12303#0: *7 http request count:2 blk:0
2014/09/12 01:01:44 [debug] 12303#0: *7 post event 000000000262D3B8
2014/09/12 01:01:44 [debug] 12303#0: *7 post event 000000000262D420
2014/09/12 01:01:44 [debug] 12303#0: *7 delete posted event 000000000262D420
2014/09/12 01:01:44 [debug] 12303#0: *7 http upstream request: "/geoip/test?"
2014/09/12 01:01:44 [debug] 12303#0: *7 http upstream dummy handler
2014/09/12 01:01:44 [debug] 12303#0: *7 delete posted event 000000000262D3B8
2014/09/12 01:01:44 [debug] 12303#0: *7 http run request: "/geoip/test?"
2014/09/12 01:01:44 [debug] 12303#0: *7 http upstream check client, write event:1, "/geoip/test"
2014/09/12 01:01:44 [debug] 12303#0: *7 http upstream recv(): -1 (11: Resource temporarily unavailable)
2014/09/12 01:01:44 [debug] 12303#0: *7 post event 0000000002613410
2014/09/12 01:01:44 [debug] 12303#0: *7 post event 000000000262D420
2014/09/12 01:01:44 [debug] 12303#0: *7 delete posted event 000000000262D420
2014/09/12 01:01:44 [debug] 12303#0: *7 http upstream request: "/geoip/test?"
2014/09/12 01:01:44 [debug] 12303#0: *7 http upstream dummy handler
2014/09/12 01:01:44 [debug] 12303#0: *7 delete posted event 0000000002613410
2014/09/12 01:01:44 [debug] 12303#0: *7 http upstream request: "/geoip/test?"
2014/09/12 01:01:44 [debug] 12303#0: *7 http upstream process header
2014/09/12 01:01:44 [debug] 12303#0: *7 malloc: 0000000002657830:4096
2014/09/12 01:01:44 [debug] 12303#0: *7 recv: fd:12 4096 of 4096
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy status 200 "200 OK"
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy header: "Date: Fri, 12 Sep 2014 06:01:44 GMT"
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy header: "Status: 200 OK"
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy header: "Connection: close"
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy header: "Access-Control-Allow-Origin: *"
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy header: "Access-Control-Allow-Methods: *"
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy header: "Content-Type: application/json"
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy header: "Content-Length: 12365"
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy header: "ETag: "a0be9300afe71f1230d8b313182f9241""
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy header: "Cache-Control: max-age=0, private, must-revalidate"
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy header: "X-Request-Id: 95a2c477-20c3-4ca7-b371-9c7f386ce6fe"
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy header: "X-Runtime: 0.015657"
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy header done
2014/09/12 01:01:44 [debug] 12303#0: *7 posix_memalign: 0000000002658840:4096 @16
2014/09/12 01:01:44 [debug] 12303#0: *7 HTTP/1.1 200 OK
Server: nginx/1.7.4
Date: Fri, 12 Sep 2014 06:01:44 GMT
Content-Type: application/json
Content-Length: 12365
Connection: keep-alive
Status: 200 OK
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: *
ETag: "a0be9300afe71f1230d8b313182f9241"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 95a2c477-20c3-4ca7-b371-9c7f386ce6fe
X-Runtime: 0.015657

2014/09/12 01:01:44 [debug] 12303#0: *7 write new buf t:1 f:0 00000000026588B0, pos 00000000026588B0, size: 404 file: 0, size: 0
2014/09/12 01:01:44 [debug] 12303#0: *7 http write filter: l:0 f:0 s:404
2014/09/12 01:01:44 [debug] 12303#0: *7 http cacheable: 0
2014/09/12 01:01:44 [debug] 12303#0: *7 http proxy filter init s:200 h:0 c:0 l:12365
2014/09/12 01:01:44 [debug] 12303#0: *7 http upstream process upstream
2014/09/12 01:01:44 [debug] 12303#0: *7 pipe read upstream: 1
2014/09/12 01:01:44 [debug] 12303#0: *7 pipe preread: 3718
2014/09/12 01:01:44 [debug] 12303#0: *7 input buf #0
2014/09/12 01:01:44 [debug] 12303#0: *7 malloc: 0000000002647290:4096
2014/09/12 01:01:44 [debug] 12303#0: *7 readv: 1:4096
2014/09/12 01:01:44 [debug] 12303#0: *7 pipe recv chain: 4096
2014/09/12 01:01:44 [debug] 12303#0: *7 input buf #1
2014/09/12 01:01:44 [debug] 12303#0: *7 malloc: 00000000026482A0:4096
2014/09/12 01:01:44 [debug] 12303#0: *7 readv: 1:4096
2014/09/12 01:01:44 [debug] 12303#0: *7 pipe recv chain: 4096
2014/09/12 01:01:44 [debug] 12303#0: *7 input buf #2
2014/09/12 01:01:44 [debug] 12303#0: *7 malloc: 00000000026492B0:4096
2014/09/12 01:01:44 [debug] 12303#0: *7 readv: 1:4096
2014/09/12 01:01:44 [debug] 12303#0: *7 pipe recv chain: 455
2014/09/12 01:01:44 [debug] 12303#0: *7 readv: 1:3641
2014/09/12 01:01:44 [debug] 12303#0: *7 pipe recv chain: 0
2014/09/12 01:01:44 [debug] 12303#0: *7 pipe buf in   s:1 t:1 f:0 0000000002657830, pos 00000000026579AA, size: 3718 file: 0, size: 0
2014/09/12 01:01:44 [debug] 12303#0: *7 pipe buf in   s:1 t:1 f:0 0000000002647290, pos 0000000002647290, size: 4096 file: 0, size: 0
2014/09/12 01:01:44 [debug] 12303#0: *7 pipe buf in   s:1 t:1 f:0 00000000026482A0, pos 00000000026482A0, size: 4096 file: 0, size: 0
2014/09/12 01:01:44 [debug] 12303#0: *7 pipe buf free s:0 t:1 f:0 00000000026492B0, pos 00000000026492B0, size: 455 file: 0, size: 0
2014/09/12 01:01:44 [debug] 12303#0: *7 pipe length: 455
2014/09/12 01:01:44 [debug] 12303#0: *7 input buf #3
2014/09/12 01:01:44 [debug] 12303#0: *7 pipe write downstream: 1
2014/09/12 01:01:44 [debug] 12303#0: *7 pipe write downstream flush in
2014/09/12 01:01:44 [debug] 12303#0: *7 http output filter "/geoip/test?"
2014/09/12 01:01:44 [debug] 12303#0: *7 http copy filter: "/geoip/test?"
2014/09/12 01:01:44 [debug] 12303#0: *7 http postpone filter "/geoip/test?" 00000000026577F8
2014/09/12 01:01:44 [debug] 12303#0: *7 write old buf t:1 f:0 00000000026588B0, pos 00000000026588B0, size: 404 file: 0, size: 0
2014/09/12 01:01:44 [debug] 12303#0: *7 write new buf t:1 f:0 0000000002657830, pos 00000000026579AA, size: 3718 file: 0, size: 0
2014/09/12 01:01:44 [debug] 12303#0: *7 write new buf t:1 f:0 0000000002647290, pos 0000000002647290, size: 4096 file: 0, size: 0
2014/09/12 01:01:44 [debug] 12303#0: *7 write new buf t:1 f:0 00000000026482A0, pos 00000000026482A0, size: 4096 file: 0, size: 0
2014/09/12 01:01:44 [debug] 12303#0: *7 write new buf t:1 f:0 00000000026492B0, pos 00000000026492B0, size: 455 file: 0, size: 0
2014/09/12 01:01:44 [debug] 12303#0: *7 http write filter: l:0 f:0 s:12769
2014/09/12 01:01:44 [debug] 12303#0: *7 http write filter limit 0
2014/09/12 01:01:44 [debug] 12303#0: *7 posix_memalign: 0000000002654940:256 @16
2014/09/12 01:01:44 [debug] 12303#0: *7 malloc: 000000000265B290:16384
2014/09/12 01:01:44 [debug] 12303#0: *7 SSL buf copy: 404
2014/09/12 01:01:44 [debug] 12303#0: *7 SSL buf copy: 3718
2014/09/12 01:01:44 [debug] 12303#0: *7 SSL buf copy: 4096
2014/09/12 01:01:44 [debug] 12303#0: *7 SSL buf copy: 4096
2014/09/12 01:01:44 [debug] 12303#0: *7 SSL buf copy: 455
2014/09/12 01:01:44 [debug] 12303#0: *7 http write filter 0000000000000000
2014/09/12 01:01:44 [debug] 12303#0: *7 http copy filter: -2 "/geoip/test?"
2014/09/12 01:01:44 [debug] 12303#0: *7 pipe write downstream done
2014/09/12 01:01:44 [debug] 12303#0: *7 event timer: 12, old: 1410501764404, new: 1410501764423
2014/09/12 01:01:44 [debug] 12303#0: *7 http upstream exit: 0000000000000000
2014/09/12 01:01:44 [debug] 12303#0: *7 finalize http upstream request: 0
2014/09/12 01:01:44 [debug] 12303#0: *7 finalize http proxy request
2014/09/12 01:01:44 [debug] 12303#0: *7 free rr peer 1 0
2014/09/12 01:01:44 [debug] 12303#0: *7 close http upstream connection: 12
2014/09/12 01:01:44 [debug] 12303#0: *7 free: 00000000026096A0, unused: 48
2014/09/12 01:01:44 [debug] 12303#0: *7 event timer del: 12: 1410501764404
2014/09/12 01:01:44 [debug] 12303#0: *7 reusable connection: 0
2014/09/12 01:01:44 [debug] 12303#0: *7 http upstream temp fd: -1
2014/09/12 01:01:44 [debug] 12303#0: *7 http output filter "/geoip/test?"
2014/09/12 01:01:44 [debug] 12303#0: *7 http copy filter: "/geoip/test?"
2014/09/12 01:01:44 [debug] 12303#0: *7 http postpone filter "/geoip/test?" 00007FFF93077FA0
2014/09/12 01:01:44 [debug] 12303#0: *7 write new buf t:0 f:0 0000000000000000, pos 0000000000000000, size: 0 file: 0, size: 0
2014/09/12 01:01:44 [debug] 12303#0: *7 http write filter: l:1 f:0 s:0
2014/09/12 01:01:44 [debug] 12303#0: *7 http write filter limit 0
2014/09/12 01:01:44 [debug] 12303#0: *7 SSL to write: 12769
2014/09/12 01:01:44 [debug] 12303#0: *7 SSL_write: 12769
2014/09/12 01:01:44 [debug] 12303#0: *7 http write filter 0000000000000000
2014/09/12 01:01:44 [debug] 12303#0: *7 http copy filter: 0 "/geoip/test?"
2014/09/12 01:01:44 [debug] 12303#0: *7 http finalize request: 0, "/geoip/test?" a:1, c:1
2014/09/12 01:01:44 [debug] 12303#0: *7 set http keepalive handler
2014/09/12 01:01:44 [debug] 12303#0: *7 http close request
2014/09/12 01:01:44 [debug] 12303#0: *7 http log handler
2014/09/12 01:01:44 [debug] 12303#0: *7 free: 00000000026492B0
2014/09/12 01:01:44 [debug] 12303#0: *7 free: 00000000026482A0
2014/09/12 01:01:44 [debug] 12303#0: *7 free: 0000000002647290
2014/09/12 01:01:44 [debug] 12303#0: *7 free: 0000000002657830
2014/09/12 01:01:44 [debug] 12303#0: *7 free: 0000000002655810, unused: 2
2014/09/12 01:01:44 [debug] 12303#0: *7 free: 0000000002656820, unused: 8
2014/09/12 01:01:44 [debug] 12303#0: *7 free: 0000000002658840, unused: 2090
2014/09/12 01:01:44 [debug] 12303#0: *7 free: 00000000025E3950
2014/09/12 01:01:44 [debug] 12303#0: *7 hc free: 0000000000000000 0
2014/09/12 01:01:44 [debug] 12303#0: *7 hc busy: 0000000000000000 0
2014/09/12 01:01:44 [debug] 12303#0: *7 free: 000000000265B290
2014/09/12 01:01:44 [debug] 12303#0: *7 tcp_nodelay
2014/09/12 01:01:44 [debug] 12303#0: *7 reusable connection: 1
2014/09/12 01:01:44 [debug] 12303#0: *7 event timer add: 11: 30000:1410501734423

Possible to use alternative IP Address header when getting GEO Data?

HI. I was wondering if it was possible to be able to use an IP Address in a different header for the IP detection logic - so we could basically pass something through like my_ip_header and use that to obtain the geo data using your module in NGINX?

Hope that makes sense.

Cheers

Install error

While make I've got error:

/usr/bin/ld: objs/addon/ngx_geoip2/ngx_http_geoip2_module.o: relocation R_X86_64_PC32 against symbol `ngx_http_geoip2_module' can not be used when making a shared object; recompile with -fPIC

I am trying to complie with nginx 1.10.0 on ubuntu (i've got this error on two different ubuntu versions).

Got error with utf8 symbols in values

If module get from DB any value that contains unicode sybmols (cyrillic, 'ü' and so on) then nginx gives me 400 Bad request error. I faced it with en names of some french or german regions.

You easily can repeat it setting for example
$geoip2_data_country_name country names ru;

then use $geoip2_data_country_name anywhere. nginx 1.14.0.

Leak in documentation

Hi, you don't mention about configurations options:

  • geoip2_proxy_recursive
  • geoip2_proxy

One thing this option will not work if we use source param

support for x_forwarded_for

We are trying to run this module using IP value set in x_forwarded_for header. Is there any way to achieve this?

Retrieving Geo Data from the Traits Object

I am able to get country_code, continent_code, latitude, and longitude.

However, I can't seem to figure out how to get data that should be under traits object e.g. ISP, Autonomous System Number, etc.

Below is what I have so far, but it's not working:

geoip2 /etc/maxmind-city.mmdb {
        $geoip2_traits_isp traits isp;
    }

Kindly assist.

How to get Subdivisions

Subdivision data type is array.While country and city are of objects.I am able to successfully fetch country and city data but not subdivisions.Can you please elaborate on how to fetch whole subdivision array and nth object in subdivisions array.

I had used the following code below to fetch subdivisions but was unable to so.
$geoip2_data_subdivision_name source=$http_x_forwarded_for subdivisions names en;

Server directive

Why not allow this module to be used in the server directive? Is there any particular reason not to? For example a static file domain doesn't have any benefit from knowing the country of a visitor.

Expose database metadata

This would allow us to report on debug endpoint which version of file is currently loaded into memory.

NGINX Error - Unknown geoip_city_country_code

I've set up NGINX (compiled from source with --add-module=/path/to/ngx_http_geoip2_module). Before I did this I followed the instructions for Installing Libmaxminddb. I've also added the following to the NGINX configuration file (nginx.conf)

http {
    ...
    geoip2 /etc/maxmind-country.mmdb {
        $geoip2_data_country_code default=US country iso_code;
        $geoip2_data_country_name country names en;
    }

    geoip2 /etc/maxmind-city.mmdb {
        $geoip2_data_city_name default=London city names en;
    }
    ....
}

However, when I start NGINX I get the following error:

nginx: [emerg] unknown "geoip_city_country_code" variable

Any indication as to what may be wrong?

Note: I'm on Ubuntu 14.04 64-bit

collect2: ld returned 1 exit status

i'm getting error message after command make

PLS help.

`./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --with-ld-opt=' -Wl,-E' --add-module=/home/ngx_http_geoip2_module/
`
objs/addon/ngx_http_geoip2_module/ngx_stream_geoip2_module.o: In function `ngx_stream_geoip2_init':
/home/ngx_http_geoip2_module//ngx_stream_geoip2_module.c:689: undefined reference to `ngx_stream_core_module'
objs/addon/ngx_http_geoip2_module/ngx_stream_geoip2_module.o: In function `ngx_stream_geoip2_add_variable_geodata':
/home/ngx_http_geoip2_module//ngx_stream_geoip2_module.c:550: undefined reference to `ngx_stream_compile_complex_value'
objs/addon/ngx_http_geoip2_module/ngx_stream_geoip2_module.o: In function `ngx_stream_geoip2_add_variable_metadata':
/home/ngx_http_geoip2_module//ngx_stream_geoip2_module.c:478: undefined reference to `ngx_stream_add_variable'
objs/addon/ngx_http_geoip2_module/ngx_stream_geoip2_module.o: In function `ngx_stream_geoip2_add_variable_geodata':
/home/ngx_http_geoip2_module//ngx_stream_geoip2_module.c:566: undefined reference to `ngx_stream_add_variable'
objs/addon/ngx_http_geoip2_module/ngx_stream_geoip2_module.o: In function `ngx_stream_geoip2_variable':
/home/ngx_http_geoip2_module//ngx_stream_geoip2_module.c:136: undefined reference to `ngx_stream_complex_value'
collect2: ld returned 1 exit status
make[1]: *** [objs/nginx] Error 1
make[1]: Leaving directory `/home/nginx-1.14.2'
make: *** [build] Error 2

does it support geoip databases?

does it support geoip databases? we are using geoip org database too, there is no geoip2 db for that.
Old database will work with this plugin?

How would I tell nginx where to find libmaxminddb?

I use custom library paths.
NGINX knows about pkgconfig/libmaxminddb.pc

However apparently it just ignores it?`

adding module in third/ngx_http_geoip2_module_git
checking for MaxmindDB library ... not found
./configure: error: the geoip2 module requires the maxminddb library.

My compile script looks simplified like:

export PKG_CONFIG_PATH="$INSTALL_DIR/extra/lib/pkgconfig"
./configure ....--add-module=third/ngx_http_geoip2_module_git ....

Any idea?

$INSTALL_DIR/extra/lib/ contains a fully working & "make check" passing libmaxminddb so it apparently just can't find it

I also can't seem to find a config.log.. oddly enough apparently nginx doesn't create one?

Nvm figured it out, didn't even realise nginx doesn't even use pkgconfig
giving it a "LIBRARY_PATH" made it work ;)

Typo?

In README.md, "supports both IPv4 and IPv4", I think one of them should be "IPv6".

Tag 3.2 fails Openresty build

The latest update fails the openresty build
BUILD step

./configure -j2 --prefix=/opt/apps/openresty \
                    --without-luajit-lua52 \
                    --with-pcre-jit \
                    --with-http_ssl_module \
                    --with-ipv6 \
                    --with-http_realip_module \
                    --with-http_stub_status_module \
                    --with-stream \
                    --add-module=/opt/apps/openresty/nginx/geoip/ngx_http_geoip2_module-master
make -j2 && make install

OUTPUT exerpt

T_VAR -DNDK_UPSTREAM_LIST -DNDK_SET_VAR -DNDK_SET_VAR -DNDK_SET_VAR -DLUA_DEFAULT_PATH='\"/opt/apps/openresty/site/lualib/?.lua;/opt/apps/openresty/site/lualib/?/init.lua;/opt/apps/openresty/lualib/?.lua;/opt/apps/openresty/lualib/?/init.lua\"' -DLUA_DEFAULT_CPATH='\"/opt/apps/openresty/site/lualib/?.so;/opt/apps/openresty/lualib/?.so\"' -DNDK_SET_VAR -I src/core -I src/event -I src/event/modules -I src/os/unix -I ../ngx_devel_kit-0.3.0/objs -I objs/addon/ndk -I ../ngx_lua-0.10.8/src/api -I objs \\", "\t-o objs/ngx_modules.o \\", "\tobjs/ngx_modules.c", "objs/Makefile:2504: recipe for target 'objs/addon/ngx_http_geoip2_module-master/ngx_stream_geoip2_module.o' failed", "make[2]: Leaving directory '/tmp/openresty/source/build/nginx-1.11.2'", "Makefile:8: recipe for target 'build' failed", "make[1]: Leaving directory '/tmp/openresty/source/build/nginx-1.11.2'", "Makefile:4: recipe for target 'all' failed"]}

Is there another solution than compile Nginx with dynamic module ?

With dynamic module, if I understand well, I don't need to compile your code.
Just take the .so file, copy it in nginx modules folder and finally and the load_module ... directive in my nginx.conf.

Why should I compile your lib with a downloaded version of Nginx code ? I have the Nginx that come from repos.

Map custom ip to some geo parameter

Hello, is it possible to map local ip or subnet to geo parameter ?
Like:

map $geoip2_data_city_geoname_id $upstream {
default upstream1;
524901 upstream2;
192.168.1.2/32 upstream2;
}

Maybe you could add this feature to your module ?

I use something like this:

geo $privatenet {
default no;
192.168.1.2/32 yes;
}

server {
.....
if ($privatenet = yes) {
set $upstream upstream2;
}
....

But I thing if your module will have such feature, it would be great :)

charset Unicode utf8 in acceslog

Hello

With this nginx simple configuration below , we are experiencing a charset encode issue when we want subdivisions geolocalisation. For example Nginx will not decode the unicode character "\xC3\x8E" we expected " Î ".

My nginx configuration :

$geoip2_data_subdivisions_names subdivisions 0 names en;

My acceslogs :

{ "t": "15/Feb/2017:16:20:09 +0000", "IP": "XX.XX.XXX.XX", "country_code": "FR", "country_name": "France", "citry_name": "Paris", "subdivisions_names": "\xC3\x8Ele-de-France" }

I try a lot of things :
set charset utf8 in my nginx configuration
set chartse_type utf8 in my nginx configuration
set LC_ALL=en_US.UTF-8 on my distro

Is there any configuration in nginx or geoip2 module to solve this issue ?

nginx-extra version --> 1.10.2-4
ngx_http_geoip2_module --> last version

Thank you

Error During Compiling with Nginx 1.11.5

Am I doing anything wrong?

objs/addon/ngx_http_geoip2_module-2.0/ngx_stream_geoip2_module.o: In function `ngx_stream_geoip2_add_variable':
/opt/ngx_modules_3/ngx_http_geoip2_module-2.0/ngx_stream_geoip2_module.c:398: undefined reference to `ngx_stream_compile_complex_value'
/opt/ngx_modules_3/ngx_http_geoip2_module-2.0/ngx_stream_geoip2_module.c:414: undefined reference to `ngx_stream_add_variable'
objs/addon/ngx_http_geoip2_module-2.0/ngx_stream_geoip2_module.o: In function `ngx_stream_geoip2_variable':
/opt/ngx_modules_3/ngx_http_geoip2_module-2.0/ngx_stream_geoip2_module.c:117: undefined reference to `ngx_stream_complex_value'
collect2: error: ld returned 1 exit status

disk io

Tried to load GeoIP2-Connection-Type database but disk io increased and server died in few minutes.

here is configuration file

geoip2 /usr/share/geoip2/GeoIP2-Connection-Type.mmdb
{
$geoip2_connection_type connection_type;
}

Any idea what is causing this?

-vij

Access last subdivisions

Hello,

I'm struggling with accessing the "last" subdivisions element.

  geoip2        /etc/nginx/GeoIP2-City.mmdb {
    $geoip_region_name subdivisions 0 names en;
  }

Is working well, but I cannot find a way to get the "last" index instead of "0". I've tried with -1 for instance.
Not sure it's an nginx or this module specific syntax.

Would be interested to know if there is a simple way, otherwise I guess I can work around it with nginx directives.

Thanks

Attempts to automatically reload GeoIP database without auto_reload parameter configured

We've been observing a situation when one of our load balancers powered by nginx/1.15.2 and ngx_http_geoip2_module (v3.0) started to produce the following entries in error log:

Sep 27 00:25:17 lb-xx nginx_error: 2018/09/27 00:25:17 [info] 6865#6865: *13189338 Reload MMDB "/var/lib/GeoIP/GeoLite2-City.mmdb", client: x.x.x.x, server: x.x.x, request: "POST /x/x/x HTTP/1.1", host: "x.x.x.x"

nginx was running on that host for about a week, plus we do have a number of automated actions which may result in reloading nginx configuration by sending SIGHUP to master process as described here [1].

Our geoip2 configuration part is quite simple:

    geoip2 /var/lib/GeoIP/GeoLite2-City.mmdb {
        $geoip_country_code country iso_code;
        $geoip_country_name country names en;
    }

    log_format  geoip '$remote_addr [$time_local] $status $geoip_country_code '
                      '"$geoip_country_name"';

The geoip log format is being used in a couple of server{} blocks with relatively high RPS.

In addition to unexpected log entries we started to caught segmentation faults in worker processes on every GeoIP database update (or even touch /var/lib/GeoIP/GeoLite2-City.mmdb). Backtraces look like this:

#0  0x000055f6f8d74920 in ngx_http_log_escape (src=0x7f96d05d02da <error: Cannot access memory at address 0x7f96d05d02da>, size=<optimized out>, dst=0x0)
    at src/http/modules/ngx_http_log_module.c:1023
1023    src/http/modules/ngx_http_log_module.c: No such file or directory.
(gdb) bt
#0  0x000055f6f8d74920 in ngx_http_log_escape (src=0x7f96d05d02da <error: Cannot access memory at address 0x7f96d05d02da>, size=<optimized out>, dst=0x0)
    at src/http/modules/ngx_http_log_module.c:1023
#1  0x000055f6f8d74aba in ngx_http_log_escape (size=<optimized out>, src=<optimized out>, dst=0x0) at src/http/modules/ngx_http_log_module.c:962
#2  ngx_http_log_variable_getlen (r=<optimized out>, data=<optimized out>) at src/http/modules/ngx_http_log_module.c:962
#3  0x000055f6f8d765fa in ngx_http_log_handler (r=0x55f6f9ceb230) at src/http/modules/ngx_http_log_module.c:305
#4  0x000055f6f8d6bcd0 in ngx_http_log_request (r=r@entry=0x55f6f9ceb230) at src/http/ngx_http_request.c:3728
#5  0x000055f6f8d6d671 in ngx_http_free_request (r=r@entry=0x55f6f9ceb230, rc=rc@entry=0) at src/http/ngx_http_request.c:3675
#6  0x000055f6f8d6e22e in ngx_http_set_keepalive (r=0x55f6f9ceb230) at src/http/ngx_http_request.c:3091
#7  ngx_http_finalize_connection (r=<optimized out>) at src/http/ngx_http_request.c:2742
#8  0x000055f6f8d7fc3d in ngx_http_upstream_process_request (r=0x55f6f9ceb230, u=0x55f6f9caad78) at src/http/ngx_http_upstream.c:4292
#9  0x000055f6f8d7ed18 in ngx_http_upstream_handler (ev=<optimized out>) at src/http/ngx_http_upstream.c:1344
#10 0x000055f6f8d5723b in ngx_epoll_process_events (cycle=<optimized out>, timer=<optimized out>, flags=<optimized out>) at src/event/modules/ngx_epoll_module.c:902
#11 0x000055f6f8d4d53a in ngx_process_events_and_timers (cycle=cycle@entry=0x55f6f973c080) at src/event/ngx_event.c:279
#12 0x000055f6f8d55361 in ngx_worker_process_cycle (cycle=cycle@entry=0x55f6f973c080, data=data@entry=0x0) at src/os/unix/ngx_process_cycle.c:785
#13 0x000055f6f8d53708 in ngx_spawn_process (cycle=cycle@entry=0x55f6f973c080, proc=0x55f6f8d552e0 <ngx_worker_process_cycle>, data=0x0, name=0x55f6f8e265ac "worker process", 
    respawn=respawn@entry=3) at src/os/unix/ngx_process.c:199
#14 0x000055f6f8d56444 in ngx_reap_children (cycle=0x55f6f973c080) at src/os/unix/ngx_process_cycle.c:657
#15 ngx_master_process_cycle (cycle=0x55f6f973c080) at src/os/unix/ngx_process_cycle.c:186
#16 0x000055f6f8d2b698 in main (argc=<optimized out>, argv=<optimized out>) at src/core/nginx.c:382
(gdb) 

Though it was 100% reproducible on the particular balancer, it was hard to get the same segfaults in test lab. However, we were able to trigger Reload MMDB ... action with the following nginx configuration:

load_module modules/ngx_http_geoip2_module.so;

worker_processes  2;

error_log  logs/error.log  debug;

events {
    worker_connections 32000; 
}


http {
    sendfile        on;
    keepalive_timeout  65;

    set_real_ip_from 127.0.0.1;

    geoip2 /var/lib/GeoIP/GeoLite2-City.mmdb {
        $geoip_country_code country iso_code;
        $geoip_country_name country names en;
    }

    log_format  geoip '$remote_addr [$time_local] $status $geoip_country_code '
                      '"$geoip_country_name"';

    server {
        listen       80;
        server_name  localhost;

	access_log logs/geoip.log geoip;

        location / {
		root html;
        }
    }
}

and the following Lua script for wrk [2]:

init = function(args)
    local fh = assert(io.open("/dev/urandom", "rb"))
    local str = fh:read(4)
    fh:close()

    local num = 0
    local len = #str
    for i = 1, len do
        num = num + string.byte(str, i) * 256^(len - i)
    end
    math.randomseed(num)
end

request = function()
   local ip = ""
   for i = 1, 4 do
     ip = ip .. math.random(1, 255)
     if i < 4 then ip = ip .. '.' end
   end
   wrk.headers["X-Real-IP"] = ip
   return wrk.format(nil, path)
end

We use the following command to launch wrk:

wrk -t 10 -c 10000 -d 1h -s geoip-test.lua http://localhost/

and the following cron configuration to simulate the initial scenario:

*/1 * * * * /usr/bin/truncate -s 0 /usr/local/nginx/logs/geoip.log
*/1 * * * * /usr/bin/touch /var/lib/GeoIP/GeoLite2-City.mmdb
*/2 * * * * /bin/kill -HUP `cat /usr/local/nginx/logs/nginx.pid`

With the above configuration, we start to get Reload MMDB ... entries after 3-5 nginx configuration reloads:

2018/10/01 03:16:44 [info] 30497#30497: *231069 Reload MMDB "/var/lib/GeoIP/GeoLite2-City.mmdb" while logging request, client: 42.27.138.155, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
2018/10/01 03:16:44 [info] 30498#30498: *231121 Reload MMDB "/var/lib/GeoIP/GeoLite2-City.mmdb" while logging request, client: 22.45.201.59, server: localhost, request: "GET / HTTP/1.1", host: "localhost"

I'm currently testing a patch which should fix the reason of unwanted MMDB reloads, and hopefully to avoid segmentation faults (though I'm not sure these 2 issues are directly connected).

I can share the GeoLite2-City.mmdb database which was used for testing, if required (it was obtained via geoipupdate on 09/27).

[1] http://nginx.org/en/docs/control.html#reconfiguration
[2] https://github.com/wg/wrk

module "/ngx_stream_geoip2_module.so" version 1011005 instead of 1011006

Getting this error from nginx while following the instructions from here used to build this module

nginx: [emerg] module "/usr/lib/nginx/modules/ngx_stream_geoip2_module.so" version 1011005 instead of 1011006 in /etc/nginx/nginx.conf:8

I think this is because of recent updates to this library because it was working just fine a few days back and today when I decided to build nginx on a new machine pulling with this module latest repo.

Build Error

I'm running below build command in ubuntu server 16.04, after installing libmaxminddb.

./configure --add-dynamic-module=/path/to/ngx_http_geoip2_module

I've got this error:

checking for OS
 + Linux 4.4.0-130-generic x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for gcc builtin 64 bit byteswap ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not found
checking for sys/param.h ... found
checking for sys/mount.h ... found
checking for sys/statvfs.h ... found
checking for crypt.h ... found
checking for Linux specific features
checking for epoll ... found
checking for EPOLLRDHUP ... found
checking for O_PATH ... found
checking for sendfile() ... found
checking for sendfile64() ... found
checking for sys/prctl.h ... found
checking for prctl(PR_SET_DUMPABLE) ... found
checking for sched_setaffinity() ... found
checking for crypt_r() ... found
checking for sys/vfs.h ... found
checking for nobody group ... not found
checking for nogroup group ... found
checking for poll() ... found
checking for /dev/poll ... not found
checking for kqueue ... not found
checking for crypt() ... not found
checking for crypt() in libcrypt ... found
checking for F_READAHEAD ... not found
checking for posix_fadvise() ... found
checking for O_DIRECT ... found
checking for F_NOCACHE ... not found
checking for directio() ... not found
checking for statfs() ... found
checking for statvfs() ... found
checking for dlopen() ... not found
checking for dlopen() in libdl ... found
checking for sched_yield() ... found
checking for SO_SETFIB ... not found
checking for SO_REUSEPORT ... found
checking for SO_ACCEPTFILTER ... not found
checking for IP_RECVDSTADDR ... not found
checking for IP_PKTINFO ... found
checking for IPV6_RECVPKTINFO ... found
checking for TCP_DEFER_ACCEPT ... found
checking for TCP_KEEPIDLE ... found
checking for TCP_FASTOPEN ... found
checking for TCP_INFO ... found
checking for accept4() ... found
checking for eventfd() ... found
checking for int size ... 4 bytes
checking for long size ... 8 bytes
checking for long long size ... 8 bytes
checking for void * size ... 8 bytes
checking for uint32_t ... found
checking for uint64_t ... found
checking for sig_atomic_t ... found
checking for sig_atomic_t size ... 4 bytes
checking for socklen_t ... found
checking for in_addr_t ... found
checking for in_port_t ... found
checking for rlim_t ... found
checking for uintptr_t ... uintptr_t found
checking for system byte ordering ... little endian
checking for size_t size ... 8 bytes
checking for off_t size ... 8 bytes
checking for time_t size ... 8 bytes
checking for setproctitle() ... not found
checking for pread() ... found
checking for pwrite() ... found
checking for pwritev() ... found
checking for sys_nerr ... found
checking for localtime_r() ... found
checking for posix_memalign() ... found
checking for memalign() ... found
checking for mmap(MAP_ANON|MAP_SHARED) ... found
checking for mmap("/dev/zero", MAP_SHARED) ... found
checking for System V shared memory ... found
checking for POSIX semaphores ... not found
checking for POSIX semaphores in libpthread ... found
checking for struct msghdr.msg_control ... found
checking for ioctl(FIONBIO) ... found
checking for struct tm.tm_gmtoff ... found
checking for struct dirent.d_namlen ... not found
checking for struct dirent.d_type ... found
checking for sysconf(_SC_NPROCESSORS_ONLN) ... found
checking for openat(), fstatat() ... found
checking for getaddrinfo() ... found
configuring additional dynamic modules
adding module in ./ngx_http_geoip2_module
./configure: error: no ./ngx_http_geoip2_m.odule/config was found

Any solution appreciated...

Geoip2 module requires the maxminddb library

Hi @leev or everyone,

I'm trying to re-compile nginx with this ngx_http_geoip2_module.

I'm trying to run the following command:

$ sudo ./configure --add-module=/opt/nginx/ngx_http_geoip2_module

but it fails on checking the Maxmind library with this output:

[...]
configuring additional modules
adding module in /opt/nginx/ngx_http_geoip2_module
checking for MaxmindDB library ... not found
./configure: error: the geoip2 module requires the maxminddb library.

As I always read the documentation, I've of course installed the libmaxminddb before and it seems to be available:

$ sudo ldconfig -p | grep maxmind
    libmaxminddb.so.0 (libc6,x86-64) => /usr/local/lib/libmaxminddb.so.0
    libmaxminddb.so (libc6,x86-64) => /usr/local/lib/libmaxminddb.so

Do you have any suggestion to help me installing it, please?

Thank you!

Build issue

Linux bananapi 4.14.84-sunxi #3 SMP Sat Dec 1 07:18:41 CET 2018 armv7l GNU/Linux

-ldl -lpthread -lpthread -lcrypt -lmaxminddb -lmaxminddb ../pcre-8.42/.libs/libpcre.a ../openssl-1.1.0h/.openssl/lib/libssl.a ../openssl-1.1.0h/.openssl/lib/libcrypto.a -ldl -lpthread ../zlib-1.2.11/libz.a
-Wl,-E
objs/addon/ngx_http_geoip2_module/ngx_stream_geoip2_module.o: In function ngx_stream_geoip2_init': /media/usb/src/nginx/ngx_http_geoip2_module/ngx_stream_geoip2_module.c:697: undefined reference to ngx_stream_core_module'
objs/addon/ngx_http_geoip2_module/ngx_stream_geoip2_module.o: In function
ngx_stream_geoip2_add_variable_metadata': /media/usb/src/nginx/ngx_http_geoip2_module/ngx_stream_geoip2_module.c:478: undefined reference to ngx_stream_add_variable'
objs/addon/ngx_http_geoip2_module/ngx_stream_geoip2_module.o: In function ngx_stream_geoip2_add_variable_geodata': /media/usb/src/nginx/ngx_http_geoip2_module/ngx_stream_geoip2_module.c:550: undefined reference to ngx_stream_compile_complex_value'
/media/usb/src/nginx/ngx_http_geoip2_module/ngx_stream_geoip2_module.c:566: undefined reference to ngx_stream_add_variable' objs/addon/ngx_http_geoip2_module/ngx_stream_geoip2_module.o: In function ngx_stream_geoip2_variable':
/media/usb/src/nginx/ngx_http_geoip2_module/ngx_stream_geoip2_module.c:136: undefined reference to `ngx_stream_complex_value'
collect2: error: ld returned 1 exit status
objs/Makefile:348: recipe for target 'objs/nginx' failed
make[1]: *** [objs/nginx] Error 1
make[1]: Leaving directory '/media/usb/src/nginx/nginx-1.15.8'
Makefile:8: recipe for target 'build' failed
make: *** [build] Error 2

nginx: [emerg] unknown "variable_with_ip" variable

Hi,

I got nginx: [emerg] unknown "variable_with_ip" variable when I try to start Nginx, have I missed something?

Related nginx.conf :

    geoip2 /etc/GeoLite2-Country.mmdb {
        $geoip2_metadata_country_build metadata build_epoch;
        $geoip2_data_country_code default=US source=$variable_with_ip country iso_code;
        $geoip2_data_country_name country names en;
    }

Nginx Version: 1.15.5

Build configuration:

    ./configure --with-ld-opt="-Wl,-rpath,/usr/local/lib/" \
		--add-module=../ngx_devel_kit-0.3.0 \
		--add-module=../lua-nginx-module-0.10.13 \
		--add-module=../ngx_brotli \
		--add-module=../nginx-ct-1.3.2 \
		--add-module=../ngx_http_geoip2_module \
		--add-module=../*pagespeed* \
		--with-openssl=../openssl \
		--with-http_v2_module \
		--with-http_ssl_module \
		--with-http_stub_status_module \
		--with-http_gzip_static_module

Please let me know if you need more information.

Read client IP from custom variable

Hello!

Is it possible to specify from which variable read client IP?

I think to integrate this module with PowerDNS through remote backend, so it will be awesome if I can use $http_x_remotebackend_real_remote variable.

Allow spaces in default values

Not 100% sure but apparently there is no way to use spaces in default values.

If I use default=Foo\ Bar it shows the Foo\ Bar
If I use default="Foo Bar" it shows the "Foo and cuts the value and breaks the request

Thanks

Performance penalty

Would it be possible to find out performance penalty introduced when using GeoLite2-City.mmdb (32MB) , vs. GeoLite2-Country.mmdb (2MB) ? Are database query results cached? Are the databases cached in memory?

About fastcgi_param

Fastcgi_param this configuration seems to be bad to use, local is not working. I can explain it? Thank you very much

Cannot locate maxminddb during configure

Hi,

I have compiled and installed libmaxminddb library from MaxMind as per their instructions, and "ldconfig -p | grep maxminddb" gives:

libmaxminddb.so.0 (libc6,x86-64) => /usr/local/lib/libmaxminddb.so.0
libmaxminddb.so (libc6,x86-64) => /usr/local/lib/libmaxminddb.so

However, when I configure nginx with ngx_http_geoip2_module, it complains:

adding module in /home/cilium/ngx_http_geoip2_module
checking for MaxmindDB library ... not found
./configure: error: the geoip2 module requires the maxminddb library.

I download the latest source of ngx_http_geoip2_module directly from Github. Any idea?

nginx: [emerg] invalid number of arguments in "geoip2" directive

nginx: [emerg] invalid number of arguments in "geoip2" directive

This is in my http block ... any ideas ?

    geoip2 /etc/maxmind-country.mmdb {
        $geoip2_data_country_code default=US source=$variable_with_ip country iso_code;
        $geoip2_data_country_name country names en;
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.