GeoIP2 HTTP Server Module: Matomo cannot find any GeoIP $_SERVER variables

We want to use ht geoip http server module on nginx. We installed everything according to this:

Then we activated the GeoIp2 (Core) Plugin, set geoip variables in general settings (everything left to the default value).

But i can’t activate the module (says not installed), and to the right the following is displayed:
Note: Cannot find apache_get_modules function, assuming non-Apache webserver.

Matomo cannot find any GeoIP $_SERVER variables.
You can configure used server variables [here]

what are we missing/how to troubleshoot?
Using the geoIP2 php function -> everything works, but we want to switch to the http module.


Check out here for many suggestions:

Thanks Lukas, i already did (before asking here of course). I created a test.php to dump the _server var, put it inside of matomo (allowed access throug nginx config) and the output doesn’t show any geoip vars.

Did i miss something? I followed each step of the instructions: ngx_http_geoip2_module/ at master · leev/ngx_http_geoip2_module · GitHub

Here is my vardump:

array(42) { 
    ["TEMP"]=> string(4) "/tmp" 
    ["TMPDIR"]=> string(4) "/tmp" 
    ["TMP"]=> string(4) "/tmp" 
    ["PATH"]=> string(28) "/usr/local/bin:/usr/bin:/bin" 
    ["HOSTNAME"]=> string(0) "" 
    ["USER"]=> string(8) "www-data" 
    ["HOME"]=> string(8) "/var/www" 
    ["HTTP_COOKIE"]=> [*replaced*]
    ["HTTP_ACCEPT_LANGUAGE"]=> string(35) "de-DE,de;q=0.9,en;q=0.8,en-US;q=0.7" 
    ["HTTP_ACCEPT_ENCODING"]=> string(17) "gzip, deflate, br" 
    ["HTTP_ACCEPT"]=> string(85) "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8" 
    ["HTTP_USER_AGENT"]=> string(120) "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36" 
    ["HTTP_UPGRADE_INSECURE_REQUESTS"]=> string(1) "1" ["HTTP_CACHE_CONTROL"]=> string(9) "max-age=0" 
    ["HTTP_HOST"]=> string(14) "[*replaced*]" ["front_controller_active"]=> string(4) "true" 
    ["modHeadersAvailable"]=> string(4) "true" ["PATH_INFO"]=> string(0) "" 
    ["SCRIPT_FILENAME"]=> string(32) "/var/www/[*replaced*]/test.php" 
    ["REDIRECT_STATUS"]=> string(3) "200" 
    ["SERVER_NAME"]=> string(14) "[*replaced*]" 
    ["SERVER_PORT"]=> string(3) "443" 
    ["SERVER_ADDR"]=> string(13) "[*replaced*]" 
    ["REMOTE_PORT"]=> string(5) "61972" 
    ["REMOTE_ADDR"]=> string(13) "[*replaced*]" 
    ["SERVER_SOFTWARE"]=> string(12) "nginx/1.14.1" 
    ["GATEWAY_INTERFACE"]=> string(7) "CGI/1.1" 
    ["HTTPS"]=> string(2) "on" 
    ["REQUEST_SCHEME"]=> string(5) "https" 
    ["SERVER_PROTOCOL"]=> string(8) "HTTP/2.0" 
    ["DOCUMENT_ROOT"]=> string(23) "/var/www/[*replaced*]" 
    ["DOCUMENT_URI"]=> string(9) "/test.php" 
    ["REQUEST_URI"]=> string(9) "/test.php" 
    ["SCRIPT_NAME"]=> string(9) "/test.php" 
    ["CONTENT_LENGTH"]=> string(0) "" 
    ["CONTENT_TYPE"]=> string(0) "" 
    ["REQUEST_METHOD"]=> string(3) "GET" 
    ["QUERY_STRING"]=> string(0) "" 
    ["FCGI_ROLE"]=> string(9) "RESPONDER" 
    ["PHP_SELF"]=> string(9) "/test.php" 
    ["REQUEST_TIME_FLOAT"]=> float(1550159359.62) 
    ["REQUEST_TIME"]=> int(1550159359) }

Hi, shouldn’t one of those variable be set to the location as detected by the server module?

Please show me your whole nginx configuration (you may replace url/ip information).

Hello I believe I’m facing same issue, can’t get Nginx module working no matter what. Matomo cannot find any GeoIP $_SERVER variables.

Matomo: 3.8.1
Nginx 1.15.8 + dynamic module ngx_http_geoip2_module-3.2
Ubuntu 18.04 LTS (fully updated)

:heavy_check_mark: All green on System Check and Tracking failures
:heavy_check_mark: Configuration for server variables used by GeoIP 2 server modules
:heavy_check_mark: GeoIP 2 (Php) and even Cloudflare work fine

Ok got it resolved, nginx.conf requires (watch out for correct path)

geoip2 /var/www/Matomo/misc/GeoLite2-City.mmdb
    auto_reload 5m;
    $geoip2_data_country_code default=US country iso_code;
    $geoip2_data_country_name country names en;
    $geoip2_data_city_name city names en;

And inside Matomo site config add variables

## only allow accessing the following php files
location ~ ^/(index|matomo|piwik|js/index).php {
    include snippets/fastcgi-php.conf; # if your Nginx setup doesn't come with a default fastcgi-php config replace this with the one from this repository
    fastcgi_param HTTP_PROXY ""; # prohibit httpoxy:
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; #replace with the path to your PHP socket file
    #fastcgi_pass; # uncomment if you are using PHP via TCP sockets

    #Added for GeoIP2 to work 
    fastcgi_param  MM_COUNTRY_CODE    $geoip2_data_country_code;
    fastcgi_param  MM_COUNTRY_NAME    $geoip2_data_country_name;
    fastcgi_param  MM_CITY_NAME       $geoip2_data_city_name;
1 Like

Thats what I guessed :wink: