stream {
geoip2 /var/lib/GeoIP/GeoLite2-Country.mmdb {
        auto_reload 60m;
        $geoip2_metadata_country_build metadata build_epoch;
        $geoip2_data_country_code country iso_code;
    }
}
server {
    listen 15000;
    proxy_pass 192.168.0.118:10204;
}
}

访问15000的流量,如何根据匹配到geoip2_data_country_code的国家代码来进行条件代理,即只代理允许国家的ip,其他国家的都要禁止代理。因为stream模块中不能用if条件语句,现在这个实现变的有些困难,希望得到一点思路,谢谢

    3 months later

    在proxy_pass 上面加入 access_by_lua_file xxx.lua; , 在lua里获取访问IP的 地区,然后拒绝就 ngx.exit(403) ... 有例子的

      Write a Reply...