Comment accorder l’access à une adresse IP spécifique bloquée par GeoIP dans nGinx?

Impossible de trouver une solution pour résoudre ce problème. Voici comment j’ai bloqué un access au pays et en même temps j’ai besoin d’accéder à une adresse IP spécifique provenant d’un pays bloqué.

Enfin trouvé la solution à ce problème.

1) dans nginx.conf add

http { geoip_country /usr/share/GeoIP/GeoIP.dat; map $geoip_country_code $allowed_country { default no; LV yes; # in my case it is Latvia (allowed country, but all other are not) } geo $exclusions { default 0; 123.123.123.123 1; # here comes allowed IP that is in blocked country list } } 

2) dans votre conteneur de configuration vhost {}

 if ($allowed_country = yes) { set $exclusions 1; } if ($exclusions = "0") { return 403; } 

L’idée principale est ICI

En bloc http

 geoip_country /usr/local/share/GeoIP/GeoIP.dat; map "$geoip_country_code:$remote_addr" $allowed_country { default yes; "~..:10.11.12.13" yes; "~..:11.12.13.14" no; "~TR:.*" no; } 

Dans le bloc serveur

 if ($allowed_country = no) { return 403; }