====== Nginx GEOIP ======


Иногда может понадобиться вариант, когда нужно проводить маршрутизацию запросов веб-приложения в зависимости от местоположения (или языка) пользователя. Тут нам на помощь придёт модуль nginx [[http://wiki.nginx.org/HttpGeoIPModule|HttpGeoIPModule]]. Устанока будет производиться на Nginx +php5_fpm (и у меня уже есть его конфиг).

===== Установка =====

  * sudo apt-get install geoip-database libgeoip-dev
  * wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
  * gunzip GeoLiteCity.dat.gz
  * sudo mkdir -v /usr/share/GeoIP
  * sudo mv -v GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat

===== Настройка =====


**/etc/nginx/nginx.conf**

  http {
  ....
      # GeoIP
      geoip_country  /usr/share/GeoIP/GeoIP.dat; # the country IP database
      geoip_city     /usr/share/GeoIP/GeoLiteCity.dat; # the city IP database
  ..
  }

**/etc/nginx/fastcgi_params**

  # For GeoIP
  fastcgi_param GEOIP_COUNTRY_CODE   $geoip_country_code;
  fastcgi_param GEOIP_COUNTRY_NAME 	$geoip_country_name;
  fastcgi_param GEOIP_REGION		$geoip_region;
  fastcgi_param GEOIP_CITY		$geoip_city;
  fastcgi_param GEOIP_POSTAL_CODE 	$geoip_postal_code;
  fastcgi_param GEOIP_CITY_CONTINENT_CODE $geoip_city_continent_code;
  fastcgi_param GEOIP_LATITUDE    	$geoip_latitude;
  fastcgi_param GEOIP_LONGITUDE		$geoip_longitude;

Теперь в массиве $_SERVER доступны данные геолокации с префиксом «GEOIP_».

Подробнее: http://nginx.org/ru/docs/http/ngx_http_geoip_module.html
