Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nginx
GitHub Repository: nginx/nginx.org
Path: blob/main/xml/en/docs/stream/ngx_stream_keyval_module.xml
1 views
1
<?xml version="1.0"?>
2
3
<!--
4
Copyright (C) Nginx, Inc.
5
-->
6
7
<!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">
8
9
<module name="Module ngx_stream_keyval_module"
10
link="/en/docs/stream/ngx_stream_keyval_module.html"
11
lang="en"
12
rev="11">
13
14
<section id="summary">
15
16
<para>
17
The <literal>ngx_stream_keyval_module</literal> module (1.13.7) creates variables
18
with values taken from key-value pairs managed by the
19
<link doc="../http/ngx_http_api_module.xml" id="stream_keyvals_">API</link>
20
or a variable that can also be set with
21
<link url="https://github.com/nginx/njs-examples/">njs</link>.
22
</para>
23
24
<para>
25
<note>
26
This module is available as part of our
27
<commercial_version>commercial subscription</commercial_version>.
28
</note>
29
</para>
30
31
</section>
32
33
34
<section id="example" name="Example Configuration">
35
36
<para>
37
<example>
38
http {
39
40
server {
41
...
42
location /api {
43
api write=on;
44
}
45
}
46
}
47
48
stream {
49
50
keyval_zone zone=one:32k state=/var/lib/nginx/state/one.keyval;
51
keyval $ssl_server_name $name zone=one;
52
53
server {
54
listen 12345 ssl;
55
proxy_pass $name;
56
ssl_certificate /usr/local/nginx/conf/cert.pem;
57
ssl_certificate_key /usr/local/nginx/conf/cert.key;
58
}
59
}
60
</example>
61
</para>
62
63
</section>
64
65
66
<section id="directives" name="Directives">
67
68
<directive name="keyval">
69
<syntax>
70
<value>key</value>
71
<value>$variable</value>
72
<literal>zone</literal>=<value>name</value></syntax>
73
<default/>
74
<context>stream</context>
75
76
<para>
77
Creates a new <value>$variable</value> whose value
78
is looked up by the <value>key</value> in the key-value database.
79
Matching rules are defined by the
80
<link id="keyval_type"><literal>type</literal></link> parameter of the
81
<link id="keyval_zone"><literal>keyval_zone</literal></link> directive.
82
The database is stored in a shared memory zone
83
specified by the <literal>zone</literal> parameter.
84
</para>
85
86
</directive>
87
88
89
<directive name="keyval_zone">
90
<syntax>
91
<literal>zone</literal>=<value>name</value>:<value>size</value>
92
[<literal>state</literal>=<value>file</value>]
93
[<literal>timeout</literal>=<value>time</value>]
94
[<literal>type</literal>=<literal>string</literal>|<literal>ip</literal>|<literal>prefix</literal>]
95
[<literal>sync</literal>]</syntax>
96
<default/>
97
<context>stream</context>
98
99
<para>
100
Sets the <value>name</value> and <value>size</value> of the shared memory zone
101
that keeps the key-value database.
102
Key-value pairs are managed by the
103
<link doc="../http/ngx_http_api_module.xml" id="stream_keyvals_">API</link>.
104
</para>
105
106
<para id="keyval_state">
107
The optional <literal>state</literal> parameter specifies a <value>file</value>
108
that keeps the current state of the key-value database in the JSON format
109
and makes it persistent across nginx restarts.
110
Changing the file content directly should be avoided.
111
</para>
112
113
<para>
114
Examples:
115
<example>
116
keyval_zone zone=one:32k state=/var/lib/nginx/state/one.keyval; # path for Linux
117
keyval_zone zone=one:32k state=/var/db/nginx/state/one.keyval; # path for FreeBSD
118
</example>
119
</para>
120
121
<para id="keyval_timeout">
122
The optional <literal>timeout</literal> parameter (1.15.0) sets
123
the time after which key-value pairs are removed from the zone.
124
</para>
125
126
<para id="keyval_type">
127
The optional <literal>type</literal> parameter (1.17.1) activates
128
an extra index optimized for matching the key of a certain type
129
and defines matching rules when evaluating
130
a <link id="keyval">keyval</link> <literal>$variable</literal>.
131
<note>
132
The index is stored in the same shared memory zone
133
and thus requires additional storage.
134
</note>
135
136
<list type="tag">
137
138
<tag-name id="keyval_type_string"><literal>type=string</literal></tag-name>
139
<tag-desc>
140
default, no index is enabled;
141
variable lookup is performed using exact match
142
of the record key and a search key
143
</tag-desc>
144
145
<tag-name id="keyval_type_ip"><literal>type=ip</literal></tag-name>
146
<tag-desc>
147
the search key is the textual representation of IPv4 or IPv6 address
148
or CIDR range;
149
to match a record key, the search key must belong to a subnet
150
specified by a record key or exactly match an IP address
151
</tag-desc>
152
153
<tag-name id="keyval_type_prefix"><literal>type=prefix</literal></tag-name>
154
<tag-desc>
155
variable lookup is performed using prefix match
156
of a record key and a search key (1.17.5);
157
to match a record key, the record key must be a prefix of the search key
158
</tag-desc>
159
160
</list>
161
</para>
162
163
<para id="keyval_sync">
164
The optional <literal>sync</literal> parameter (1.15.0) enables
165
<link doc="ngx_stream_zone_sync_module.xml" id="zone_sync">synchronization</link>
166
of the shared memory zone.
167
The synchronization requires the
168
<literal>timeout</literal> parameter to be set.
169
<note>
170
If the synchronization is enabled, removal of key-value pairs (no matter
171
<link doc="../http/ngx_http_api_module.xml" id="patchStreamKeyvalZoneKeyValue">one</link>
172
or
173
<link doc="../http/ngx_http_api_module.xml" id="deleteStreamKeyvalZoneData">all</link>)
174
will be performed only on a target cluster node.
175
The same key-value pairs on other cluster nodes
176
will be removed upon <literal>timeout</literal>.
177
</note>
178
</para>
179
180
</directive>
181
182
</section>
183
184
</module>
185
186