约 96 字 预计阅读 1 分钟
Nginx获取客户端地理位置
如何在nginx中获取nginx的ip地址。
- 使用geoip2
- 使用ngx_http_geoip2_module模块
步骤
1
|
yum install geoip geoip-devel -y
|
1
|
yum install -y libmaxminddb-devel
|
1
|
mmdblookup --file /usr/local/geoip/GeoLite2-City/GeoLite2-City.mmdb --ip 183.195.99.161
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
geoip2 /usr/local/geoip/GeoLite2-Country/GeoLite2-Country.mmdb{
$geoip2_data_country_code country iso_code ;
$geoip2_data_country_name country names zh-CN;
}
geoip2 /usr/local/geoip/GeoLite2-City/GeoLite2-City.mmdb {
$geoip2_data_country_code country iso_code;
$geoip2_data_country_name country names zh-CN;
$geoip2_data_city_name city names zh-CN;
$geoip2_data_province_name subdivisions 0 names en;
$geoip2_data_province_isocode subdivisions 0 iso_code;
$geoip2_continent_code continent code;
$geoip2_data_city_name default=China;
}
|
1
2
|
log_format main escape=json '$remote_addr - $remote_user [$time_local] '
'"$geoip2_data_country_name" "$geoip2_data_city_name" ';
|
参考