PROGRAMS :: Modules Apache

mod_geo.c version 1.3

The module determining geography of visitors of a site

Download: ftp://ftp.lexa.ru/pub/apache-rus/contrib/

The Table of contents

1. Copyright

2. Purpose

3. Installation (Apache 2.0)

4. The Configuration

5. Remarks

6. TODO

Copyright

Copyright (C) 2000-2002 Alex Tutubalin, lexa@lexa.ru

Distribution and use to derivative products on conditions similar Apache License Is supposed - should be kept Copyright the author and the link on

 http://www.lexa.ru/lexa, the derivative product should not refer to mod_geo

The Module includes an essential part libpatricia, Copyright (c) 1997, 1998, 1999
The Regents of the
University of Michigan ("The Regents") and Merit Network, Inc. All rights reserved.

The Description

The module is intended for definition of geography of the user of the WWW-server and transfer of geography to caused script/dynamic pages as additional argument of search. It can be useful, if depending on region different contents of reciprocal page are formed, we shall tell different advertising or different links to Internets - shops (for example, American for US/CA, European for the others). The module is compatible with mod_accel - answers for each country caching separately since the country code is added to seen mod_accel URL.

Internal performance as Patricia tree Is used, that supposes presence in a database of the enclosed addresses:

 8.0.0.0/7 US
 9.20.0.0/17 GB 

Speed of work Patricia tree more than is sufficient - on a similar task and the table in 70 thousand prefixes the author received speed about 800 thousand lookups/sec on PIII-600, that on three order there is more than speed Apache by the same machine.

Scripts for construction DB on geography in the complete set of the module do not enter and will be published later, the table included in the complete set was constructed 10.01.2002 on data DB RIPE/ARIN/APNIC.

Definition of geography of the user occurs twice:

  • Right after readings of search, thus the country code is located in a variable of environment IP_GEO which can be used in RewriteRule and similar directives. Presence/absence of GEOActive/GEOCGIArg directives does not influence this phase of work - definition of geography occurs if for the given server / virtual server the table with geographical DB is specified.
  • At a final stage of processing of search (before start handler) there is a repeated definition of geography of the user and add it in a line of arguments of search. This stage takes place only if she(it) is resolved(allowed) by GEOActive/GEOCGIArg

Recording of the geographical data in a log-file
The geographical information can be written down in a broad gully having added a field of %{IP_GEO}e in LogFormat directive

Installation (Apache 1.x)

For work with Apache 1.x the module mod_geo.c is intended
At configuration Apache to parameters ./configure it is necessary to add -add-module=/path/to/mod_geo.c:

 
tar xzvf apache_1.3xxx
tar xzvf mod_geo-1.0.xx.tar.gz
cd apache_1.3xx
./configure --prefix=/usr/local/apache \
... --add-module=../mod_geo_1.0.xx/mod_geo.c other-params
make
make install

Installation (Apache 2.0)

For work with Apache 2.0 the module mod_geo2.c is intended
First it is necessary to establish Apache 2.0.x, suppose, we have made it in a directory/usr/local/apache
For installation of the module mod_geo2 it is necessary to use the program apxs:

 

tar xzvf mod_geo-1.xx.tar.gz

cd mod_geo-1.xx

/usr/local/apach/bin/apxs -i -c -a mod_geo2.c

 
 

This command will compile the module (the key-c), will establish it in catalogue Apache (a key-i) and is activated with the module addition of LoadModule command in httpd.conf (a key-a)

Configuration

Directives Configuration GEOTable directive can be specified only in a context of all server or inside <VirtualServer>, the others (both:) - anywhere in httpd.conf, and for the indication in .htaccess it should be authorized AllowOverride FileInfo.

GEOTable filename

The Name of a file with geographical base in a format
address/masklen CountryCode

 

14.0.0.0/8 US

15.0.0.0/8 GB

15.203.128.0/18 FR

15.204.96.0/19 FR

...

 
 

The length of the name of the country should be no more than three symbols, all that is longer - is ignored.
Addresses can be enclosed, in this case will be best match
Default: defaults are not present

GEOActive On/Off

Includes - switches off addition of a country code in QUERY_STRING.
Default: On

 

GEOCGIArg string

The Name of parameter which will contain a country code. For example at

 
 GEOCGIArg ipcountry 

And the client come from Russia (RU) in a line of search the parameter ipcountry=RU will be added, accordingly this parameter will be seen to CGI-scripts, dynamic documents and so on.

Remarks

1. At use together with caching the module (mod_accel and so on) to include work mod_geo it is necessary only for those documents for which it is really necessary. Otherwise the argument with a name of the country will be attributed to all URL (switching a picture), that sharply will lower efficiency of caching.

2. The Charge of memory the given module is rather insignificant - units of megabytes under the table in 40 thousand recordings (the size for today), at initialization of the table once in a context of the server these data are shared between all processes and the common charge of memory in calculation on one copy httpd cheap.

TODO

1. Support of more common format of geography (for example, the country/region/gorod/ulitsa/nomer_doma) - a problem only in where to take the appropriate database small blood.