Skip to content

IP geolocation

The VIP edge cache respects the vary: X-Country-Code response header, making it possible to deliver variations of cached content based on an end user’s global location. Logic at the edge determines which specific cached version will be delivered in response to a user’s request based on the country code value in the incoming X-Country-Code request header.

  • The X-Country-Code request header can be leveraged by both WordPress and Node.js applications.
  • For WordPress sites, updating a post or page will invalidate the cached versions of a URL for all country codes.

Limitations

Geolocation on the VIP Platform is not reliable for sites behind a 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 for Node.js

Setting response headers will work differently across Node.js frameworks. Searching for “setting response headers” in the framework’s documentation will generally surface the correct approach.

Ideally, Vary responses should be limited to 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.

Geolocation in PHP

WordPress applications on the VIP Platform can leverage the $_SERVER['GEOIP_COUNTRY_CODE'] superglobal for geolocation. This superglobal is set to an ISO-3166 country code (ISO-3166-1 alpha-2) based on a site visitor’s IP address. The recognized set of country codes is powered by the Maxmind GeoIP database and kept current by VIP.

VIP Go Geo Uniques plugin

The VIP Go Geo Uniques plugin is specifically designed for WordPress sites on the VIP Platform and leverages 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.

Last updated: March 11, 2024

Relevant to

  • Node.js
  • WordPress