ngx_stream_ipdb_module icon indicating copy to clipboard operation
ngx_stream_ipdb_module copied to clipboard

nginx stream geoip module for ipdb

Name

Build Status Coverage Status

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

Table of Contents

  • Name
  • Status
  • Install
  • Example Configuration
  • Directives
    • ipdb
    • ipdb_language
  • Variable
    • $ipdb_country_name
    • $ipdb_region_name
    • $ipdb_city_name
    • $ipdb_isp_domain
    • $ipdb_raw
  • Lua API
    • get_raw
  • TODO
  • Author
  • Copyright and License
  • See Also

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 --with-stream --add-module=./github.com/vislee/ngx_stream_ipdb_module
# or dynamic compile
configure --prefix=/usr/local/nginx --with-stream --add-dynamic-module=./github.com/vislee/ngx_stream_ipdb_module --with-compat

# or stream_lua
configure --prefix=/usr/local/nginx --with-stream --add-module=./github.com/openresty/stream-lua-nginx-module/ --add-module=./github.com/vislee/ngx_stream_ipdb_module --with-cc-opt='-I ./github.com/openresty/stream-lua-nginx-module/src'

The following information is success:

checking for json-c library ... found

  • ngx_stream_ipdb_module was configured

Back to TOC

Example Configuration


# load_module modules/ngx_stream_ipdb_module.so;

stream {
    ipdb conf/ipiptest.ipdb;
    ipdb_language "CN";

    server {
        listen 8091;
        # ipdb_language EN;

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

    # stream_lua
    server {
        listen 8092;
        ipdb_language CN;

        content_by_lua_block {
            local sipdb = require "ngx.stream.ipdb";
            ngx.say(sipdb.get_raw("127.0.0.1"));
        }
    }
}

Back to TOC

TODO

Back to TOC

Directives

ipdb

syntax: ipdb file;

default: -

context: stream

Specifies a database.

ipdb_language

syntax: ipdb_language EN|CN;

default: EN

context: stream,server

set variable language.

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_isp_domain

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

ipdb_raw

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

Back to TOC

Lua API

get_raw

syntax: ipdb_raw = ngx.stream.ipdb.get_raw(addr)

context: content_by_lua*, log_by_lua*

Get raw info for addr . for example, "中国\t内蒙古\t呼和浩特","China\tNei Mongol\tHohhot"

Back to TOC

Author

wenqiang li(vislee)

Back to TOC

Copyright and License

This module is licensed under the BSD 3-Clause License.

Copyright (C) 2019, by vislee.

All rights reserved.

Back to TOC

See Also