Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of server GEOIP headers when after reverse proxy #13121

Closed
iprok opened this issue Jul 1, 2018 · 4 comments
Closed

Add support of server GEOIP headers when after reverse proxy #13121

iprok opened this issue Jul 1, 2018 · 4 comments
Labels
answered For when a question was asked and we referred to forum or answered it.

Comments

@iprok
Copy link

iprok commented Jul 1, 2018

Hello!

I make IP->geo resolving on nginx reverse proxy. So geoip headers come to matomo with HTTP_ prefix. Can you add support of such situation to matomo please? For now I manually patched the code. Path attached.
geoip-proxy.patch.gz

@Findus23
Copy link
Member

Findus23 commented Jul 1, 2018

In case someone doesn't want to download and extract the patch file:

--- plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php.old	2018-07-01 18:49:31.401744139 +0300
+++ plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php	2018-07-01 18:42:21.977012029 +0300
@@ -26,25 +26,25 @@
 {
     const ID = 'geoip_serverbased';
     const TITLE = 'GeoIP Legacy (%s)';
-    const TEST_SERVER_VAR = 'GEOIP_ADDR';
-    const TEST_SERVER_VAR_ALT = 'GEOIP_COUNTRY_CODE';
-    const TEST_SERVER_VAR_ALT_IPV6 = 'GEOIP_COUNTRY_CODE_V6';
+    const TEST_SERVER_VAR = 'HTTP_GEOIP_ADDR';
+    const TEST_SERVER_VAR_ALT = 'HTTP_GEOIP_COUNTRY_CODE';
+    const TEST_SERVER_VAR_ALT_IPV6 = 'HTTP_GEOIP_COUNTRY_CODE_V6';
 
     private static $geoIpServerVars = array(
-        parent::COUNTRY_CODE_KEY => 'GEOIP_COUNTRY_CODE',
-        parent::COUNTRY_NAME_KEY => 'GEOIP_COUNTRY_NAME',
-        parent::REGION_CODE_KEY  => 'GEOIP_REGION',
-        parent::REGION_NAME_KEY  => 'GEOIP_REGION_NAME',
-        parent::AREA_CODE_KEY    => 'GEOIP_AREA_CODE',
-        parent::LATITUDE_KEY     => 'GEOIP_LATITUDE',
-        parent::LONGITUDE_KEY    => 'GEOIP_LONGITUDE',
-        parent::POSTAL_CODE_KEY  => 'GEOIP_POSTAL_CODE',
+        parent::COUNTRY_CODE_KEY => 'HTTP_GEOIP_COUNTRY_CODE',
+        parent::COUNTRY_NAME_KEY => 'HTTP_GEOIP_COUNTRY_NAME',
+        parent::REGION_CODE_KEY  => 'HTTP_GEOIP_REGION',
+        parent::REGION_NAME_KEY  => 'HTTP_GEOIP_REGION_NAME',
+        parent::AREA_CODE_KEY    => 'HTTP_GEOIP_AREA_CODE',
+        parent::LATITUDE_KEY     => 'HTTP_GEOIP_LATITUDE',
+        parent::LONGITUDE_KEY    => 'HTTP_GEOIP_LONGITUDE',
+        parent::POSTAL_CODE_KEY  => 'HTTP_GEOIP_POSTAL_CODE',
     );
 
     private static $geoIpUtfServerVars = array(
-        parent::CITY_NAME_KEY => 'GEOIP_CITY',
-        parent::ISP_KEY       => 'GEOIP_ISP',
-        parent::ORG_KEY       => 'GEOIP_ORGANIZATION',
+        parent::CITY_NAME_KEY => 'HTTP_GEOIP_CITY',
+        parent::ISP_KEY       => 'HTTP_GEOIP_ISP',
+        parent::ORG_KEY       => 'HTTP_GEOIP_ORGANIZATION',
     );
 
     /**
@@ -232,7 +232,7 @@
 
         $geoipServerVars = array();
         foreach ($_SERVER as $key => $value) {
-            if (strpos($key, 'GEOIP') === 0) {
+            if (strpos($key, 'HTTP_GEOIP') === 0) {
                 $geoipServerVars[] = $key;
             }
         }

@sgiehl
Copy link
Member

sgiehl commented Jul 1, 2018

@iprok GeoIP (Legacy) has been deprecated, so I guess we won't change the behavior for this anymore.
For GeoIP2 it is already possible to configure the server variable names for all variables.

@iprok
Copy link
Author

iprok commented Jul 1, 2018

@iprok GeoIP (Legacy) has been deprecated, so I guess we won't change the behavior for this anymore.
For GeoIP2 it is already possible to configure the server variable names for all variables.

I use geoip2 on my proxy and I just fake variable names because I thought matomo doesn't support geoip2 variable names. Where can I find information about it? I have latest matomo installed.

@sgiehl
Copy link
Member

sgiehl commented Jul 1, 2018

you need to enable the geoip2 plugin, but this will trigger an update on the log tables, so for bigger databases this might take a bit longer...

@sgiehl sgiehl closed this as completed Jul 2, 2018
@sgiehl sgiehl added the answered For when a question was asked and we referred to forum or answered it. label Jul 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered For when a question was asked and we referred to forum or answered it.
Projects
None yet
Development

No branches or pull requests

3 participants