Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
N

ngx_http_geoip2_module

> 编程语言
Open source

Nginx GeoIP2 module

1.1K stars0 likes1 views
WebsiteGitHub

About

Nginx GeoIP2 module

Description

ngx_http_geoip2_module - creates variables with values from the maxmind geoip2 databases based on the client IP (default) or from a specific variable (supports both IPv4 and IPv6)

The module now supports nginx streams and can be used in the same way the http module can be used.

Installing

First install libmaxminddb as described in its README.md file.

Download nginx source

bash
wget http://nginx.org/download/nginx-VERSION.tar.gz
tar zxvf nginx-VERSION.tar.gz
cd nginx-VERSION
To build as a dynamic module (nginx 1.9.11+):
./configure --with-compat --add-dynamic-module=/path/to/ngx_http_geoip2_module
make modules

This will produce objs/ngx_http_geoip2_module.so. It can be copied to your nginx module path manually if you wish.

Add the following line to your nginx.conf:

load_module modules/ngx_http_geoip2_module.so;
To build as a static module:
./configure --add-module=/path/to/ngx_http_geoip2_module
make
make install
If you need stream support, make sure to compile with stream:
./configure --add-dynamic-module=/path/to/ngx_http_geoip2_module --with-stream
OR
./configure --add-module=/path/to/ngx_http_geoip2_module --with-stream

Download Maxmind GeoLite2 Database (optional)

The free GeoLite2 databases are available from Maxminds website (requires signing up)

Example Usage:

…
Metadata:

Retrieve metadata regarding the geoip database.

$variable_name metadata 

Available fields:

  • build_epoch: the build timestamp of the maxmind database.
  • last_check: the last time the database was checked for changes (when using auto_reload)
  • last_change: the last time the database was reloaded (when using auto_reload)
Autoreload (default: disabled):

Enabling auto reload will have nginx check the modification time of the database at the specified interval and reload it if it has changed.

auto_reload 
GeoIP:
$variable_name [default=
        "iso_code":
          "US" 
        "names":
          {
            "de":
              "USA" 
            "en":
              "United States" 
          }
      }
  }

$ mmdblookup --file /usr/share/GeoIP/GeoIP2-Country.mmdb --ip 8.8.8.8 country names en

  "United States" 

This translates to:

$country_name "default=United States" source=$remote_addr country names en
Additional Commands:

These commands works the same as the original ngx_http_geoip_module documented here: http://nginx.org/en/docs/http/ngx_http_geoip_module.html#geoip_proxy.

However, if you provide the source=$variable_with_ip option on a variable, these settings will be ignored for that particular variable.

geoip2_proxy 

Defines trusted addresses. When a request comes from a trusted address, an address from the "X-Forwarded-For" request header field will be used instead.

geoip2_proxy_recursive 

If recursive search is disabled then instead of the original client address that matches one of the trusted addresses, the last address sent in "X-Forwarded-For" will be used. If recursive search is enabled then instead of the original client address that matches one of the trusted addresses, the last non-trusted address sent in "X-Forwarded-For" will be used.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言