1.Проверка того,что Nginx собран с поддержкой geoip-модуля
1 |
# nginx –V |
1 2 |
……………… --with-http_geoip_module |
2. Скачивание GeoIP-баз
1 |
# mkdir /etc/nginx/geoip |
1 |
# cd /etc/nginx/geoip |
1 |
# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz |
1 |
# gunzip GeoIP.dat.gz |
1 |
# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz |
1 |
# gunzip GeoLiteCity.dat.gz |
3. Настройка GeoIP в Nginx
1 |
# nano /etc/nginx/nginx.conf |
1 2 3 4 5 6 |
http { ………………. geoip_country /etc/nginx/geoip/GeoIP.dat; geoip_city /etc/nginx/geoip/GeoLiteCity.dat; ……………………….. } |
1 |
# nano /etc/nginx/fastcgi_params |
(связка Nginx+PHP-FPM используется)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
### SET GEOIP Variables ### fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code; fastcgi_param GEOIP_COUNTRY_CODE3 $geoip_country_code3; fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name; fastcgi_param GEOIP_CITY_COUNTRY_CODE $geoip_city_country_code; fastcgi_param GEOIP_CITY_COUNTRY_CODE3 $geoip_city_country_code3; fastcgi_param GEOIP_CITY_COUNTRY_NAME $geoip_city_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; |
- Проверка рабостоспособности
1 |
# nano /path_to_sitename/geoiptest.php |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<html> <body> <?php $geoip_country_code = getenv(GEOIP_COUNTRY_CODE); $geoip_country_code3 = getenv(GEOIP_COUNTRY_CODE3); $geoip_country_name = getenv(GEOIP_COUNTRY_NAME); $geoip_city_country_code = getenv(GEOIP_CITY_COUNTRY_CODE); $geoip_city_country_code3 = getenv(GEOIP_CITY_COUNTRY_CODE3); $geoip_city_country_name = getenv(GEOIP_CITY_COUNTRY_NAME); $geoip_region = getenv(GEOIP_REGION); $geoip_city = getenv(GEOIP_CITY); $geoip_postal_code = getenv(GEOIP_POSTAL_CODE); $geoip_city_continent_code = getenv(GEOIP_CITY_CONTINENT_CODE); $geoip_latitude = getenv(GEOIP_LATITUDE); $geoip_longitude = getenv(GEOIP_LONGITUDE); echo 'country_code: '.$geoip_country_code.'<br>'; echo 'country_code3: '.$geoip_country_code3.'<br>;'; echo 'country_name: '.$geoip_country_name.'<br>'; echo 'city_country_code: '.$geoip_city_country_code.'<br>'; echo 'city_country_code3: '.$geoip_city_country_code3.'<br>'; echo 'city_country_name: '.$geoip_city_country_name.'<br>'; echo 'region: '.$geoip_region.'<br>'; echo 'city: '.$geoip_city.'<br>'; echo 'postal_code: '.$geoip_postal_code.'<br>'; echo 'city_continent_code: '.$geoip_city_continent_code.'<br>'; echo 'latitude: '.$geoip_latitude.'<br>'; echo 'longitude: '.$geoip_longitude.'<br>'; ?> </body> </html> |
Обращаемся по
1 |
http://<sitename>/geoiptest.php |
Источник:
http://www.howtoforge.com/using-geoip-with-nginx-on-ubuntu-12.04
http://piwik.org/faq/how-to/faq_166/