GeoIP on Acquia Cloud with Cloud Edge (Powered by Cloudflare)

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. If your team is using a reverse proxy CDN in front of the web stack this process can become slightly more complicated. A simple solution for this use case which I've implemented with multiple enterprise customers is outlined in this article. I'll keep it concise and comment only on the changes that need to be implemented in order to make this work.

In this use case we have Acquia Cloud Edge Powered by Cloudflare in front of a Drupal enterprise web application hosted on Acquia Cloud. The diagram below illustrates the workflow of using geolocation data on Acquia Cloud with Cloudflare in the mix. It is important to note that dedicated load balancers are required with your subscription in this scenario.

GeoIP with Cloud Edge

Image: Diagram showing GeoIP on Acquia Cloud with Cloud Edge (Powered by Cloudflare).

The recommended next step is for customers to add visitor location headers with Managed Transform in their Cloud Edge (Powered by Cloudflare) zone. This Managed Transform adds HTTP request headers with location information for the visitor’s IP address, such as city, country, continent, longitude, and latitude. These additional headers will be utilized by Acquia Cloud to make the geographical information available to your application.

The final piece to the setup is a quick configuration change on the server stack at Acquia. You can talk to your TAM, CSM, or AM or file an Acquia Support ticket and request that Acquia enable CF-Connecting-IP on Acquia Cloud for your application. This can only be completed by Acquia Support engineers. Once this is in place you can use the header in PHP application code like:

$country_code = $_SERVER[HTTP_CF_IPCOUNTRY];

If you need further help, please reach out to your account team and/or Acquia Support.