Nginx中文文档

HttpGeoIP

This module creates ngx_http_geoip_module variables based on the IP-address of the client matched against the MaxMind GeoIP binary files. This module appeared in nginx version 0.8.6.

本模块ngx_http_geoip_module的变量基于IP地址匹配MaxMind GeoIP 二进制文件. 这个模块开始出现在nginx0.8.6。

Precondition 首先

This module needs the geo databases and the library to read the database.

模块必需有geo数据库和读取数据库类

#下载免费的geo_city数据库
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
#下载免费的geo_coundty数据库
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
#在debian中安装libgeoip:
sudo apt-get install libgeoip-dev
#其它系统,你可以下载并编译一个源文件
wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz

在centos可以用yum安装:

yum install geoip

编译

./configure --with-http_geoip_module

例如

http {
    geoip_country  GeoIP.dat;
    geoip_city     GeoLiteCity.dat;
    ...

指令

geoip_country

syntax: geoip_country path/to/db.dat;

default: none

context: http

The directive indicates the path to the .dat file used for determining the visitor's country from the IP-address of the client. When set the module makes available the following variables:

dat文件用于判断访问者IP中的国家。当前模块 下可用的变量 :

If you only need the country's name, you can just set the geoip_country database(1.1M), while the geoip_city database is much bigger(43M) and all the databses will be cached in memory.

如果你只需要国家,你只需设置geoip_country数据库(1.1M), 但城市的ip数据库就比较大(43M)并且将加载到内存当缓存。

geoip_city

syntax: geoip_city path/to/db.dat;

default: none

context: http

The directive indicates the path to the .dat file used for determining countries, regions and cities from IP-address of the client. When set the module makes available the following variables:

dat文件用于判断访问者IP中的国家、省,城市。当前模块 下可用的变量:

References

Original Documentation