comparison 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
comparison
equal deleted inserted replaced
2453:1b0cc44de0fd 2454:253641e268a8
7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd"> 7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd">
8 8
9 <article name="Примеры использования" 9 <article name="Примеры использования"
10 link="/ru/docs/njs/examples.html" 10 link="/ru/docs/njs/examples.html"
11 lang="ru" 11 lang="ru"
12 rev="6"> 12 rev="7">
13 13
14 <section id="helloword" name="Hello World"> 14 <section id="helloword" name="Hello World">
15 15
16 <para> 16 <para>
17 <path>nginx.conf</path>: 17 <path>nginx.conf</path>:
303 </example> 303 </example>
304 </para> 304 </para>
305 305
306 </section> 306 </section>
307 307
308
309 <section id="requests" name="Запись в лог количества запросов от клиента">
310
311 <para>
312 <path>nginx.conf</path>:
313 <example>
314 js_include js_requests.js;
315
316 js_set $num_requests num_requests;
317
318 keyval_zone zone=foo:10m;
319
320 keyval $remote_addr $foo zone=foo;
321
322 log_format bar '$remote_addr [$time_local] $num_requests';
323 access_log logs/access.log bar;
324
325 server {
326 listen 8000;
327
328 location / {
329 root html;
330 }
331 }
332 </example>
333 </para>
334
335 <para>
336 <path>js_requests.js</path>:
337 <example>
338 function num_requests(r)
339 {
340 var n = r.variables.foo;
341 n = n ? Number(n) + 1 : 1;
342 r.variables.foo = n;
343 return n;
344 }
345 </example>
346 <note>
347 Директивы <link doc="../http/ngx_http_keyval_module.xml" id="keyval"/> и
348 <link doc="../http/ngx_http_keyval_module.xml" id="keyval_zone"/>
349 доступны как часть
350 <commercial_version>коммерческой подписки</commercial_version>.
351 </note>
352 </para>
353
354 </section>
355
308 </article> 356 </article>