IP 地址的 HAProxy 地理定位图不匹配任何条目

HAProxy Geolocation map of ip addresses not matching any entries

我的 haproxy 配置中有以下行:

http-request set-header x-geoip-country %[src,map(/etc/hap1.8/geo/country_iso_code.map)]

设置原产国,但只有当密钥是确切的密钥 ip 而不是 haproxy 期望的 CIDR 表示法 ips 时它才有效。该列表来自 maxmind,其格式如下;

1.0.0.0/24 AU
1.0.1.0/24 CN
1.0.16.0/20 JP
...

例如 1.0.0.45 的 ip 将匹配文件中的 1.0.0.45 而不是 1.0.0.0/24。虽然这看起来合乎逻辑,但它是在 haproxy 上的一个示例,所以我想问它是否可以与 10.0.0.0/24 匹配?

默认情况下,map 将按字符串匹配,而不是按 ip。来自 docs:

map_<match_type>(<map_file>[,<default_value>])

... If the <match_type> is not set, it defaults to "str" ...

通过ip匹配使用map_ip:

http-request set-header x-geoip-country %[src,map_ip(/etc/hap1.8/geo/country_iso_code.map)]