nginx 配置geoip2

geoip2 配置如下

用map获取http_x_forwarded_for里面的第一个IP地址

    map $http_x_forwarded_for $real_ip {
        ~^(\d+\.\d+\.\d+\.\d+) $1;
        default $remote_addr;
    }

    geoip2 /usr/share/GeoIP/GeoLite2-Country.mmdb {
            $geoip2_data_country_code default=CN source=$real_ip country iso_code;
            $geoip2_data_country_name country names en;
    }

取$real_ip变量的值就可以了

猜你喜欢

转载自www.cnblogs.com/xu-xm/p/11765648.html