Title: IP geolocation
Author: WordPress VIP Documentation
Published: February 1, 2023
Last modified: February 18, 2026

---

 1. [Caching](https://docs.wpvip.com/caching/)
 2. [Page cache](https://docs.wpvip.com/caching/page-cache/)
 3. [Customize page cache behavior](https://docs.wpvip.com/caching/page-cache/customize-behavior/)
 4. IP geolocation

#  IP geolocation

The VIP [edge cache](https://docs.wpvip.com/infrastructure/edge-servers/) respects
a set of geolocation response headers that make it possible to deliver variations
of cached content based on the end user’s global location. Logic at the edge leverages
the geolocation response headers to determine which specific cached version will
be delivered in a response.

## Limitations

 * `Vary` responses should be limited to a specific set of page URLs that absolutely
   require it. Adding a `Vary` response for every page can negatively affect the
   page cache hit ratio and overall performance of a site. For Node.js applications
   built on Next.js, the `source` property can be utilized to [match specific paths](https://nextjs.org/docs/api-reference/next.config.js/headers#path-matching).
 * **Geolocation on the VIP Platform is not reliable for sites behind a [reverse proxy](https://docs.wpvip.com/reverse-proxy/).**
   Requests that pass through a reverse proxy for a site on VIP will have the remote
   IP address of the reverse proxy instead of the requester’s IP address. When using
   a reverse proxy, it is possible that the correct country might be served to the
   end user, but in most cases, it will be incorrect.

## Geolocation headers

Geolocation response headers can be used by both WordPress and Node.js applications.

Each geolocation response header has a corresponding superglobal variable that can
be used by WordPress applications in PHP.

This recognized set of location response headers is powered by the Maxmind GeoIP
® database and kept current by WordPress VIP.

| Response header (Node.js) | Superglobal variable (WordPress) | Description | 
| `x-continent` | `GEOIP_CONTINENT` | A two-character code for the continent | 
| `x-country-code` | `GEOIP_COUNTRY_CODE` | ISO 3166-1 country code | 
| `x-region` | `GEOIP_REGION` | Represents a ISO 3166-2 code of a first level subdivision | 
| `x-metro-code` | `GEOIP_METRO_CODE` | The metro code of the location associated with the IP address. Only valid if the location is within the United States. These codes are consistent with the metro_codes used by Google AdWords API. | 
| `x-city` | `GEOIP_CITY` | City name | 
| `x-postal-code` | `GEOIP_POSTAL_CODE` | The postal code of the location associated with the IP address. Postal codes are not available for all countries. In some countries, this will only contain part of the postal code. |

### `x-continent` response header

The value of the `x-continent` HTTP response header is a two-character code for 
the continent associated with the IP address.

| `x-continent` response | Response description | 
| `AF` | Africa | 
| `AN` | Antarctica | 
| `AS` | Asia | 
| `EU` | Europe | 
| `NA` | North America | 
| `OC` | Oceania | 
| `SA` | South America |

_All possible values for the `x-continent` HTTP response header and their descriptions_

## Geolocation in PHP

WordPress applications on the VIP Platform can leverage the predefined superglobal
variables for geolocation. For example, to vary the cache for users based on their
city, logic in the application’s code can leverage:

    ```lang-php
    $_SERVER['GEOIP_CITY']
    ```

All cached geolocation versions of a page or a post’s URL will be invalidated when
that page or post is updated.

## VIP Go Geo Uniques plugin

The [VIP Go Geo Uniques plugin](https://github.com/Automattic/vip-go-geo-uniques)
is specifically designed for WordPress sites on the VIP Platform and is currently
limited to leveraging the `$_SERVER['GEOIP_COUNTRY_CODE']` superglobal described
above.

A default country code and a list of supported country codes must be configured 
for the plugin to efficiently deliver different versions of content from the page
cache to users based on location. More detailed instructions for installation and
usage can be found in [the plugin’s GitHub repository](https://github.com/Automattic/vip-go-geo-uniques).

## Geolocation for Node.js

Node.js applications can read the location data of a request from the corresponding
location header.

The exact methods required to read the value of the geolocation response headers
and to set response headers to vary the cache is specific to an application’s Node.
js framework. To identify the correct method, search the framework’s documentation
for terms similar to “setting response headers”.

Example code in [the vip-go-node-skeleton](https://github.com/Automattic/vip-go-node-skeleton/blob/4b97a6071f1614bbaea92c9afc98167704c7921c/src/index.js#L18)
repository demonstrates passing a request object to the server as `req`. In that
use case, the country code value of a request can be be retrieved with:

    ```lang-js
    req.headers['x-country-code']
    ```

Last updated: February 18, 2026