Overriding which IP address the GeoIP features use

By default the GeoIP lookup is based on the IP address of the user. In some cases, such as with traffic through proxies, this type of lookup doesn't work properly. In particular, users of Opera Mini always browse through a proxy and the true IP address appears in the X-Forwarded-For header. Similarly, the Amazon Silk browser can optionally come through a proxy, indicated via the User Agent string.

To work around this, you can set this variable to account for both the Opera Mini and Amazon Silk browsers:

set geoip.use_x_forwarded_for = true;

To do so, you would use code like this in vcl_recv:

if (req.http.X-OperaMini-Features || req.http.User-Agent ~ " Silk-Accelerated=true$") {
  set geoip.use_x_forwarded_for = true;

which tells Fastly to use the X-Forwarded-For header for the IP address. If it is not available, then the code will fall back to using the IP address of the client.

Finally, just in case there's some scenario or browser we haven't anticipated, you can also override based on an arbitrary header:

set geoip.ip_override = req.http.Custom-IP-Override;

Setting either of these variables:

set geoip.use_x_forwarded_for = true;
set geoip.ip_override = req.http.Custom-IP-Override;

will force the GeoIP information to be reloaded.

Back to Top