Welcome to Centmin Mod Community
Register Now

When to expect GeoIp2 in centminmod?

Discussion in 'Feature Requests & Suggestions' started by wmtech, May 9, 2018.

Tags:
  1. eva2000

    eva2000 Administrator Staff Member

    39,155
    8,647
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,296
    Local Time:
    2:58 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Only issue I am struggling with is fact that nginx geoip2 module is 4yrs old with no updates or active development. I can easily control nginx side configs so when geoip2 module is disabled i also disable nginx side configs.

    But php.conf include file fastcgi_params can be spread when php.conf include files are copied/cloned in some configurations and if nginx geoip2 module is disabled, those php.conf fastcgi_param will error out preventing nginx for starting up until they are removed.

    This isn't an issue for nginx native geoip module for geoip legacy database as the module is always enabled and trusted development wise.
     
  2. wmtech

    wmtech Active Member

    101
    27
    28
    Jul 22, 2017
    Ratings:
    +72
    Local Time:
    6:58 PM
    You can also think about to include the city database only. All the data from the country database is available in the city database too and it saves memory if just one database is added.

    The country database should be used only if neither city or region info is needed and you want to save even more memory.
     
    • Like Like x 1
  3. wmtech

    wmtech Active Member

    101
    27
    28
    Jul 22, 2017
    Ratings:
    +72
    Local Time:
    6:58 PM
    I understand your concerns. Maybe there will be a new GeoIp2 module available once Nginx recognizes that legacy GeoIP is no longer available. Or the existing module will be picked up by another developer. Who knows.

    But the new database info will stay, so it will be just a matter of switching modules if anything happens.

    And the existing module works as it should, is recommended by Nginx and looks also very decent from my quick reading over the code today.
     
  4. eva2000

    eva2000 Administrator Staff Member

    39,155
    8,647
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,296
    Local Time:
    2:58 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Yeah for now I intend to create a separate include file /usr/local/nginx/conf/php-geoip2.conf which is same as /usr/local/nginx/conf/php.conf include just with extended GEOIP2 fastcgi_param settings included. So users can switch that manually themselves and use that instead in their nginx vhosts.

    the settings in /usr/local/nginx/conf/php-geoip2.conf
    Code (Text):
    # Set php-fpm 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;
    
    fastcgi_param GEOIP2_CITY $geoip2_data_city_name;
    fastcgi_param GEOIP2_CITY_GEONAMEID $geoip2_data_city_geonameid;
    fastcgi_param GEOIP2_CONTINENT_CODE $geoip2_data_continent_code;
    fastcgi_param GEOIP2_CONTINENT_GEONAMEID $geoip2_data_continent_geonameid;
    fastcgi_param GEOIP2_CONTINENT_NAME $geoip2_data_continent_name;
    fastcgi_param GEOIP2_COUNTRY_GEONAMEID $geoip2_data_country_geonameid;
    fastcgi_param GEOIP2_COUNTRY_ISO_CODE $geoip2_data_country_iso;
    fastcgi_param GEOIP2_COUNTRY $geoip2_data_country_name;
    fastcgi_param GEOIP2_LOCATION_ACCURACY_RADIUS $geoip2_data_location_accuracyradius;
    fastcgi_param GEOIP2_LATITUDE $geoip2_data_location_latitude;
    fastcgi_param GEOIP2_LONGITUDE $geoip2_data_location_longitude;
    fastcgi_param GEOIP2_LOCATION_METROCODE $geoip2_data_location_metrocode;
    fastcgi_param GEOIP2_LOCATION_TIMEZONE $geoip2_data_location_timezone;
    fastcgi_param GEOIP2_POSTAL_CODE $geoip2_data_postal_code;
    fastcgi_param GEOIP2_REGISTERED_COUNTRY_GEONAMEID $geoip2_data_rcountry_geonameid;
    fastcgi_param GEOIP2_REGISTERED_COUNTRY_ISO $geoip2_data_rcountry_iso;
    fastcgi_param GEOIP2_REGISTERED_COUNTRY_NAME $geoip2_data_rcountry_name;
    fastcgi_param GEOIP2_REGION_GEONAMEID $geoip2_data_region_geonameid;
    fastcgi_param GEOIP2_REGION $geoip2_data_region_iso;
    fastcgi_param GEOIP2_REGION_NAME $geoip2_data_region_name;
    


    haven't updated 123.09beta01 branch with this code as yet though

    code updated at Beta Branch - add php-geoip2.conf include file variant for GeoIP2

    upload_2018-5-10_3-10-25.png
     
    • Agree Agree x 1
  5. eva2000

    eva2000 Administrator Staff Member

    39,155
    8,647
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,296
    Local Time:
    2:58 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Overlooked this post. Looks like a good plan :)

    size wise
    Code (Text):
    ls -lah /usr/share/GeoIP| grep GeoLite2
    -rw-r--r--  1 2000 2000  54M May  1 17:00 GeoLite2-City.mmdb
    -rw-r--r--  1 root root  26M May  1 17:00 GeoLite2-City.tar.gz
    -rw-r--r--  1 2000 2000 3.3M May  1 16:48 GeoLite2-Country.mmdb
    -rw-r--r--  1 root root 1.7M May  1 16:48 GeoLite2-Country.tar.gz
    
     
  6. eva2000

    eva2000 Administrator Staff Member

    39,155
    8,647
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,296
    Local Time:
    2:58 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Just bring this discussion up again as GeoIP legacy database is truly gone and not updated anymore. Latest 123.09beta01 has updated the optional geoip2 nginx module config to setup include file at /usr/local/nginx/conf/geoip2.conf referenced in /usr/local/nginx/conf/nginx.conf

    includes both GeoLite2-City and GeoLite2-ASN databases enabled by default
    Code (Text):
    # GeoIP2 Lite databases
       # geoip2 /usr/share/GeoIP/GeoLite2-Country.mmdb {
       #   auto_reload 5m;
       #   $geoip2_metadata_country_build metadata build_epoch;
       #   $geoip2_data_country_code country iso_code;
       #   $geoip2_data_country_name country names en;
       # }
    
      geoip2 /usr/share/GeoIP/GeoLite2-City.mmdb {
        auto_reload 5m;
        $geoip2_metadata_city_build metadata build_epoch;
        $geoip2_data_city_name city names en;
        $geoip2_data_city_geonameid city geoname_id;
        $geoip2_data_continent_code continent code;
        $geoip2_data_continent_geonameid continent geoname_id;
        $geoip2_data_continent_name continent names en;
        $geoip2_data_country_geonameid country geoname_id;
        $geoip2_data_country_code country iso_code;
        $geoip2_data_country_name country names en;
        $geoip2_data_country_is_eu country is_in_european_union;
        $geoip2_data_location_accuracyradius location accuracy_radius;
        $geoip2_data_location_latitude location latitude;
        $geoip2_data_location_longitude location longitude;
        $geoip2_data_location_metrocode location metro_code;
        $geoip2_data_location_timezone location time_zone;
        $geoip2_data_postal_code postal code;
        $geoip2_data_rcountry_geonameid registered_country geoname_id;
        $geoip2_data_rcountry_iso registered_country iso_code;
        $geoip2_data_rcountry_name registered_country names en;
        $geoip2_data_rcountry_is_eu registered_country is_in_european_union;
        $geoip2_data_region_geonameid subdivisions 0 geoname_id;
        $geoip2_data_region_iso subdivisions 0 iso_code;
        $geoip2_data_region_name subdivisions 0 names en;
      }
    
      geoip2 /usr/share/GeoIP/GeoLite2-ASN.mmdb {
        auto_reload 5m;
        $geoip2_data_autonomous_system_number autonomous_system_number;
        $geoip2_data_autonomous_system_organization autonomous_system_organization;
      }
    

    there's a separate php include file contents at centminmod/centminmod which ends up at /usr/local/nginx/conf/php-geoip2.conf similar to default php.conf include at /usr/local/nginx/conf/php.conf just that it has mapped geoip2 lite database variables registered as well
    Code (Text):
    fastcgi_param GEOIP2_CITY_BUILD_DATE $geoip2_metadata_city_build;
    fastcgi_param GEOIP2_CITY $geoip2_data_city_name;
    fastcgi_param GEOIP2_CITY_GEONAMEID $geoip2_data_city_geonameid;
    fastcgi_param GEOIP2_CONTINENT_CODE $geoip2_data_continent_code;
    fastcgi_param GEOIP2_CONTINENT_GEONAMEID $geoip2_data_continent_geonameid;
    fastcgi_param GEOIP2_CONTINENT_NAME $geoip2_data_continent_name;
    fastcgi_param GEOIP2_COUNTRY_GEONAMEID $geoip2_data_country_geonameid;
    fastcgi_param GEOIP2_COUNTRY_CODE $geoip2_data_country_code;
    fastcgi_param GEOIP2_COUNTRY_NAME $geoip2_data_country_name;
    fastcgi_param GEOIP2_COUNTRY_IN_EU $geoip2_data_country_is_eu;
    fastcgi_param GEOIP2_LOCATION_ACCURACY_RADIUS $geoip2_data_location_accuracyradius;
    fastcgi_param GEOIP2_LATITUDE $geoip2_data_location_latitude;
    fastcgi_param GEOIP2_LONGITUDE $geoip2_data_location_longitude;
    fastcgi_param GEOIP2_LOCATION_METROCODE $geoip2_data_location_metrocode;
    fastcgi_param GEOIP2_LOCATION_TIMEZONE $geoip2_data_location_timezone;
    fastcgi_param GEOIP2_POSTAL_CODE $geoip2_data_postal_code;
    fastcgi_param GEOIP2_REGISTERED_COUNTRY_GEONAMEID $geoip2_data_rcountry_geonameid;
    fastcgi_param GEOIP2_REGISTERED_COUNTRY_ISO $geoip2_data_rcountry_iso;
    fastcgi_param GEOIP2_REGISTERED_COUNTRY_NAME $geoip2_data_rcountry_name;
    fastcgi_param GEOIP2_REGISTERED_COUNTRY_IN_EU $geoip2_data_rcountry_is_eu;
    fastcgi_param GEOIP2_REGION_GEONAMEID $geoip2_data_region_geonameid;
    fastcgi_param GEOIP2_REGION $geoip2_data_region_iso;
    fastcgi_param GEOIP2_REGION_NAME $geoip2_data_region_name;
    
    fastcgi_param GEOIP2_ASN $geoip2_data_autonomous_system_number;
    fastcgi_param GEOIP2_ASN_ORG $geoip2_data_autonomous_system_organization;
    

    Code (Text):
    ls -lah /usr/share/GeoIP| grep GeoLite2
    -rw-r--r--    1 2000 2000 6.2M Apr  1 13:52 GeoLite2-ASN.mmdb
    -rw-r--r--    1 root root 3.5M Apr  1 13:52 GeoLite2-ASN.tar.gz
    -rw-r--r--    1 2000 2000  58M Apr  2 18:44 GeoLite2-City.mmdb
    -rw-r--r--    1 root root  28M Apr  2 18:44 GeoLite2-City.tar.gz
    -rw-r--r--    1 2000 2000 3.6M Apr  2 18:32 GeoLite2-Country.mmdb
    -rw-r--r--    1 root root 1.9M Apr  2 18:32 GeoLite2-Country.tar.gz
    

    you can manually setup the tools/geop2db-update.sh script as a cronjob to get GeoLite2 IP database updates once a week too - though it should be automatically setup when you enable geoip2 nginx module support in centmin mod 123.09beta01's run for centmin.sh menu option 4 nginx compiles
    Code (Text):
    crontab -l | grep geoip2db
    20 2 * * 4 /usr/local/src/centminmod/tools/geoip2db-update.sh >/dev/null 2>&1
    

    it's what I am using for Version 3 geoip lookup site at https://geoip.centminmod.com/v2/ mentioned at https://community.centminmod.com/threads/17099/
     
  7. Itworx4me

    Itworx4me Premium Member Premium Member

    165
    16
    18
    Mar 14, 2017
    Ratings:
    +21
    Local Time:
    9:58 AM
    Nginx 1.15.X
    MariaDB 10.3.X
    What are some use cases for this feature?
     
  8. eva2000

    eva2000 Administrator Staff Member

    39,155
    8,647
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,296
    Local Time:
    2:58 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    It is used for nginx geo ip redirections or blocking or redirecting traffic in nginx based on the geo location of the visitor's IP address. For instance centminmod.com site uses geoip legacy nginx module (i should switch to geoip2 lite nginx module above eventually) as i rotate and display add banners on the site based on geo ip location of visitor. So i try to show web host banner ads more relevant to the visitor's geo ip location i.e. showing a web host who's server location(s) are more in line with visitor's location.

    so variables mapped in https://community.centminmod.com/threads/when-to-expect-geoip2-in-centminmod.14737/page-2#post-72515 for /usr/local/nginx/conf/geoip2.conf can be used as variables in nginx vhost configs.
    Code (Text):
    # GeoIP2 Lite databases
       # geoip2 /usr/share/GeoIP/GeoLite2-Country.mmdb {
       #   auto_reload 5m;
       #   $geoip2_metadata_country_build metadata build_epoch;
       #   $geoip2_data_country_code country iso_code;
       #   $geoip2_data_country_name country names en;
       # }
    
      geoip2 /usr/share/GeoIP/GeoLite2-City.mmdb {
       auto_reload 5m;
       $geoip2_metadata_city_build metadata build_epoch;
       $geoip2_data_city_name city names en;
       $geoip2_data_city_geonameid city geoname_id;
       $geoip2_data_continent_code continent code;
       $geoip2_data_continent_geonameid continent geoname_id;
       $geoip2_data_continent_name continent names en;
       $geoip2_data_country_geonameid country geoname_id;
       $geoip2_data_country_code country iso_code;
       $geoip2_data_country_name country names en;
       $geoip2_data_country_is_eu country is_in_european_union;
       $geoip2_data_location_accuracyradius location accuracy_radius;
       $geoip2_data_location_latitude location latitude;
       $geoip2_data_location_longitude location longitude;
       $geoip2_data_location_metrocode location metro_code;
       $geoip2_data_location_timezone location time_zone;
       $geoip2_data_postal_code postal code;
       $geoip2_data_rcountry_geonameid registered_country geoname_id;
       $geoip2_data_rcountry_iso registered_country iso_code;
       $geoip2_data_rcountry_name registered_country names en;
       $geoip2_data_rcountry_is_eu registered_country is_in_european_union;
       $geoip2_data_region_geonameid subdivisions 0 geoname_id;
       $geoip2_data_region_iso subdivisions 0 iso_code;
       $geoip2_data_region_name subdivisions 0 names en;
      }
    
      geoip2 /usr/share/GeoIP/GeoLite2-ASN.mmdb {
       auto_reload 5m;
       $geoip2_data_autonomous_system_number autonomous_system_number;
       $geoip2_data_autonomous_system_organization autonomous_system_organization;
      }
    

    so variable $geoip2_data_country_code country would retrieve the visitor's 2 letter country code i.e. Australia = AU or USA = US

    so you can map the geoip2 variable to your own variable
    Code (Text):
    map $geoip2_data_country_code $detect_country {
      default www.example.com;
      AU      au.example.com;
      US      us.example.com;
    }
    


    or do something similar to https://www.cleverti.com/news/how-t...ased-on-user-s-location-with-nginx-and-geoip2

    you can use the variables to also block traffic by country code detected etc etc

    and of course you can use it to do stuff like my created geoip look up site with some php referencing the above fastcgi_param variables https://geoip.centminmod.com/v2/

    example for 2 letter country code when you set
    Code (Text):
    fastcgi_param GEOIP2_COUNTRY_CODE $geoip2_data_country_code;

    in php.conf include file you register with PHP the environmental variable you can grab with PHP code
    PHP:
    <?php

    $geoip_country_code 
    getenv(GEOIP2_COUNTRY_CODE);

    echo 
    'country code: '.$geoip_country_code.'';
    An Australian visitor visiting that php page will see
    as geoip2 nginx module referencing geoip2 lite database found that visitor's IP address has a country code = AU

    And reason why @wmtech asked about GeoIP2 lite database/nginx module support is because older GeoIP legacy database is EOL and not receiving anymore geo ip location database updates - https://medium.com/@karljohnson/geo...ade-to-geoip2-with-nginxon-centos-c2a3dbcf8fd

    Centmin Mod LEMP stack installs older GeoIP legancy nginx module and database out of the box. But GeoIP2 Lite nginx module is optionally enable by end user if they want.

    Here's Centmin Mod Nginx with both GeoIP legacy and GeoIP2 Lite nginx modules - where latter is compiled as dynamic nginx module
     
    Last edited: Apr 6, 2019
    • Informative Informative x 1
  9. eva2000

    eva2000 Administrator Staff Member

    39,155
    8,647
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,296
    Local Time:
    2:58 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Also eventually, will have to look at making nginx geoip2 nginx module the default instead of geoip legacy nginx module but trick would be making the registered fastcgi_param variables for geoip2 lite closely match geoip legacy's variables

    geoip legacy variables
    Code (Text):
    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;
    

    geoip2 lite variables
    Code (Text):
    fastcgi_param GEOIP2_CITY_BUILD_DATE $geoip2_metadata_city_build;
    fastcgi_param GEOIP2_CITY $geoip2_data_city_name;
    fastcgi_param GEOIP2_CITY_GEONAMEID $geoip2_data_city_geonameid;
    fastcgi_param GEOIP2_CONTINENT_CODE $geoip2_data_continent_code;
    fastcgi_param GEOIP2_CONTINENT_GEONAMEID $geoip2_data_continent_geonameid;
    fastcgi_param GEOIP2_CONTINENT_NAME $geoip2_data_continent_name;
    fastcgi_param GEOIP2_COUNTRY_GEONAMEID $geoip2_data_country_geonameid;
    fastcgi_param GEOIP2_COUNTRY_CODE $geoip2_data_country_code;
    fastcgi_param GEOIP2_COUNTRY_NAME $geoip2_data_country_name;
    fastcgi_param GEOIP2_COUNTRY_IN_EU $geoip2_data_country_is_eu;
    fastcgi_param GEOIP2_LOCATION_ACCURACY_RADIUS $geoip2_data_location_accuracyradius;
    fastcgi_param GEOIP2_LATITUDE $geoip2_data_location_latitude;
    fastcgi_param GEOIP2_LONGITUDE $geoip2_data_location_longitude;
    fastcgi_param GEOIP2_LOCATION_METROCODE $geoip2_data_location_metrocode;
    fastcgi_param GEOIP2_LOCATION_TIMEZONE $geoip2_data_location_timezone;
    fastcgi_param GEOIP2_POSTAL_CODE $geoip2_data_postal_code;
    fastcgi_param GEOIP2_REGISTERED_COUNTRY_GEONAMEID $geoip2_data_rcountry_geonameid;
    fastcgi_param GEOIP2_REGISTERED_COUNTRY_ISO $geoip2_data_rcountry_iso;
    fastcgi_param GEOIP2_REGISTERED_COUNTRY_NAME $geoip2_data_rcountry_name;
    fastcgi_param GEOIP2_REGISTERED_COUNTRY_IN_EU $geoip2_data_rcountry_is_eu;
    fastcgi_param GEOIP2_REGION_GEONAMEID $geoip2_data_region_geonameid;
    fastcgi_param GEOIP2_REGION $geoip2_data_region_iso;
    fastcgi_param GEOIP2_REGION_NAME $geoip2_data_region_name;
    
    fastcgi_param GEOIP2_ASN $geoip2_data_autonomous_system_number;
    fastcgi_param GEOIP2_ASN_ORG $geoip2_data_autonomous_system_organization;
    
     
    • Like Like x 1
  10. eva2000

    eva2000 Administrator Staff Member

    39,155
    8,647
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,296
    Local Time:
    2:58 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
..