- 可能很多網上博客都說在上圖所示網址下載,但是經過測試好幾次後,發現頁面是找不到的,這兒有一個暫時可以用的網址:https://src.fedoraproject.org/lookaside/pkgs/GeoIP/GeoLiteCity.dat.gz/2ec4a73cd879adddf916df479f3581c7/GeoLiteCity.dat.gz
- 解壓
- 在/etc/nginx/nginx.conf加載模塊:
load_module "modules/ngx_http_geoip_module.so"; load_module "modules/ngx_stream_geoip_module.so";
-
在conf裏面加載的conf文件的配置:
geoip_country /home/admin/software/Nginx/GeoIP.dat; geoip_city /home/admin/software/Nginx/GeoLiteCity.dat; #upstream dynamic { # server 127.0.0.1:8080; #} server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { if ($geoip_country_code != CN) { return 403; } root /usr/share/nginx/html; index index.html index.htm; } location /where { default_type 'text/plain'; return 200 "$remote_addr $geoip_country_name $geoip_country_code $geoip_city"; } # location ~.*\.jsp { # proxy http://dynamic; # index index.html index.htm; # }
-
最終成果:
geoip地理位置獲取
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.