Project

General

Profile

lighttpd mod_maxminddb country code to access log

Added by ambipur over 3 years ago

I have installed and configured lighttpd-mod-geoip. I would like to append the geoip country code to lighttpd access.log . Is it possible?


Replies (5)

RE: lighttpd-mod-geoip country code to access log - Added by gstrauss over 3 years ago

Is it possible?

Yes, it is possible.

Did you read the documentation? Obviously not. mod_geoip is deprecated. Go RTFM.

RE: lighttpd-mod-geoip country code to access log - Added by ambipur over 3 years ago

OK, I have switched to mod_geoip. I have downloaded the maxminddb database in mmdb format.
I have configured mod_maxminddb with creating a 09-modmaxminddb.conf in /etc/lighttpd/conf-available
Added the 3 options from the documentation plus the beginning line server.modules += ( "mod_maxminddb" )
Now lighttpd starts correctly, without any error massages.
I am running Debian 10 and lighttpd/1.4.55

Could you help me how to add the country code to access.log?

RE: lighttpd-mod-geoip country code to access log - Added by gstrauss over 3 years ago

Could you help me how to add the country code to access.log?

How to get support

There is a big difference between "Can you help me?" and "Do it for me!"

What have you tried? What did you observe?

RE: lighttpd mod_maxminddb country code to access log - Added by ambipur over 3 years ago

My 10-accesslog.conf is the following:
accesslog.format = "%{X-Forwarded-For}i V %u %t \"%r\" %>s %b \"{Referer}i\" \"%{User-Agent}i\" \"%{GEOIP_COUNTRY_CODE}e\""

In the access log the last characters related to a log line, when trying to access my server externally is only "-"

My lighttpd is running behind haproxy, that is why the first "X-Forwarded-For" in my accesslog config.
Does lighttpd require a special compile-time switch for mod-maxminddb to work? Not sure about how the Debian team has shipped their package.

RE: lighttpd mod_maxminddb country code to access log - Added by gstrauss over 3 years ago

mod_maxminddb docs say

Redirecting based on GeoIP2 data can be performed inside lighttpd using mod_magnet or using backend CGI, FastCGI, SCGI, etc.

Compared to serving a static file, a database lookup can be expensive. mod_maxminddb (and before that, mod_geoip) looks up the IP and sets environment variables for requests that are handled by dynamic modules, including those dynamic modules listed above. The database is not queried for static files or other non-dynamic handlers.

If you are accessing static files, you can post-process the logs (offline) or send logging through a piped logger. High performance websites post-process their logs. In-line processing done specifically when the response is based on or modified by the GeoIP results.

If you do not care, then you can add a mod_magnet handler to simply return to trigger the dynamic environment and mod_maxminddb database query.

    (1-5/5)