发布于 2015-09-20 00:05:58 | 239 次阅读 | 评论: 0 | 来源: 网络整理

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中的国家。当前模块 下可用的变量 :

  • $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

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务