S
S
Shing2015-12-11 22:14:45
linux
Shing, 2015-12-11 22:14:45

How to make GeoIP work?

Geoip is worth it. Databases are filled with /usr/share/GeoIP
phpinfo shows
/etc/php.d/geoip.ini
geoip extension version 1.0.8
geoip library version 1004005
geoip.custom_directory no value no value
Extension=geoip.so
line is written in php.ini Nginx is built along with the geo module, nginx -V confirms this. It is written in nginx.conf

# GeoIP
    geoip_country  /usr/share/GeoIP/GeoIP.dat; # the country IP database
    geoip_city     /usr/share/GeoIP/GeoLiteCity.dat; # the city IP database
 ### SET FASTCGI Variables ###
  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;

In fastcgi_params too
# 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;

php -m | grep geoip
PHP Warning:  Module 'geoip' already loaded in Unknown on line 0
geoip

And in the test file does not even determine the country.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mihelsonkk, 2015-12-13
@mihelsonkk

Why do you need an extension in php-fpm?
Nginx sets variables and proxies the request to php-fpm
In the php script, check for the presence of the desired values ​​in the $_SERVER array
print_r($_SERVER);

X
XakRu, 2015-12-12
@XakRU

Why do you need GeoIP in php-fpm and NGINX? Maybe you don't need it if you don't know how to use it?
No goal, no goal, no method.
It's like asking - the tractor won't start, I pressed all the buttons, put it on everywhere, but it doesn't go.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question