注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

老和山小和尚

敬天爱人

 
 
 

日志

 
 
 
 

ngx_http_geoip_module (nginx geoip模块使用)  

2009-07-21 15:43:14|  分类: Nginx |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

1. Get the souce and the library
#Get the latest version of nginx
wget http://sysoev.ru/nginx/nginx-0.8.6.tar.gz
#Get the free database of geo_city
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
#Get the free database of geo_coundty
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
#Get the libgeoip. In debian you can do like this:
sudo apt-get install geoip-bin libgeoip-dev libgeoip1
#In other systems, you can download the source and compile it youself.
wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz

2. Compile nginx with geoip module:
./configure --with-http_geoip_module

3. Configure the nginx, add the path of geo database files.  Like this:
http {
      geoip_country GeoIP.dat;
      geoip_city GeoLiteCity.dat;
      ...
}

4. Use the variables:
a. If you set the geoip_country directive, these variables can be use:
$geoip_country_code; - two-letter country code, for example, "RU", "US".
$geoip_country_code3; - three-letter country code, for example, "RUS", "USA".
$geoip_country_name; - the name of the country, for example, "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 the memory.

b. If you set the geoip_city directive, these variables can be use:
$geoip_city_country_code; - two-letter country code, for example, "RU", "US".
$geoip_city_country_code3; - three-letter country code, for example, "RUS", "USA".
$geoip_city_country_name; - the name of the country, for example, "Russian Federation", "United States".
$geoip_region; - the name of region (province, region, state, province, federal land, and the like), for example, "Moscow City", "DC".
$geoip_city; - the name of the city, for example, "Moscow", "Washington".
$geoip_postal_code; - postal code.



  评论这张
 
阅读(1669)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018