Using GeoIP2

Francis Daly francis at daoine.org
Fri Jun 21 07:46:04 UTC 2019


On Wed, Jun 19, 2019 at 08:05:13PM -0500, Peter Fraser wrote:

Hi there,

>      geoip2 /usr/local/etc/nginx/GeoIP2/GeoIP2-Country.mmdb {
>         auto_reload 5m;
>         $geoip2_metadata_country_build metadata build_epoch;
>         $geoip2_data_country_code default=US source=$variable_with_ip country iso_code;
>         $geoip2_data_country_name country names en;
>      }

> I am realizing I don’t fully understand what all this does. The part source=$variable_with_ip country iso_code. I am trying to understand, what should go there.

A web search for "nginx geoip2 module" pointed me to
https://www.nginx.com/products/nginx/modules/geoip2/ and to
https://github.com/leev/ngx_http_geoip2_module; and the first does also
point to the second.

The documentation there says "If source is not specified, $remote_addr
will be used to perform the lookup" (the surrounding context is probably
helpful for those docs).

My reading of that is that, assuming the (common) case where the IP
address that you want to geo-locate is in the nginx variable $remote_addr,
you can either write source=$remote_addr, or omit source= entirely.

The rest of that config line is described in those docs -- very roughly as
"like what the mmdblookup tool does".

I hope this helps,

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list