Nginx 教程


Nginx功能概述 为什么选择Nginx Nginx安装 常见问题(FAQ) 配置符号参考 调试 nginx 优化 Nginx 运行和控制Nginx


Nginx事件模块 Nginx主模块


Browser模块 Charset模块 Geo模块 HttpAccess模块 HttpAuthBasic模块 HttpAutoindex模块 HttpEmptyGif模块 HttpFcgi模块 HttpGzip模块 HttpHeaders模块 HttpIndex模块 HttpIndex模块. HttpLimit zone HttpLimitReqest模块 HttpLog模块 HttpProxy模块 HttpRewrite模块 HttpSSI模块 HttpUserId http核心模块 map Memcached


Addition模块 EmbeddedPerl flv GooglePerftools HttpDav模块 HttpGeoIP HttpGzipStatic HttpImageFilter HttpRealIp HttpSecureLink HttpSSL HttpSubstitution HttpXSLT RandomIndex StubStatus模块


MailAuth MailCore MailProxy MailSSL


nginx php-fpm安装配置 nginx在fedora上的安装 nginx在freebsd上的安装 nginx在ubuntu上的安装 nginx在windows上的安装


HWLoadbalancerCheckErrors nginx防盗链 负载均衡 完整例子 完整例子2 虚拟主机



This module creates variables, whose values depend on the IP-address of the client.

Example configuration:

geo  $geo  {

  default          0;     2;   1;      1;




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

default: none


The directive describes the dependency of the value of a variable on the IP-address of a client. By default, the IP-address used for the lookup is $remote_addr, but since version 0.7.27 it is possible to specify which variable should be used.

 geo  $arg_remote_addr $geo {

Addresses are assigned in the form CIDR. Furthermore, there are four special parameters:

Example of the description:

  • delete – deletes the specified network (0.7.23).
  • default - the value of variable, if the client address does not correspond to any assigned address. It is possible so to write instead of default
  • include - text file with addresses and values information. Several files can be inluded like this.
  • proxy - specifies the address of proxy server (0.8.7+). NEED MORE DESCRIPTION...
  • ranges – specifies that the addresses specified are in the form of ranges (0.7.23). This directive must be the first.
 geo  $country  {
   default          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;        us;        ru;      us;      ru;  uk;