When developing a Drupal application on Acquia Cloud you may have the need to utilize the geographical location data and/or IP addresses of your visitors for application functionality. This article is for customers that don’t have Cloudflare or Akamai and want to use GeoIP functionality in their Acquia-hosted Drupal application code.
To implement this feature, dedicated load balancers are required because the configuration involves Varnish customizations. Specifically, to add geographical functionality to Varnish, an additional Varnish Configuration Language file provides the country code of the user to the Drupal application. If your application doesn't currently utilize dedicated load balancers you can talk to your account manager to add them.
Image: Diagram showing GeoIP on Acquia Cloud with Varnish.
Once you have the requisite architecture, customers can request to have Acquia enable IP-address-based country identification on their dedicated load balancer pair. This process adds an addon-geoip.vcl file to the customer's Varnish layer.
Once this is enabled, backend applications will start receiving the HTTP request header X-Geo-Country with a two-character ISO_3166-1_alpha-2 country identifier.
At this point the development team can add logic to the Drupal application to leverage the geographic data. This can be done multiple ways including in Drupal via PHP using the server variable:
or within .htaccess as:
For more context on use cases, please see How to Use GeoIP Headers.
If you need further help, please reach out to your account team and/or Acquia Support.
When there’s no country, this is presumably because the data in the request header X-Forwarded-For didn’t match a valid IPv4 or IPv6 address. In these cases the header will be X-Geo-Country: AA.
Also reference: Using GeoIP Information - Make country codes available with Maxmind