简体   繁体   中英

Apache mod_maxminddb - not showing country code, ERROR undefined index

I installed mod_maxmindb as suggested on github. Probably i missed something but i don't get an country code or something else.

I found 2 issues:

  • during make --> dlname not found
  • and during testing i get apache error: PHP notice: Undefined index: MM_COUNTRY_CODE

In detail: STEP 1 - installation)

Apache2 version:
Server version: Apache/2.4.41 (Ubuntu)
Server built:   2020-04-13T17:19:17
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:        20.04
Codename:       focal
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
/usr/bin# ls -la apx*
-rwxr-xr-x 1 root root 19743 Mar 13 13:26 apxs
lrwxrwxrwx 1 root root     4 Mar 13 13:26 apxs2 -> apxs
add-apt-repository ppa:maxmind/ppa
apt update
apt install libmaxminddb0 libmaxminddb-dev mmdb-bin
apt install apache2-dev
apt install build-essential
wget https://github.com/maxmind/mod_maxminddb/releases/download/1.2.0/mod_maxminddb-1.2.0.tar.gz
tar -xzf mod_maxminddb-1.2.0.tar.gz
cd mod_maxminddb-1.2.0/
./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... none
checking for gcc option to accept ISO C99... none needed
checking whether compiler accepts "-std=c99 -fms-extensions"... yes
checking for apxs2... /usr/bin/apxs2
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking maxminddb.h usability... yes
checking maxminddb.h presence... yes
checking for maxminddb.h... yes
checking for MMDB_lib_version in -lmaxminddb... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: executing depfiles commands
make install
Making install in src
make[1]: Entering directory '/mod_maxminddb-1.2.0/src'
make[2]: Entering directory '/mod_maxminddb-1.2.0/src'
/usr/bin/apxs2 -c  -lmaxminddb  -Wc,"-g -O2 -std=c99 -fms-extensions"  mod_maxminddb.c
/usr/share/apr-1.0/build/libtool  --mode=compile --tag=disable-static x86_64-linux-gnu-gcc -prefer-pic -pipe -g -O2 -fstack-protector-strong -Wformat -Werror=format-security  -Wdate-time -D_FORTIFY_SOURCE=2   -DLINUX -D_REENTRANT -D_GNU_SOURCE  -pthread  -I/usr/include/apache2  -I/usr/include/apr-1.0   -I/usr/include/apr-1.0 -I/usr/include -g -O2 -std=c99 -fms-extensions  -c -o mod_maxminddb.lo mod_maxminddb.c && touch mod_maxminddb.slo
libtool: compile:  x86_64-linux-gnu-gcc -pipe -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -DLINUX -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/apache2 -I/usr/include/apr-1.0 -I/usr/include/apr-1.0 -I/usr/include -g -O2 -std=c99 -fms-extensions -c mod_maxminddb.c  -fPIC -DPIC -o .libs/mod_maxminddb.o
/usr/share/apr-1.0/build/libtool  --mode=link --tag=disable-static x86_64-linux-gnu-gcc -Wl,--as-needed -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now    -o mod_maxminddb.la  -lmaxminddb -rpath /usr/lib/apache2/modules -module -avoid-version    mod_maxminddb.lo
libtool: link: rm -fr  .libs/mod_maxminddb.la .libs/mod_maxminddb.lai .libs/mod_maxminddb.so
libtool: link: x86_64-linux-gnu-gcc -shared  -fPIC -DPIC  .libs/mod_maxminddb.o   -lmaxminddb  -Wl,--as-needed -Wl,-Bsymbolic-functions -Wl,-z -Wl,relro -Wl,-z -Wl,now   -Wl,-soname -Wl,mod_maxminddb.so -o .libs/mod_maxminddb.so
libtool: link: ( cd ".libs" && rm -f "mod_maxminddb.la" && ln -s "../mod_maxminddb.la" "mod_maxminddb.la" )
/usr/bin/apxs2 -i -a -n maxminddb .libs/mod_maxminddb.so
/usr/share/apache2/build/instdso.sh SH_LIBTOOL='/usr/share/apr-1.0/build/libtool' .libs/mod_maxminddb.so /usr/lib/apache2/modules
/usr/share/apr-1.0/build/libtool --mode=install install .libs/mod_maxminddb.so /usr/lib/apache2/modules/
libtool: install: install .libs/mod_maxminddb.so /usr/lib/apache2/modules/mod_maxminddb.so
Warning!  dlname not found in /usr/lib/apache2/modules/mod_maxminddb.so.
Assuming installing a .so rather than a libtool archive.
chmod 644 /usr/lib/apache2/modules/mod_maxminddb.so
[preparing module `maxminddb' in /etc/apache2/mods-available/maxminddb.load]
Module maxminddb already enabled

--> during make install i get the warning --> Warning. dlname not found in /usr/lib/apache2/modules/mod_maxminddb.so

STEP 2) database

apt update
apt install geoipupdate
nano /etc/GeoIP.conf

Fill in my data

geoipupdate

check if db is here:

/usr/share/GeoIP# ls -la /usr/share/GeoIP/Ge*
-rw-r--r-- 1 root root 3830286 Jun 16 21:52 /usr/share/GeoIP/GeoLite2-Country.mmdb

STEP 3 - TEST

check if module is loades in apache:

apachectl -M | grep -i maxmin*
 maxminddb_module (shared)

my vhost config looks like:

<VirtualHost *:443>
ServerName sub.domain.tld
DocumentRoot "/var/www/test"
SSLEngine On
    <Directory /var/www/test/>
        Require all granted
        AllowOverride All
        Options Indexes FollowSymLinks
    MaxMindDBEnable On
    MaxMindDBFile COUNTRY_DB /usr/share/GeoIP/GeoLite2-Country.mmdb
    MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code

    </Directory>
SSLCertificateFile /xxx
SSLCertificateKeyFile /xxx
SSLCertificateChainFile /xxx

ErrorLog ${APACHE_LOG_DIR}/error_test.log
CustomLog ${APACHE_LOG_DIR}/access_test.log combined

Then i created a website with content:

<?php
$country = $_SERVER["MM_COUNTRY_CODE"];
echo "<br />TESTCOUNTRY : $country<br />";

And accessed it from public IP. Apache log shows external IP:

89.144.xxx.xxx - - [22/Jun/2020:15:05:44 +0200] "GET / HTTP/1.1" 200 250 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 EdgiOS/45.5.0 Mobile/15E148 Safari/605.1.15"

Geoiplocation.net shows my IP address is "AT"

But i don't get an country code - the website only shows: TESTCOUNTRY:

apache error log shows undefined index:

Tue Jun 23 19:55:27.905107 2020] [php7:notice] [pid 22519] [client 89.144.xxx.xxx:17391] PHP Notice:  Undefined index: MM_COUNTRY_CODE in /var/www/test/index.php on line 2

Also restarted Apache / server.

So - it would be great if someone could help me or explain where i am wrong or probably where the error lies..

Thank you! rodnheli

UPDATE 23.06. After thinking this is a problem with the DB file i also downloaded the other DBs

EditionIDs GeoLite2-ASN GeoLite2-City GeoLite2-Country

and changed the vhost from Geolite2-Contry mmdb to Geolite2-City.mmdb:

MaxMindDBEnable On
MaxMindDBFile CITY_DB /usr/share/GeoIP/GeoLite2-City.mmdb
MaxMindDBEnv MM_COUNTRY_CODE CITY_DB/country/iso_code

AND i get my country code shown now!!

Now i tried to download the GeoLite2-Country.mmdb manually and replaced it with the automatically downloaded mmdb - but the undefined index error still exists.

Any suggestions:-)

Thanks maxmind support to solve the issue!

With the right env settings all works now: https://github.com/maxmind/mod_maxminddb#maxminddbenv

MaxMindDBEnable On
MaxMindDBFile COUNTRY_DB /usr/share/GeoIP/GeoLite2-Country.mmdb
MaxMindDBEnv COUNTRY_CODE COUNTRY_DB/country/iso_code

i took my code from this example - what didn't work

https://github.com/maxmind/mod_maxminddb#blocking-by-country

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM