Geolocation of IP addresses and MaxMind GeoIP2
Due to the "Regulation against unjustified geo-blocking in the internal market" and the strong, legal restriction of this technology introduced with it, the topic of geo-blocking has become the focus of public attention.
What is geo-blocking?
Geoblocking works by allowing websites to change their behavior based on the country in which the website visitor is located. This is common practice in the film and music industry, for example. It uses geoblocking to be able to market content as many times as possible in different countries. Anyone who once tried to watch a YouTube video and only got the error message "Sorry, this video is not available in your country" knows this. Despite the "geoblocking ban", there is nothing wrong with country allocation. Many websites use it to preselect languages or display country-specific content. This remains permissible even after the change of the legislation.
Geoblocking or just geolocation?
The recognition of the country - also called geolocation - is based on the customer's IP address. The individual IP address belongs to a block of addresses that has been assigned to a provider by a registration authority. In Europe, RIPE (Réseaux IP Européens) is responsible for this. If you now know which provider "owns" the IP, you very likely also know the country in which the IP is used. The information about the IP provider assignment is basically public, but distributed over five different registries worldwide . There are various providers who collect the information and compile it into a usable database. Of course, you have to regularly update these databases, because IP addresses change hands frequently.
One representative of such databases is the MaxMind GeoIP2, which we have often used for such purposes so far. For this, there was the module mod_geoip2, which was integrated into the web server and enriched the incoming request with geo-information based on the requesting IP address. Applications and content management systems could then use this information for their purposes. mod_geoip2 also has the advantage that it can work together with mod_rpaf. We need the latter in setups where HTTP caches like Varnish or load balancers are used, so that Apache knows the correct original client IP addresses.
Effects in practice
In terms of performance, all three methods are quite equal. There are measurements from 2016 that compare the PHP implementation to the Apache module. No significant speed difference beyond the measurement inaccuracy was proven there. Since PHP 7.0 and 7.2 have again increased the execution speed considerably, we do not expect performance losses.
Please feel free to share this article.
Comments
No comments yet.