client.geo.ip_override

STRING, can be read and set, but not unset.

Available inall subroutines.

Override the IP address for geolocation data. The default is to use client.ip as the source for geolocation.

On services that have shielding enabled, the value of client.ip may be the address of another Fastly data center rather than the address of the end user. To access the end-user's geolocation data while on a shield server (which can be determined using the fastly.ff.visits_this_service variable), override the IP address using client.geo.ip_override.

When Fastly sees a request for the first time, we set the Fastly-Client-IP header to the value of client.ip. This value is not updated by upstream Fastly servers, which makes it useful for this purpose:

if (fastly.ff.visits_this_service > 0) {
set client.geo.ip_override = req.http.Fastly-Client-IP;
}

Invalid addresses

It is possible to set client.geo.ip_override to an invalid IP address

set client.geo.ip_override = "xxx";

in which case the various geolocation variables present values to indicate an invalid region. STRING variables are set to the empty string, FLOAT variables are set to 999.0, and INTEGER variables are set to 0.

Try it out

client.geo.ip_override is used in the following code examples. Examples apply VCL to real-world use cases and can be deployed as they are, or adapted for your own service. See the full list of code examples for more inspiration.

Click RUN on a sample below to provision a Fastly service, execute the code on Fastly, and see how the function behaves.

Geo-IP API at the edge

Create an API endpoint for fetching geolocation data for the requesting browser, implemented 100% at the edge. The response should show your current approximate location, but no requests to any origin servers.

Comprehensive logging

Fastly offers a myriad of different variables that you can log. See and test a large collection here.