diff xml/ru/docs/njs/examples.xml @ 2454:253641e268a8

Added js_requests.js example in njs.
author Yaroslav Zhuravlev <yar@nginx.com>
date Thu, 31 Oct 2019 15:33:19 +0300
parents 86b0dd6e7208
children b60e5be733cd
line wrap: on
line diff
--- 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 @@
 <article name="Примеры использования"
         link="/ru/docs/njs/examples.html"
         lang="ru"
-        rev="6">
+        rev="7">
 
 <section id="helloword" name="Hello World">
 
@@ -305,4 +305,52 @@
 
 </section>
 
+
+<section id="requests" name="Запись в лог количества запросов от клиента">
+
+<para>
+<path>nginx.conf</path>:
+<example>
+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;
+    }
+}
+</example>
+</para>
+
+<para>
+<path>js_requests.js</path>:
+<example>
+function num_requests(r)
+{
+    var n = r.variables.foo;
+    n = n ? Number(n) + 1 : 1;
+    r.variables.foo = n;
+    return n;
+}
+</example>
+<note>
+Директивы <link doc="../http/ngx_http_keyval_module.xml" id="keyval"/> и
+<link doc="../http/ngx_http_keyval_module.xml" id="keyval_zone"/>
+доступны как часть
+<commercial_version>коммерческой подписки</commercial_version>.
+</note>
+</para>
+
+</section>
+
 </article>