ngx_stream_geo_module 模块

The ngx_stream_geo_module module (1.11.3) creates variables with values depending on the client IP address.

Example Configuration

geo $geo {
   default        0;

   127.0.0.1      2;
   192.168.1.0/24 1;
   10.1.0.0/16    1;

   ::1            2;
   2001:0db8::/32 1;
}

Directives

Syntax:

geo [$address] $variable { ... }
   

Default:

—    

Context:

stream
   

Describes the dependency of values of the specified variable on the client IP address. By default, the address is taken from the $remote_addr variable, but it can also be taken from another variable, for example:

geo $arg_remote_addr $geo {
   ...;
}

Since variables are evaluated only when used, the mere existence of even a large number of declared “geo” variables does not cause any extra costs for connection processing.

If the value of a variable does not represent a valid IP address then the “255.255.255.255” address is used.

Addresses are specified either as prefixes in CIDR notation (including individual addresses) or as ranges.

The following special parameters are also supported:

delete

deletes the specified network.

default

a value set to the variable if the client address does not match any of the specified addresses. When addresses are specified in CIDR notation, “0.0.0.0/0” and “::/0” can be used instead of default. When default is not specified, the default value will be an empty string.

include

includes a file with addresses and values. There can be several inclusions.

ranges

indicates that addresses are specified as ranges. This parameter should be the first. To speed up loading of a geo base, addresses should be put in ascending order.

Example:

geo $country {
   default        ZZ;
   include        conf/geo.conf;
   delete         127.0.0.0/16;

   127.0.0.0/24   US;
   127.0.0.1/32   RU;
   10.1.0.0/16    RU;
   192.168.1.0/24 UK;
}

The conf/geo.conf file could contain the following lines:

10.2.0.0/16    RU;
192.168.2.0/24 RU;

A value of the most specific match is used. For example, for the 127.0.0.1 address the value “RU” will be chosen, not “US”.

Example with ranges:

geo $country {
   ranges;
   default                   ZZ;
   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;
}

说说我的看法
全部评论(
没有评论
关于
本网站专注于 Java、数据库(MySQL、Oracle)、Linux、软件架构及大数据等多领域技术知识分享。涵盖丰富的原创与精选技术文章,助力技术传播与交流。无论是技术新手渴望入门,还是资深开发者寻求进阶,这里都能为您提供深度见解与实用经验,让复杂编码变得轻松易懂,携手共赴技术提升新高度。如有侵权,请来信告知:hxstrive@outlook.com
公众号