Path: blob/main/xml/en/docs/stream/ngx_stream_geo_module.xml
1 views
<?xml version="1.0"?>12<!--3Copyright (C) Nginx, Inc.4-->56<!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">78<module name="Module ngx_stream_geo_module"9link="/en/docs/stream/ngx_stream_geo_module.html"10lang="en"11rev="2">1213<section id="summary">1415<para>16The <literal>ngx_stream_geo_module</literal> module (1.11.3) creates variables17with values depending on the client IP address.18</para>1920</section>212223<section id="example" name="Example Configuration">2425<para>26<example>27geo $geo {28default 0;2930127.0.0.1 2;31192.168.1.0/24 1;3210.1.0.0/16 1;3334::1 2;352001:0db8::/32 1;36}37</example>38</para>3940</section>414243<section id="directives" name="Directives">4445<directive name="geo">46<syntax block="yes">[<value>$address</value>] <value>$variable</value></syntax>47<default/>48<context>stream</context>4950<para>51Describes the dependency of values of the specified variable52on the client IP address.53By default, the address is taken from the <var>$remote_addr</var> variable,54but it can also be taken from another variable, for example:55<example>56geo $arg_remote_addr $geo {57...;58}59</example>60</para>6162<para>63<note>64Since variables are evaluated only when used, the mere existence65of even a large number of declared “<literal>geo</literal>” variables66does not cause any extra costs for connection processing.67</note>68</para>6970<para>71If the value of a variable does not represent a valid IP address72then the “<literal>255.255.255.255</literal>” address is used.73</para>7475<para>76Addresses are specified either as prefixes in CIDR notation77(including individual addresses) or as ranges.78</para>7980<para>81The following special parameters are also supported:82<list type="tag">8384<tag-name><literal>delete</literal></tag-name>85<tag-desc>86deletes the specified network.87</tag-desc>8889<tag-name><literal>default</literal></tag-name>90<tag-desc>91a value set to the variable if the client address does not92match any of the specified addresses.93When addresses are specified in CIDR notation,94“<literal>0.0.0.0/0</literal>” and “<literal>::/0</literal>”95can be used instead of <literal>default</literal>.96When <literal>default</literal> is not specified, the default97value will be an empty string.98</tag-desc>99100<tag-name><literal>include</literal></tag-name>101<tag-desc>102includes a file with addresses and values.103There can be several inclusions.104</tag-desc>105106<tag-name><literal>ranges</literal></tag-name>107<tag-desc>108indicates that addresses are specified as ranges.109This parameter should be the first.110To speed up loading of a geo base, addresses should be put in ascending order.111</tag-desc>112113<tag-name id="volatile"><literal>volatile</literal></tag-name>114<tag-desc>115indicates that the variable is not cacheable (1.29.3).116</tag-desc>117118</list>119</para>120121<para>122Example:123<example>124geo $country {125default ZZ;126include conf/geo.conf;127delete 127.0.0.0/16;128129127.0.0.0/24 US;130127.0.0.1/32 RU;13110.1.0.0/16 RU;132192.168.1.0/24 UK;133}134</example>135</para>136137<para>138The <path>conf/geo.conf</path> file could contain the following lines:139<example>14010.2.0.0/16 RU;141192.168.2.0/24 RU;142</example>143</para>144145<para>146A value of the most specific match is used.147For example, for the 127.0.0.1 address the value “<literal>RU</literal>”148will be chosen, not “<literal>US</literal>”.149</para>150151<para>152Example with ranges:153<example>154geo $country {155ranges;156default ZZ;157127.0.0.0-127.0.0.0 US;158127.0.0.1-127.0.0.1 RU;159127.0.0.1-127.0.0.255 US;16010.1.0.0-10.1.255.255 RU;161192.168.1.0-192.168.1.255 UK;162}163</example>164</para>165166</directive>167168</section>169170</module>171172173