# HG changeset patch # User Yaroslav Zhuravlev # Date 1572525199 -10800 # Node ID 253641e268a8817e5948b54db6718da1da7f6b87 # Parent 1b0cc44de0fd476b7c4d858116cde847e8fff71c Added js_requests.js example in njs. diff -r 1b0cc44de0fd -r 253641e268a8 xml/en/docs/http/ngx_http_keyval_module.xml --- a/xml/en/docs/http/ngx_http_keyval_module.xml Tue Oct 29 19:21:03 2019 +0300 +++ b/xml/en/docs/http/ngx_http_keyval_module.xml Thu Oct 31 15:33:19 2019 +0300 @@ -9,14 +9,16 @@ + rev="7">
The ngx_http_keyval_module module (1.13.3) creates variables with values taken from key-value pairs managed by the -API. +API +or a variable (1.15.10) that can also be set with +njs. diff -r 1b0cc44de0fd -r 253641e268a8 xml/en/docs/njs/examples.xml --- a/xml/en/docs/njs/examples.xml Tue Oct 29 19:21:03 2019 +0300 +++ b/xml/en/docs/njs/examples.xml Thu Oct 31 15:33:19 2019 +0300 @@ -9,7 +9,7 @@
+ rev="7">
@@ -305,4 +305,52 @@
+ +
+ + +nginx.conf: + +js_include js_requests.js; + +js_set $num_requests num_requests; + +keyval_zone zone=foo:10m; + +keyval $remote_addr $foo zone=foo; + +log_format bar '$remote_addr [$time_local] $num_requests'; +access_log logs/access.log bar; + +server { + listen 8000; + + location / { + root html; + } +} + + + + +js_requests.js: + +function num_requests(r) +{ + var n = r.variables.foo; + n = n ? Number(n) + 1 : 1; + r.variables.foo = n; + return n; +} + + +The and + directives +are available as part of our +commercial subscription. + + + +
+
diff -r 1b0cc44de0fd -r 253641e268a8 xml/ru/docs/njs/examples.xml --- a/xml/ru/docs/njs/examples.xml Tue Oct 29 19:21:03 2019 +0300 +++ b/xml/ru/docs/njs/examples.xml Thu Oct 31 15:33:19 2019 +0300 @@ -9,7 +9,7 @@
+ rev="7">
@@ -305,4 +305,52 @@
+ +
+ + +nginx.conf: + +js_include js_requests.js; + +js_set $num_requests num_requests; + +keyval_zone zone=foo:10m; + +keyval $remote_addr $foo zone=foo; + +log_format bar '$remote_addr [$time_local] $num_requests'; +access_log logs/access.log bar; + +server { + listen 8000; + + location / { + root html; + } +} + + + + +js_requests.js: + +function num_requests(r) +{ + var n = r.variables.foo; + n = n ? Number(n) + 1 : 1; + r.variables.foo = n; + return n; +} + + +Директивы и + +доступны как часть +коммерческой подписки. + + + +
+