Path: blob/main/xml/en/docs/stream/ngx_stream_map_module.xml
1 views
<?xml version="1.0"?>12<!--3Copyright (C) Igor Sysoev4Copyright (C) Nginx, Inc.5-->67<!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">89<module name="Module ngx_stream_map_module"10link="/en/docs/stream/ngx_stream_map_module.html"11lang="en"12rev="3">1314<section id="summary">1516<para>17The <literal>ngx_stream_map_module</literal> module (1.11.2) creates variables18whose values depend on values of other variables.19</para>2021</section>222324<section id="example" name="Example Configuration">2526<para>27<example>28map $remote_addr $limit {29127.0.0.1 "";30default $binary_remote_addr;31}3233limit_conn_zone $limit zone=addr:10m;34limit_conn addr 1;35</example>36</para>3738</section>394041<section id="directives" name="Directives">4243<directive name="map">44<syntax block="yes">45<value>string</value>46<value>$variable</value></syntax>47<default/>48<context>stream</context>4950<para>51Creates a new variable whose value52depends on values of one or more of the source variables53specified in the first parameter.54</para>5556<para>57<note>58Since variables are evaluated only when they are used, the mere declaration59even of a large number of “<literal>map</literal>” variables60does not add any extra costs to connection processing.61</note>62</para>6364<para>65Parameters inside the <literal>map</literal> block specify a mapping66between source and resulting values.67</para>6869<para>70Source values are specified as strings or regular expressions.71</para>7273<para>74Strings are matched ignoring the case.75</para>7677<para>78A regular expression should either start from the “<literal>~</literal>”79symbol for a case-sensitive matching, or from the “<literal>~*</literal>”80symbols for case-insensitive matching.81A regular expression can contain named and positional captures82that can later be used in other directives along with the83resulting variable.84</para>8586<para>87If a source value matches one of the names of special parameters88described below, it should be prefixed with the “<literal>\</literal>” symbol.89</para>9091<para>92The resulting value can contain text,93variable, and their combination.94</para>9596<para>97The following special parameters are also supported:98<list type="tag">99<tag-name><literal>default</literal> <value>value</value></tag-name>100<tag-desc>101sets the resulting value if the source value matches none102of the specified variants.103When <literal>default</literal> is not specified, the default104resulting value will be an empty string.105</tag-desc>106107<tag-name><literal>hostnames</literal></tag-name>108<tag-desc>109indicates that source values can be hostnames with a prefix or suffix mask:110<example>111*.example.com 1;112example.* 1;113</example>114The following two records115<example>116example.com 1;117*.example.com 1;118</example>119can be combined:120<example>121.example.com 1;122</example>123This parameter should be specified before the list of values.124</tag-desc>125126<tag-name><literal>include</literal> <value>file</value></tag-name>127<tag-desc>128includes a file with values.129There can be several inclusions.130</tag-desc>131132<tag-name id="volatile"><literal>volatile</literal></tag-name>133<tag-desc>134indicates that the variable is not cacheable (1.11.7).135</tag-desc>136137</list>138</para>139140<para>141The search is performed in the following order of priority142and terminates on the first matching variant:143<list type="enum">144145<listitem>146the string value without a mask147</listitem>148149<listitem>150the longest string value with a prefix mask,151e.g. “<literal>*.example.com</literal>”152</listitem>153154<listitem>155the longest string value with a suffix mask,156e.g. “<literal>mail.*</literal>”157</listitem>158159<listitem>160the first matching regular expression161(in order of appearance in the configuration file)162</listitem>163164<listitem>165the default value166</listitem>167168</list>169</para>170171</directive>172173174<directive name="map_hash_bucket_size">175<syntax><value>size</value></syntax>176<default>32|64|128</default>177<context>stream</context>178179<para>180Sets the bucket size for the <link id="map"/> variables hash tables.181Default value depends on the processor’s cache line size.182The details of setting up hash tables are provided in a separate183<link doc="../hash.xml">document</link>.184</para>185186</directive>187188189<directive name="map_hash_max_size">190<syntax><value>size</value></syntax>191<default>2048</default>192<context>stream</context>193194<para>195Sets the maximum <value>size</value> of the <link id="map"/> variables196hash tables.197The details of setting up hash tables are provided in a separate198<link doc="../hash.xml">document</link>.199</para>200201</directive>202203</section>204205</module>206207208