[edit] geo

Syntax: geo [ $address ] $variable { ... }
Default:
Context: http
Reference: geo


This directive describes the dependency of the value of the defined variable on the client's IP address. By default, the IP address used for doing the lookup is $remote_addr, but since version 0.7.27 it is possible to specify an another variable.

Note that in the case of an invalid IP address, the value 255.255.255.255 is used.

Here we're using $arg_remote_addr:

 geo  $arg_remote_addr $geo {
   (...)
 }

IP addresses are enumerated in CIDR notation. There are four parameters for this directive:

Multiple files can be included.

 geo  $country  {
   default          no; # Sets the default value (client doesn't match any of the enumerated IP addresses) to "no"
   include          conf/geo.conf;
   127.0.0.0/24     us;
   127.0.0.1/32     ru;
   10.1.0.0/16      ru;
   192.168.1.0/24   uk;
 }

In the file conf/geo.conf:

 10.2.0.0/16      ru;
 192.168.2.0/24   ru;

The value will be the the one with maximum agreement. For example, the IP address 127.0.0.1 will get the value "ru", but not "us".

Example with ranges:

 geo  $country  {
   ranges;
   default                    no; # note that ranges precedes all other directives
   127.0.0.0-127.0.0.0        us;
   127.0.0.1-127.0.0.1        ru;
   127.0.0.1-127.0.0.255      us;
   10.1.0.0-10.1.255.255      ru;
   192.168.1.0-192.168.1.255  uk; 
 }

[edit] References


Module: HttpGeoModule