5

I'm installing mod_geoIP for cpanel based on these instructions (not very detailed, hence this question)

At this point, I've installed the module as instructed. I've also downloaded the csv file for the GeoLite Country. AM I missing anything?

I assume the next step is to create the entry in my .htaccess file for allowed countries like so:

GeoIPEnable On
GeoIPDBFile /path/to/GeoIPCountryWhois.csv

SetEnvIf GEOIP_COUNTRY_CODE US AllowCountry
SetEnvIf GEOIP_COUNTRY_CODE CA AllowCountry
SetEnvIf GEOIP_COUNTRY_CODE MX AllowCountry

Deny from all
Allow from env=AllowCountry

Does it look like I'm missing anything? Also is there a way to test this?

Christian Rau
  • 43,206
  • 10
  • 106
  • 177
Paul
  • 11,011
  • 28
  • 81
  • 137
  • Can you see GEOIP_COUNTRY_CODE being set? For example using $_ENV["GEOIP_COUNTRY_CODE"] is some php file. – Gerben Nov 29 '11 at 19:09

1 Answers1

3

I know that your question is a bit old, but it could use an answer anyway.

I think the only thing you did wrong was that you have to use the Binary DB file not the CSV file.

If you're using a Debian-based distribution, do this:

  1. Install Apache2 and mod_geoip: sudo apt-get install apache2 libapache2-mod-geoip
  2. Download one of these:
  3. Gunzip it: sudo gunzip /etc/apache2/GeoIP.dat.gz
  4. Edit the appropriate host file: sudo nano /etc/apache2/sites-available/default (or whichever you wish)
  5. Insert the following into that file:
    GeoIPEnable On
    GeoIPDBFile /etc/apache2/GeoIP.dat
  6. sudo service apache2 restart or sudo invoke-rc.d apache2 restart
  7. Then use the ENV variables within Apache2 or your favorite programming language.

If geoip-bin package exists, you could probably use that instead of downloading it in step 2. I haven't used it, so I'm not sure at what path that file would be.

The above steps give me these ENV variables:

GEOIP_ADDR          99.99.99.99
GEOIP_CONTINENT_CODE    NA
GEOIP_COUNTRY_CODE      US
GEOIP_COUNTRY_NAME      United States
GEOIP_REGION        TX
GEOIP_REGION_NAME       Texas
GEOIP_CITY          San Antonio
GEOIP_DMA_CODE      641
GEOIP_AREA_CODE     210
GEOIP_LATITUDE      29.488899
GEOIP_LONGITUDE     -98.398697
GEOIP_POSTAL_CODE       78218
Emmaly Wilson
  • 833
  • 6
  • 20