Basic notes on Geo IP resolving

Note, this documentation is also available in docstrings in the geo module.

Additional changes have been made in univ_drill to ensure that user_country is stored in Logs, if that setting is available in the session. This module handles getting the country code data into the session, and requires the use of a C library, GeoIP, and its relevant data files. Compilation is easy.


Table alterations for univ_drill.log

See geo/sql_changes.sql but be careful on production servers.

Install geoip C library

The C library is required for the geodjango GeoIP object to be able to perform lookups, and what we need out of this is the path of

    tar zxvf GeoIP.dat.gz
    cd into directory
    mkdir /home/univ_oahpa/univ_oahpa/geo/geoip
    ./configure --prefix=/home/univ_oahpa/univ_oahpa/geo/geoip
    make install

Then find the path to that file, which should be:


fetch data files

Here we need two .dat files.

    gzip -d GeoLiteCity.dat.gz
    gzip -d GeoIP.dat.gz
    cp *.dat /home/univ_oahpa/univ_oahpa/geo/data/

Include the following settings in, change the directories if you have installed them to another path.

	GEOIP_PATH = '/home/univ_oahpa/univ_oahpa/geo/data/'
	GEOIP_LIBRARY_PATH = '/home/univ_oahpa/univ_oahpa/geo/geoip/lib/'
	GEOIP_CITY = 'GeoLiteCity.dat'

Add the context processor to add country to user session info


Potential problems

request.META has no REMOTE_ADDR, or HTTP_X_REAL_IP

Check that nginx is passing this in the fastcgi configuration, if not, add

	fastcgi_param REMOTE_ADDR $remote_addr;

only IPs tracked are

Nginx proxy definitions need to have the following:

	proxy_set_header   X-Real-IP        $remote_addr;
	proxy_set_header   X-Forwarded-For  $remote_addr;

Make sure to use a separate header

Additional django docs