### HttpGeoIP
This module creates ngx_http_geoip_module variables based on the IP-address of the client matched against the [MaxMind](http://www.maxmind.com/ "http://www.maxmind.com/") GeoIP binary files. This module appeared in nginx version 0.8.6.
本模块ngx_http_geoip_module的变量基于IP地址匹配[MaxMind](http://www.maxmind.com/) 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中的国家。当前模块 下可用的变量 :
- $geoip_country_code; -国家名的前两个字母, 如, "RU", "US".
- $geoip_country_code3; - 国家名的前三个字母, 如, "RUS", "USA".
- $geoip_country_name; -国家名称, 如, "Russian Federation", "United States".
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中的国家、省,城市。当前模块 下可用的变量:
- $geoip_city_country_code; -国家名的前两个字母, 如, "RU", "US".
- $geoip_city_country_code3; - 国家名的前三个字母, 如, "RUS", "USA".
- $geoip_city_country_name; -国家名称, 如, "Russian Federation", "United States".
- $geoip_region; - 省,州或区名 (province, region, state, province, federal land, and the like), 如, "Moscow City", "DC".
- $geoip_city; - 城市名称, 如, "Moscow", "Washington".
- $geoip_postal_code; - 邮政编号.
### References
[Original Documentation](http://sysoev.ru/nginx/docs/http/ngx_http_geoip_module.html "http://sysoev.ru/nginx/docs/http/ngx_http_geoip_module.html")
- 主要文档
- Nginx功能概述
- 为什么选择Nginx
- Nginx安装
- 运行和控制Nginx
- 配置符号参考
- 优化 Nginx
- 常见问题(FAQ)
- 调试 nginx
- 核心模块
- Nginx主模块
- Nginx事件模块
- 基本模块
- http核心模块
- HttpIndex模块
- HttpAccess模块
- HttpAuthBasic模块
- HttpAutoindex模块
- Browser模块
- Charset模块
- HttpEmptyGif模块
- HttpFcgi模块
- Geo模块
- HttpGzip模块
- HttpHeaders模块
- HttpIndex模块
- HttpReferer模块
- HttpLimit zone
- HttpLimitReqest模块
- HttpLog模块
- map
- Memcached
- HttpProxy模块
- HttpRewrite模块
- HttpSSI模块
- HttpUserId
- 其他模块
- Addition模块
- EmbeddedPerl
- flv
- HttpGzipStatic
- RandomIndex
- HttpGeoIP
- HttpRealIp
- HttpSSL
- StubStatus模块
- HttpSubstitution
- HttpDav模块
- GooglePerftools
- HttpXSLT
- HttpSecureLink
- HttpImageFilter
- mail模块
- MailCore
- MailAuth
- MailProxy
- MailSSL
- 安装
- nginx在windows上的安装
- nginx在freebsd上的安装
- nginx在ubuntu上的安装
- nginx在fedora上的安装
- nginx php-fpm安装配置
- 配置示例和方法
- 完整例子
- 完整例子2
- 虚拟主机
- 负载均衡
- nginx防盗链
- HWLoadbalancerCheckErrors