RT Cunningham

GDPR Revisited – How to Block those European Union Countries

May 25, 2018 was proclaimed “GDPR Day” by a bunch of online publications, mostly tech pubs. I just read an article at Techdirt where the author was none too enthusiastic about the GDPR.

Me, I’m not worried about it with my website. I have a way to avoid issues with some simple (to me, anyway) server code, followed by some SSI code on the web pages themselves should I need to go that far.

GDPR Countries

The EU GDPR country list can be found here. As of today, 28 countries are members, including the United Kingdom. The UK will probably leave the EU eventually because of “Brexit”.

With Nginx (or any web server supporting GeoIP country codes), the country codes are:

AT, BE, BG, EU, HR, CY, CZ, DK, EE, FI, FR, DE, GR, HU, IE, IT, LV, LT, LU, MT, NL, PL, PT, RO, SK, SI, ES, SE, UK, GB, and IE

I included EU (naturally), GB and IE. I’ve never seen the UK country code being used anywhere and it’s better to be safe than sorry. I’ll explain how I use country codes with Nginx and server-side includes (SSI) in just a moment.

I explained something like this in an article about geographical targeting way back in 2014. I stopped using it shortly after I started.

GDPR Blocking

With Nginx, it’s easy to block the country codes I provided above. I don’t want to repeat myself, so please refer to the page I just referenced to install the GeoIP legacy code and data. A cron job and wget is the best way to keep the data up-to-date.

I have no reason to block any of the EU countries. Not yet anyway. If I choose to block them for displaying ads, for example, this is how I would do it.

First, I would add these lines to my server configuration:

set $showads 1;
if ($geoip_country_code ~ (AT|BE|BG|HR|CY|CZ|DK|EE|FI|FR|DE|GR|HU|IE|IT|LV|LT|LU|MT|NL|PL|PT|RO|SK|SI|ES|SE|UK|GB|IE)) { set $showads 0; }

Second, I would insert this line just before each ad:

<!--# if expr="$showads = 1" -->

Finally, I would follow each ad with:

<!--# endif -->

Yes, I’ve already tested it to make sure it works as advertised. Anyway, I’m more likely to use this routine for things other than blocking ads being displayed to people in the European Union. Although… I’ll definitely use it if I get invalid clicks from places like China.


May 26, 2018
Web Development

You May Also Like: