geoip_country         /opt/geoip/GeoIP.dat;
geoip_city            /opt/geoip/GeoLiteCity.dat;
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;
    }

    #通过访问/myip可以获取相应的ip和geo信息
    location /myip {
         default_type "text/plain";
         return 200 "$remote_addr $geoip_country_name $geoip_country_code $geoip_city";
    }

}


备份地址: 【nginx-geoip-module