DEV Community

Cover image for nginx-mod-http-geoip
samnang rosady
samnang rosady

Posted on

nginx-mod-http-geoip

nginx-mod-http-geoip

nginx-mod-http-geoip is an nginx module that allows you to determine the geographical location of an IP address. The geo of country is presented by Alpha-2 code.

You can find ISO ISO’s full, searchable list of all country codes to find your code.

map $geoip_country_code $allowed_country {
  default no;
  RU yes; # <ISO 3166-1 alpha-2> <yes/no>
}

server {
  ...
  if ($allowed_country = no) {
    return 403;
  }
  ...
}
Enter fullscreen mode Exit fullscreen mode

GitHub Sample Repository 🐳

Enjoy you practice 🌟

Top comments (0)