Git Product home page Git Product logo

ngx_http_ipdb_module's Introduction

Name

travis-ci Coverage Status

ngx_http_ipdb_module - creates variables with values depending on the client IP address or specifies address, using the precompiled ipip.net ipdb.

Table of Contents

Status

The module is currently in active development.

Back to TOC

Install

# install json-c lib
# centos
yum install json-c-devel -y
#or mac OSX
brew install json-c

configure --prefix=/usr/local/nginx --add-module=./github.com/vislee/ngx_http_ipdb_module
# or dynamic compile
configure --prefix=/usr/local/nginx --add-dynamic-module=./github.com/vislee/ngx_http_ipdb_module --with-compat

The following information is success:

checking for json-c library ... found

+ ngx_http_ipdb_module was configured

Back to TOC

Example Configuration

# load_module ./modules/ngx_http_ipdb_module.so;

http {
    include       mime.types;
    default_type  application/octet-stream;

    ......

    ipdb /tmp/nginx/conf/ipiptest.ipdb;
    ipdb_language CN;
    ipdb_proxy 127.0.0.1;
    ipdb_proxy_recursive on;

    server {
        listen       8090;
        server_name  localhost;

        ......

        location / {
            # ipdb_specifies_addr $http_addr;
            # ipdb_language EN;

            return 200 "country_name:$ipdb_country_name, raw_info:$ipdb_raw";
        }
    }
}

Back to TOC

TODO

  • add variable

Back to TOC

Directives

ipdb

syntax: ipdb file;

default: -

context: http

Specifies a database.

ipdb_language

syntax: ipdb_language EN|CN;

default: EN

context: http,server,location

set variable language.

ipdb_proxy

syntax: ipdb_proxy address|CIDR;

default: -

context: http

Defines trusted addresses. Just like geoip_proxy.

ipdb_proxy_recursive

syntax: ipdb_proxy_recursive on|off;

default: off

context: http

Is recursive search. Just like geoip_proxy_recursive

ipdb_specifies_addr

syntax: ipdb_specifies_addr address;

default: -

context: http,server,location

Specifies the address. The address can contain text, variables.

Back to TOC

Variable

ipdb_country_name

$ipdb_country_name - country name, for example, "**", "China"

ipdb_region_name

$ipdb_region_name - country region name, for example, "内蒙古","Nei Mongol", "北京", "Beijing"

ipdb_city_name

$ipdb_city_name - city name, for example, "呼和浩特", "Hohhot", "北京", "Beijing"

ipdb_owner_domain

ipdb_isp_domain

$ipdb_isp_domain - ISP name, for example, "电信", "ChinaTelecom"

ipdb_latitude

ipdb_longitude

ipdb_timezone

ipdb_utc_offset

ipdb_china_admin_code

ipdb_idd_code

ipdb_country_code

ipdb_continent_code

ipdb_idc

ipdb_base_station

ipdb_country_code3

ipdb_european_union

ipdb_currency_code

ipdb_currency_name

ipdb_anycast

ipdb_raw

$ipdb_raw - raw info, for example, "**\t内蒙古\t呼和浩特","China\tNei Mongol\tHohhot"

NOTE: If you need to get multiple variables, use this $ipdb_raw.

Back to TOC

Author

wenqiang li(vislee)

Back to TOC

Copyright and License

This module is licensed under the GPL license.

Copyright (C) 2018-2019, by vislee.

All rights reserved.

Back to TOC

See Also

ngx_http_ipdb_module's People

Contributors

vislee 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

ngx_http_ipdb_module's Issues

failed to compile it into nginx

Hi~ ngx_http_ipdb_module/ngx_http_ipdb_module.c:146:7: error: 'ngx_http_null_variable' undeclared here (not in a function)

ngx_http_null_variable is not defined which lead to error in compiling it into nginx

alpinelinux环境下编译出错

提示错误
./ngx_http_ipdb_module-master//ipdb/ipdb.c In file included from ./ngx_http_ipdb_module-master//ipdb/ipdb.c:9: ./ngx_http_ipdb_module-master//ipdb/ipdb.h:60:44: error: unknown type name 'u_char' int ipdb_search(ipdb_reader *reader, const u_char *ip, int bit_count, int *node); ^~~~~~ ./ngx_http_ipdb_module-master//ipdb/ipdb.c:184:44: error: unknown type name 'u_char' int ipdb_search(ipdb_reader *reader, const u_char *ip, int bit_count, int *node) { ^~~~~~ ./ngx_http_ipdb_module-master//ipdb/ipdb.c: In function 'ipdb_find0': ./ngx_http_ipdb_module-master//ipdb/ipdb.c:219:42: error: unknown type name 'u_char' err = ipdb_search(reader, (const u_char *) &addr4.s_addr, 32, &node); ^~~~~~ ./ngx_http_ipdb_module-master//ipdb/ipdb.c:227:42: error: unknown type name 'u_char' err = ipdb_search(reader, (const u_char *) &addr6.s6_addr, 128, &node); ^~~~~~ make[1]: *** [objs/Makefile:1212: objs/addon/ipdb/ipdb.o] Error 1 make[1]: Leaving directory '/tmp/nginx-1.17.4' make: *** [Makefile:8: build] Error 2

在 ipdb.h里加上 typedef unsigned char u_char; 才能编译通过

如何同时加载 ipv4 和 ipv6 ipdb

ipdb

syntax: ipdb file;

default: -

context: http

Specifies a database.

ipdb 参数只能加载一个文件, 要么是 ipv4.ipdbipv6.ipdb

现在大部分都多支持双栈, 如何同时加载 ipv4ipv6 文件, 以便 v4 v6 地址都支持

Build fails after nginx 1.23.0

when try to build with nginx 1.23.1,it fails

here are the error log:

        -o objs/ngx_http_ipdb_module_modules.o \
        objs/ngx_http_ipdb_module_modules.c
/usr/src/ngx_http_ipdb_module/ngx_http_ipdb_module.c: In function 'ngx_http_ipdb_variable':
/usr/src/ngx_http_ipdb_module/ngx_http_ipdb_module.c:620:14: error: assignment to 'ngx_array_t *' from incompatible pointer type 'ngx_table_elt_t **' {aka 'struct ngx_table_elt_s **'} [-Werror=incompatible-pointer-types]
  620 |         xfwd = &r->headers_in.x_forwarded_for;
      |              ^
/usr/src/ngx_http_ipdb_module/ngx_http_ipdb_module.c:622:58: error: passing argument 3 of 'ngx_http_get_forwarded_addr' from incompatible pointer type [-Werror=incompatible-pointer-types]
  622 |             (void) ngx_http_get_forwarded_addr(r, &addr, xfwd, NULL,
      |                                                          ^~~~
      |                                                          |
      |                                                          ngx_array_t *
In file included from src/http/ngx_http.h:36,
                 from /usr/src/ngx_http_ipdb_module/ngx_http_ipdb_module.c:7:
src/http/ngx_http_core_module.h:532:22: note: expected 'ngx_table_elt_t *' {aka 'struct ngx_table_elt_s *'} but argument is of type 'ngx_array_t *'
  532 |     ngx_table_elt_t *headers, ngx_str_t *value, ngx_array_t *proxies,
      |     ~~~~~~~~~~~~~~~~~^~~~~~~

编译出错

centos 7
kernel 5
gcc 8
nginx 1.17.6

/www/server/nginx/src/ngx_http_ipdb_module/ipdb/ipdb.c: In function ‘ipdb_reader_new’:
/www/server/nginx/src/ngx_http_ipdb_module/ipdb/ipdb.c:106:5: error: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Werror=unused-result]
fread(&meta_length, sizeof(meta_length), 1, fd);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/www/server/nginx/src/ngx_http_ipdb_module/ipdb/ipdb.c:111:5: error: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Werror=unused-result]
fread(meta_json, sizeof(char), meta_length, fd);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/www/server/nginx/src/ngx_http_ipdb_module/ipdb/ipdb.c:124:5: error: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Werror=unused-result]
fread(rd->data, sizeof(unsigned char), (size_t) data_len, fd);

debian Adaptation

This module is compiled on Debian system, there is no error, but it can not generate related dynamic module. There is no error in static compilation, but error is reported when loading related instructions in configuration file

nginx: [emerg] unknown directive "ipdb" in /etc/nginx/nginx.conf:26
nginx: configuration file /etc/nginx/nginx.conf test failed

http {
ipdb /etc/nginx/ipip.ipdb;
ipdb_language EN;
ipdb_proxy 127.0.0.1;
ipdb_proxy_recursive on;

结果为空 country_name:, raw_info:*

使用的openresty 1.5.18,编译成功。

使用示例配置:

http {
    # ipip
    ipdb /usr/local/nginx/conf/mydata4vipweek2.ipdb;
    ipdb_language EN;
    ipdb_proxy 127.0.0.1;
    ipdb_proxy_recursive on;

    server {
        location /ip {
            return 200 "country_name:$ipdb_country_name, raw_info:$ipdb_raw";
        }
    }
}

测试命令:
curl -H 'X-Forwarded-For: 1.85.4.99' -v 127.0.0.1/ip

得到的结果是空:

country_name:, raw_info:*

变量为空

配置如下:
HTTP段:

ipdb /root/ipipfree.ipdb;
ipdb_language EN;
ipdb_proxy 127.0.0.1;
    ipdb_proxy_recursive on;

Server段内容为:

add_header x-info $ipdb_country_name;
add_header x-test $ipdb_region_name;

发现response中不返回x-info($ipdb_country_name),结果为空,重启过nginx,同时nginx中无错误日志,请问是怎么回事?

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.