Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nginx
GitHub Repository: nginx/nginx.org
Path: blob/main/xml/en/docs/stream/ngx_stream_map_module.xml
1 views
1
<?xml version="1.0"?>
2
3
<!--
4
Copyright (C) Igor Sysoev
5
Copyright (C) Nginx, Inc.
6
-->
7
8
<!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">
9
10
<module name="Module ngx_stream_map_module"
11
link="/en/docs/stream/ngx_stream_map_module.html"
12
lang="en"
13
rev="3">
14
15
<section id="summary">
16
17
<para>
18
The <literal>ngx_stream_map_module</literal> module (1.11.2) creates variables
19
whose values depend on values of other variables.
20
</para>
21
22
</section>
23
24
25
<section id="example" name="Example Configuration">
26
27
<para>
28
<example>
29
map $remote_addr $limit {
30
127.0.0.1 "";
31
default $binary_remote_addr;
32
}
33
34
limit_conn_zone $limit zone=addr:10m;
35
limit_conn addr 1;
36
</example>
37
</para>
38
39
</section>
40
41
42
<section id="directives" name="Directives">
43
44
<directive name="map">
45
<syntax block="yes">
46
<value>string</value>
47
<value>$variable</value></syntax>
48
<default/>
49
<context>stream</context>
50
51
<para>
52
Creates a new variable whose value
53
depends on values of one or more of the source variables
54
specified in the first parameter.
55
</para>
56
57
<para>
58
<note>
59
Since variables are evaluated only when they are used, the mere declaration
60
even of a large number of “<literal>map</literal>” variables
61
does not add any extra costs to connection processing.
62
</note>
63
</para>
64
65
<para>
66
Parameters inside the <literal>map</literal> block specify a mapping
67
between source and resulting values.
68
</para>
69
70
<para>
71
Source values are specified as strings or regular expressions.
72
</para>
73
74
<para>
75
Strings are matched ignoring the case.
76
</para>
77
78
<para>
79
A regular expression should either start from the “<literal>~</literal>
80
symbol for a case-sensitive matching, or from the “<literal>~*</literal>
81
symbols for case-insensitive matching.
82
A regular expression can contain named and positional captures
83
that can later be used in other directives along with the
84
resulting variable.
85
</para>
86
87
<para>
88
If a source value matches one of the names of special parameters
89
described below, it should be prefixed with the “<literal>\</literal>” symbol.
90
</para>
91
92
<para>
93
The resulting value can contain text,
94
variable, and their combination.
95
</para>
96
97
<para>
98
The following special parameters are also supported:
99
<list type="tag">
100
<tag-name><literal>default</literal> <value>value</value></tag-name>
101
<tag-desc>
102
sets the resulting value if the source value matches none
103
of the specified variants.
104
When <literal>default</literal> is not specified, the default
105
resulting value will be an empty string.
106
</tag-desc>
107
108
<tag-name><literal>hostnames</literal></tag-name>
109
<tag-desc>
110
indicates that source values can be hostnames with a prefix or suffix mask:
111
<example>
112
*.example.com 1;
113
example.* 1;
114
</example>
115
The following two records
116
<example>
117
example.com 1;
118
*.example.com 1;
119
</example>
120
can be combined:
121
<example>
122
.example.com 1;
123
</example>
124
This parameter should be specified before the list of values.
125
</tag-desc>
126
127
<tag-name><literal>include</literal> <value>file</value></tag-name>
128
<tag-desc>
129
includes a file with values.
130
There can be several inclusions.
131
</tag-desc>
132
133
<tag-name id="volatile"><literal>volatile</literal></tag-name>
134
<tag-desc>
135
indicates that the variable is not cacheable (1.11.7).
136
</tag-desc>
137
138
</list>
139
</para>
140
141
<para>
142
The search is performed in the following order of priority
143
and terminates on the first matching variant:
144
<list type="enum">
145
146
<listitem>
147
the string value without a mask
148
</listitem>
149
150
<listitem>
151
the longest string value with a prefix mask,
152
e.g. “<literal>*.example.com</literal>
153
</listitem>
154
155
<listitem>
156
the longest string value with a suffix mask,
157
e.g. “<literal>mail.*</literal>
158
</listitem>
159
160
<listitem>
161
the first matching regular expression
162
(in order of appearance in the configuration file)
163
</listitem>
164
165
<listitem>
166
the default value
167
</listitem>
168
169
</list>
170
</para>
171
172
</directive>
173
174
175
<directive name="map_hash_bucket_size">
176
<syntax><value>size</value></syntax>
177
<default>32|64|128</default>
178
<context>stream</context>
179
180
<para>
181
Sets the bucket size for the <link id="map"/> variables hash tables.
182
Default value depends on the processor’s cache line size.
183
The details of setting up hash tables are provided in a separate
184
<link doc="../hash.xml">document</link>.
185
</para>
186
187
</directive>
188
189
190
<directive name="map_hash_max_size">
191
<syntax><value>size</value></syntax>
192
<default>2048</default>
193
<context>stream</context>
194
195
<para>
196
Sets the maximum <value>size</value> of the <link id="map"/> variables
197
hash tables.
198
The details of setting up hash tables are provided in a separate
199
<link doc="../hash.xml">document</link>.
200
</para>
201
202
</directive>
203
204
</section>
205
206
</module>
207
208