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