ip2region_private/binding/nginx
Wu Jian Ping a8571d4a99 优化文档 2023-03-30 22:11:55 +08:00
..
src 优化代码 2023-03-30 21:58:40 +08:00
t nginx-impl init 2023-03-30 17:46:38 +08:00
LICENSE nginx-impl init 2023-03-30 17:46:38 +08:00
README.md 优化文档 2023-03-30 22:11:55 +08:00
config 优化代码 2023-03-30 21:58:40 +08:00

README.md

nginx-ip2region

Build

$ mkdir -p workspace
$ cd workspace
$ wget https://nginx.org/download/nginx-1.23.4.tar.gz
$ tar -zxf nginx-1.23.4.tar.gz && rm -rf nginx-1.23.4.tar.gz
$ git clone https://github.com/lionsoul2014/ip2region.git
$ cd nginx-1.23.4
$ ./configure \
    --add-module=$(PWD)/../ip2region/binding/nginx
$ make
$ make install

Nginx conf

Syntax: ip2region_db xdb_file_path [cache_policy 可选]; Context: http

cache_policy: file or vectorIndex or content, default: content

...
http {

    log_format main escape=json '{'
                                '"remote_addr": "$remote_addr", '
                                '"region": "$ip2region", '
                                '"http_x_forwarded_for": "$http_x_forwarded_for"'
                                '}';

    access_log logs/access.log main;

    # set xdb file path
    ip2region_db ip2region.xdb;

    server {
        listen 80;
        server_name localhost;

        location / {
            root html;
            index index.html index.htm;
        }
    }
}

$ ./configure
--prefix=$(PWD)/../build
--add-module=$(PWD)/../ip2region/binding/nginx

Made with ♥ by Wu Jian Ping