<!-- review: finished -->

<a id="http-geoip"></a>

# GeoIP

Creates variables with values depending on the client IP address,
using the precompiled [MaxMind](http://www.maxmind.com/) databases
or their counterparts.

When using the databases with IPv6 support,
IPv4 addresses are looked up as IPv4-mapped IPv6 addresses.

When [building from the source code](https://en.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild),
this module isn't built by default;
it should be enabled with the
`‑‑with‑http_geoip_module`
[build option](https://en.angie.software//angie/docs/installation/sourcebuild.md#configure).

#### NOTE
This module requires the [MaxMind GeoIP](https://www.maxmind.com/en/geoip-databases) database
or a counterpart such as [MaxMind GeoLite2](https://dev.maxmind.com/geoip/geolite2-free-geolocation-data).

<a id="configuration-example-17"></a>

## Configuration Example

```nginx
http {
    geoip_country         GeoIP.dat;
    geoip_city            GeoLiteCity.dat;
    geoip_proxy           192.168.100.0/24;
    geoip_proxy           2001:0db8::/32;
    geoip_proxy_recursive on;
    ...
```

<a id="directives-18"></a>

## Directives

<a id="index-0"></a>

<a id="geoip-country"></a>

### geoip_country

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `geoip_country` file;   |
|------------------------------------------------------------------------------------------|-------------------------|
| Default                                                                                  | —                       |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                    |

Specifies a database used to determine the country depending on the client IP address. The following variables are available when using this database:

| `$geoip_country_code`   | two-letter country code, for example, "RU", "US".                 |
|-------------------------|-------------------------------------------------------------------|
| `$geoip_country_code3`  | three-letter country code, for example, "RUS", "USA".             |
| `$geoip_country_name`   | country name, for example, "Russian Federation", "United States". |

<a id="index-1"></a>

<a id="geoip-city"></a>

### geoip_city

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `geoip_city` file;   |
|------------------------------------------------------------------------------------------|----------------------|
| Default                                                                                  | —                    |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                 |

Specifies a database used to determine the country, region, and city depending on the client IP address. The following variables are available when using this database:

| `$geoip_city_continent_code`   | two-letter continent code, for example, "EU", "NA".                                                                                                                                   |
|--------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `$geoip_city_country_code`     | two-letter country code, for example, "RU", "US".                                                                                                                                     |
| `$geoip_city_country_code3`    | three-letter country code, for example, "RUS", "USA".                                                                                                                                 |
| `$geoip_city_country_name`     | country name, for example, "Russian Federation", "United States".                                                                                                                     |
| `$geoip_dma_code`              | DMA region code in US (also known as "metro code"), according to the [geotargeting](https://developers.google.com/adwords/api/docs/appendix/cities-DMAregions) in Google AdWords API. |
| `$geoip_latitude`              | latitude.                                                                                                                                                                             |
| `$geoip_longitude`             | longitude.                                                                                                                                                                            |
| `$geoip_region`                | two-symbol country region code (region, territory, state, province, federal land and the like), for example, "48", "DC".                                                              |
| `$geoip_region_name`           | country region name (region, territory, state, province, federal land and the like), for example, "Moscow City", "District of Columbia".                                              |
| `$geoip_city`                  | city name, for example, "Moscow", "Washington".                                                                                                                                       |
| `$geoip_postal_code`           | postal code.                                                                                                                                                                          |

<a id="index-2"></a>

<a id="geoip-org"></a>

### geoip_org

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `geoip_org` file;   |
|------------------------------------------------------------------------------------------|---------------------|
| Default                                                                                  | —                   |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                |

Specifies a database used to determine the organization depending on the client IP address. The following variable is available when using this database:

| `$geoip_org`   | organization name, for example, "The University of Melbourne".   |
|----------------|------------------------------------------------------------------|

<a id="index-3"></a>

<a id="geoip-proxy"></a>

### geoip_proxy

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `geoip_proxy` address | CIDR | unix:;   |
|------------------------------------------------------------------------------------------|-----------------------------------------|
| Default                                                                                  | —                                       |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                    |

Defines trusted addresses. When a request comes from a trusted address, an address from the `X-Forwarded-For` request header field will be used instead.

<a id="index-4"></a>

<a id="geoip-proxy-recursive"></a>

### geoip_proxy_recursive

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `geoip_proxy_recursive` `on` | `off`;   |
|------------------------------------------------------------------------------------------|-----------------------------------------|
| Default                                                                                  | `geoip_proxy_recursive off;`            |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                    |

If recursive search is disabled then instead of the original client address that matches one of the trusted addresses, the last address sent in `X-Forwarded-For` will be used. If recursive search is enabled then instead of the original client address that matches one of the trusted addresses, the last non-trusted address sent in `X-Forwarded-For` will be used.
