# nginx 安装geoip 扩展,主配置
- geoip2 /etc/GeoIP/data/GeoLite2-City.mmdb {
- auto_reload 30m;
- $geoip2_data_city_continent_code source=$ip continent code;
- $geoip2_data_city_continent_name source=$ip continent names en;
- #$geoip2_data_city_continent_name source=$ip continent names zh-CN;
- $geoip2_data_city_country_code source=$ip country iso_code;
- $geoip2_data_city_country_name source=$ip country names en;
- $geoip2_data_city_region_code source=$ip subdivisions 0 iso_code;
- $geoip2_data_city_region_name source=$ip subdivisions 0 names en;
- #$geoip2_data_city_region_name source=$ip subdivisions 0 names zh-CN;
- $geoip2_data_city_location_latitude source=$ip location latitude;
- $geoip2_data_city_location_longitude source=$ip location longitude;
- $geoip2_data_city_postal source=$ip postal code;
- $geoip2_data_city_city_name source=$ip city names en;
- #$geoip2_data_city_city_name source=$ip city names zh-CN;
- $geoip2_data_city_location_timezone source=$ip location time_zone;
- }
-
- geoip2 /etc/GeoIP/data/GeoIP2-ISP.mmdb {
- auto_reload 30m;
- $geoip2_data_isp_isp source=$ip isp;
- $geoip2_data_isp_org source=$ip organization;
- }
-
- geoip2 /etc/GeoIP/data/GeoLite2-ASN.mmdb {
- auto_reload 30m;
- $geoip2_data_asn_asn source=$ip autonomous_system_number;
- $geoip2_data_asn_org source=$ip autonomous_system_organization;
- $geoip2_data_asn_network source=$ip network;
- }
-
- geoip2 /etc/GeoIP/data/GeoLite2-Country.mmdb {
- auto_reload 30m;
- $geoip2_metadata_country_build source=$ip metadata build_epoch;
- $geoip2_data_country_name source=$ip country names en;
- #$geoip2_data_country_name source=$remote_addr country names zh-CN;
- $geoip2_data_country_code source=$ip default=US country iso_code;
- }
-
- geoip2 /etc/GeoIP/data/GeoIP2-Connection-Type.mmdb {
- auto_reload 30m;
- $geoip2_data_connectiontype source=$ip connection_type;
- $geoip2_data_network source=$ip network;
- }
复制代码
#网站配置
- set $ip $remote_addr;
- if ($query_string ~ "ip=(d+.d+.d+.d+)"){
- set $ip "$1";
-
- }
-
- location ~ ^/ {
- default_type text/plain;
- charset utf-8;
- if ($http_x_real_ip != "") {
- set $ip $http_x_real_ip;
- }
- return 200 "$ip $geoip2_data_country_name $geoip2_data_city_region_name $geoip2_data_city_city_name $geoip2_data_isp_isp $geoip2_data_asn_org";
- }
-
- location = /text {
- default_type text/plain;
- charset utf-8;
- if ($http_x_real_ip != "") {
- set $ip $http_x_real_ip;
- }
- return 200 "$ipn $geoip2_data_country_namen $geoip2_data_city_country_coden $geoip2_data_city_region_namen $geoip2_data_city_region_coden $geoip2_data_city_city_namen $geoip2_data_city_location_latituden $geoip2_data_city_location_longituden $geoip2_data_city_location_timezonen AS$geoip2_data_asn_asnn $geoip2_data_isp_ispn $geoip2_data_asn_orgn $geoip2_data_connectiontypen $http_user_agentn";
- }
-
- location = /json {
-
- default_type application/json;
- charset utf-8;
- if ($http_x_real_ip != "") {
- set $ip $http_x_real_ip;
- }
-
- return 200 ‘{n "ip": "$ip",n "country": "$geoip2_data_country_name",n "country_code": "$geoip2_data_city_country_code",n "region": "$geoip2_data_city_region_name",n "region_code": "$geoip2_data_city_region_code",n "city": "$geoip2_data_city_city_name",n "latitude": "$geoip2_data_city_location_latitude",n "longitude": "$geoip2_data_city_location_longitude",n "time_zone": "$geoip2_data_city_location_timezone",n "asn": "AS$geoip2_data_asn_asn",n "isp": "$geoip2_data_isp_isp",n "org": "$geoip2_data_asn_org",n "connection_type": "$geoip2_data_connectiontype",n "user_agent": "$http_user_agent"n}’;
- }
复制代码
|