The mod_geoip2 module for Nginx
来源:互联网 发布:微软邮箱软件 编辑:程序博客网 时间:2024/06/16 06:41
The mod_geoip2 module for Nginx
一,关于GEOIP
官网:http://www.maxmind.com/zh/home
通过MaxMind的GeoIP产品,您可以对网络访问者的地点、机构、连网速度 及用户类型加以识别。
GeoIP数据库是现有的最常见、 最准确的IP地理定位数据库。
本文主要介绍的是Geoip2结合Nginx的安装和应用,Geoip(1代)使用更为简单,请参考官方网站。
二,安装ngx_http_geoip2_module的依赖库libmaxminddb
github地址:https://github.com/maxmind/libmaxminddb
注意:按照README.md上的方法,用git clone下来的源码,在编译的时候会报错,原因不明,下载tar包就没有问题。
下载并安装libmaxminddb
三,编译Nginx geoip2模块
github地址:https://github.com/leev/ngx_http_geoip2_module
wget https://github.com/leev/ngx_http_geoip2_module/archive/master.zip
unzip master
mv ngx_http_geoip2_module /user/local/src/
重新编译Nginx
./configure --prefix=/user/local/nginx --add-module=/usr/local/src/ngx_http_geoip2_module
四,应用
免费版Geoip数据库下载地址
http://dev.maxmind.com/geoip/geoip2/geolite2/
以下是Geoip官网根据ip输出maxmind-city.mmdb结构及内容的一个示例:
更多介绍请参考:http://dev.maxmind.com/geoip/geoip2/web-services/
以下是ngx_http_geoip2_modul官方给的应用例子:
## Example Usage:
```
其中geoip2_data方法的第一个参数为自定义的变量名称,变量值可以在Nginx直接写入日志文件或是传递给php变量。
第二个及后面的参数为geoip2 mmdb数据库中的各级字段名称。
注意:在获取省份信息的时候,注意subdivisions字段下面是个数组,获取方法如下:
结合以上例子和数据结构,可根据自己的需要来获得国家、省份、城市等信息。
一,关于GEOIP
官网:http://www.maxmind.com/zh/home
通过MaxMind的GeoIP产品,您可以对网络访问者的地点、机构、连网速度 及用户类型加以识别。
GeoIP数据库是现有的最常见、 最准确的IP地理定位数据库。
本文主要介绍的是Geoip2结合Nginx的安装和应用,Geoip(1代)使用更为简单,请参考官方网站。
二,安装ngx_http_geoip2_module的依赖库libmaxminddb
github地址:https://github.com/maxmind/libmaxminddb
注意:按照README.md上的方法,用git clone下来的源码,在编译的时候会报错,原因不明,下载tar包就没有问题。
下载并安装libmaxminddb
yum -y install autoconf automake libtoolwget https://github.com/maxmind/libmaxminddb/releases/download/0.5.5/libmaxminddb-0.5.5.tar.gztar -zxvf libmaxminddb-0.5.5.tar.gzcd libmaxminddb-0.5.5./configuremake checkmake installldconfig
三,编译Nginx geoip2模块
github地址:https://github.com/leev/ngx_http_geoip2_module
wget https://github.com/leev/ngx_http_geoip2_module/archive/master.zip
unzip master
mv ngx_http_geoip2_module /user/local/src/
重新编译Nginx
./configure --prefix=/user/local/nginx --add-module=/usr/local/src/ngx_http_geoip2_module
四,应用
免费版Geoip数据库下载地址
http://dev.maxmind.com/geoip/geoip2/geolite2/
以下是Geoip官网根据ip输出maxmind-city.mmdb结构及内容的一个示例:
更多介绍请参考:http://dev.maxmind.com/geoip/geoip2/web-services/
{ "city": { "confidence": 25, "geoname_id": 54321, "names": { "de": "Los Angeles", "en": "Los Angeles", "es": "Los Ángeles", "fr": "Los Angeles", "ja": "ロサンゼルス市", "pt-BR": "Los Angeles", "ru": "Лос-Анджелес", "zh-CN": "洛杉矶" } }, "continent": { "code": "NA", "geoname_id": 123456, "names": { "de": "Nordamerika", "en": "North America", "es": "América del Norte", "fr": "Amérique du Nord", "ja": "北アメリカ", "pt-BR": "América do Norte", "ru": "Северная Америка", "zh-CN": "北美洲" } }, "country": { "confidence": 75, "geoname_id": "6252001", "iso_code": "US", "names": { "de": "USA", "en": "United States", "es": "Estados Unidos", "fr": "États-Unis", "ja": "アメリカ合衆国", "pt-BR": "Estados Unidos", "ru": "США", "zh-CN": "美国" } }, "location": { "accuracy_radius": 20, "latitude": 37.6293, "longitude": -122.1163, "metro_code": 807, "time_zone": "America/Los_Angeles" }, "postal": { "code": "90001", "confidence": 10 }, "registered_country": { "geoname_id": "6252001", "iso_code": "US", "names": { "de": "USA", "en": "United States", "es": "Estados Unidos", "fr": "États-Unis", "ja": "アメリカ合衆国", "pt-BR": "Estados Unidos", "ru": "США", "zh-CN": "美国" } }, "represented_country": { "geoname_id": "6252001", "iso_code": "US", "names": { "de": "USA", "en": "United States", "es": "Estados Unidos", "fr": "États-Unis", "ja": "アメリカ合衆国", "pt-BR": "Estados Unidos", "ru": "США", "zh-CN": "美国" }, "type": "military" }, "subdivisions": [ { "confidence": 50, "geoname_id": 5332921, "iso_code": "CA", "names": { "de": "Kalifornien", "en": "California", "es": "California", "fr": "Californie", "ja": "カリフォルニア", "ru": "Калифорния", "zh-CN": "加州" } } ], "traits": { "autonomous_system_number": "1239", "autonomous_system_organization": "Linkem IR WiMax Network", "domain": "example.com", "is_anonymous_proxy": true, "is_satellite_provider": true, "isp": "Linkem spa", "ip_address": "1.2.3.4", "organization": "Linkem IR WiMax Network", "user_type": "traveler", }, "maxmind": { "queries_remaining": "54321" }}
以下是ngx_http_geoip2_modul官方给的应用例子:
## Example Usage:
```
http { ... geoip2_mmdb /etc/maxmind-city.mmdb; geoip2_data $geoip2_data_country_code country iso_code; geoip2_data $geoip2_data_country_name country names en; geoip2_data $geoip2_data_city_name city names en; geoip2_data $geoip2_data_geoname_id country geoname_id; geoip2_data $geoip2_data_latitude location latitude; geoip2_data $geoip2_data_country_code default=US country iso_code; ....}
其中geoip2_data方法的第一个参数为自定义的变量名称,变量值可以在Nginx直接写入日志文件或是传递给php变量。
第二个及后面的参数为geoip2 mmdb数据库中的各级字段名称。
注意:在获取省份信息的时候,注意subdivisions字段下面是个数组,获取方法如下:
geoip2_data $privince subdivisions 0 names en
结合以上例子和数据结构,可根据自己的需要来获得国家、省份、城市等信息。
0 0
- The mod_geoip2 module for Nginx
- Smooth Streaming Module for Nginx
- Python wrapper module for the Spread
- idea not found for the web module.
- nginx module
- how to write a nginx module for http living stream
- Nginx-Lua-Module Manual for ngx_lua v0.10.11
- 编译Nginx提示gzip module requires the zlib library
- How the Kernel compile .c files for Kernel Module
- tomcat 启动not found for the web module
- the output path is not specified for module
- The kernel module programming primer(3)-A brief introduction for module utilities
- nginx ./configure: error: the HTTP rewrite module requires the PCRE library
- nginx安转时报错处理:the HTTP rewrite module requires the PCRE library
- 安装nginx 报“./configure: error: the HTTP gzip module requires the zlib library.”解决方法
- Nginx安装报错:./configure: error: the HTTP rewrite module requires the PCRE library.
- nginx configure error: the HTTP rewrite module requires the PCRE library
- ubuntu安装nginx时提示error: the HTTP rewrite module requires the PCRE library
- JS中URL编码与.net URL解码
- makefile的语法及写法(二)
- 转载 应用程序域
- spring整合cxf 发布restFul风格的webservice
- Hadoop学习线路
- The mod_geoip2 module for Nginx
- 从1.5k到18k, 一个程序员的5年成长之路
- 美国学者谈中国反腐:受贿者和行贿者都应受惩
- JQuery设置和去除disabled属性
- 输入三个整数,按由小到大的顺序输出
- 【php】php中call_user_func_array和call_user_func函数的用法
- 理解class.forName()
- Linux网络编程--单进程服务器处理多客户请求(I/O复用)
- 什么是GAC?它解决了什么问题?