GItHub:https://github.com/TravelEngineers/ngx_http_geoip2_module
DB文件下载
先注册用户:https://dev.maxmind.com/geoip/geoip2/geolite2/
进入下载页面:https://www.maxmind.com/en/accounts/455551/geoip/downloads
log_format main escape=json ‘{"remote_addr":"$remote_addr",‘ ‘"timestamp":"$time_local",‘ ‘"country":"$geoip2_data_country_name",‘ ‘"city":"$geoip2_city_name",‘ ‘"method":"$request_method",‘ ‘"request":"$uri",‘ ‘"requestParam":"$query_string",‘ ‘"status":"$status",‘ ‘"referrer":"$http_referer",‘ ‘"agent":"$http_user_agent",‘ ‘"elapsed":"$request_time",‘ ‘"serverelapsed":"$upstream_response_time"}‘; geoip2 /usr/local/nginx/conf/GeoLite2-Country.mmdb { auto_reload 5m; $geoip2_metadata_country_build metadata build_epoch; $geoip2_data_country_code default=US country iso_code; $geoip2_data_country_name country names en; } geoip2 /usr/local/nginx/conf/GeoLite2-City.mmdb { $geoip2_city_name default=BeiJing city names en; $geoip2_continent_code continent code; }
原文:https://www.cnblogs.com/wjoyxt/p/14087434.html