How to Install Mod_GeoIP for Apache in RHEL and CentOS

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

27 Responses

  1. richard says:

    You changed to the file name in this line: gunzip GeoLite2-Country.tar.gz
    but that just produces a .tar file in a new directory.

    It no longer produces the file: GeoIP.dat nor does it put it in the current directory
    so the lines in later code: GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
    will no longer work.

    More changes are needed in your code. Have you tested your code? I don’t think it will work with all the changes MaxMiind has made in their system.

    • Ravi Saive says:

      @Richard,

      Thanks for your input, I think I should re-install and test it again Mod_GeoIP, give me a day or two to test and update this article with latest information.

  2. Richard says:

    It appears that the database files in your code have all changed names because MaxMind has discontinued those files and has new file names:
    https://support.maxmind.com/geolite-legacy-discontinuation-notice/

  3. Jasmin says:

    i get error: /usr/bin/perl: symbol lookup error: /usr/local/lib64/perl5/auto/Geo/IP/IP.so: undefined symbol: GeoIP_open

  4. cjwalter says:

    I used the sample script, it shows the IP, not showing Country name .

  5. Naval saini says:

    Nice article
    Each and every step clearly defined

  6. Krunal says:

    What about nginx ?

  7. Stan says:

    Hello,

    deny on geopip.conf does not work. I get the error:

    Stopping httpd: [ OK ]
    Starting httpd: Syntax error on line 21 of /etc/httpd/conf.d/geoip.conf:
    deny not allowed here

    i used the syntax:

    SetEnvIf GEOIP_COUNTRY_CODE DE AllowCountry
    SetEnvIf GEOIP_COUNTRY_CODE AT AllowCountry

    Deny from all
    Allow from env=AllowCountry

    How can i fix this?

    Thanks!

  8. Peter says:

    Hi there, nice article.
    But how can I block countries for all my domains which are hosted on my server.
    Or should I have to paste the code into each .htaccess for each domain?

    • Ravi Saive says:

      Yes, you must create a specific .htaccess file under each domain and add the following example of code to block countries.

      SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry
      SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry
      Deny from env=BlockCountry
      

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.