geoip_country
The `geoip_country` directive is used to specify the location of the GeoIP database to enable IP-based geolocation in NGINX.
Description
The geoip_country directive allows you to point NGINX to the GeoIP database needed for performing geolocation based on the IP addresses of clients. When configured, NGINX can assign geographical information, such as the country of origin, to the requests. This information can subsequently be used for access control or content customization, ensuring that the server can adapt its responses based on users' locations.
The directive accepts one or two arguments: the path to the GeoIP database file and an optional 'country' option. If provided, this enables or disables specific country lookup features or alters behavior regarding the database's usage. This functionality is essential when organizations need to enforce region-based policies, target advertising, or serve localized content, as it helps identify the source location of incoming requests accurately.
By integrating with the GeoIP module, it enables the server to dynamically identify the user's country, allowing for rules to be tied to specific geographical locations. Note that it requires an external database that must be regularly updated to maintain accurate geolocation mappings.
Config Example
geoip_country /path/to/geoip.dat;
Ensure that the GeoIP database file is accessible by the NGINX worker process, or it will fail to load.
The directive must be set in the http context and not allowed in server or location contexts.
If the GeoIP database path is incorrect or the file is missing, NGINX will log an error and override the directive to 'off'.