Page Discussion History

Difference between revisions of "HttpGeoModule"

m (References: update link to the original documentation)
Line 75: Line 75:
= References =
= References =
* [http://nginx.org/en/docs/http/ngx_http_geo_module.html Original Documentation]
* [[HWLoadbalancerCheckErrors]]
* [[HWLoadbalancerCheckErrors]]
* [http://www.ruby-forum.com/topic/125810 Creating geo.conf From MaxMind GeoIP Country Database]
* [http://www.ruby-forum.com/topic/125810 Creating geo.conf From MaxMind GeoIP Country Database]
* [http://sysoev.ru/nginx/docs/http/ngx_http_geo_module.html Original Documentation]

Revision as of 15:24, 21 April 2012



This module makes available variables, whose values depend on the IP address of the client. When combined with Geo IP module allows for very elaborate rules serving content according to the geolocation context.

Here'a an example configuration:

geo  $geo  { # the variable created is $geo
  default          0;     2;   1;      1;



syntax: geo [$ip_variable] $variable { ... }

default: none

context: http

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 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:

  • delete – deletes the specified network (0.7.23).
  • default - the value of the defined variable, if the client address does not correspond to any of the enumerated addresses in the directive clauses. Any IP address not matching the enumerated IP adresses is matched by this clause that sets the value of the defined variable.
  • include - specifies a file mapping addresses to values of the defined variable.

Multiple files can be included.

  • proxy - specifies the address of a proxy server (requires Nginx version ≥ 0.8.7). NEED MORE DESCRIPTION...
  • ranges – specifies that the IP addresses enumerated are in the form of ranges (requires Nginx version ≥ 0.7.23) instead of CIDR notation. This directive must precede all other .
 geo  $country  {
   default          no; # Sets the default value (client doesn't match any of the enumerated IP addresses) to "no"
   include          conf/geo.conf;     us;     ru;      ru;   uk;

In the file conf/geo.conf:      ru;   ru;

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

Example with ranges:

 geo  $country  {
   default                    no; # note that ranges precedes all other directives        us;        ru;      us;      ru;  uk;