Mercurial > hg > nginx-site
changeset 1517:53ae63cb4cfa
Added the limit_conn module for stream.
author | Yaroslav Zhuravlev <yar@nginx.com> |
---|---|
date | Thu, 18 Jun 2015 21:04:07 +0300 |
parents | 7ece86947201 |
children | 0d349b6211f5 |
files | xml/en/GNUmakefile xml/en/docs/index.xml xml/en/docs/stream/ngx_stream_limit_conn_module.xml xml/ru/GNUmakefile xml/ru/docs/index.xml xml/ru/docs/stream/ngx_stream_limit_conn_module.xml |
diffstat | 6 files changed, 296 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/xml/en/GNUmakefile Tue Jun 16 18:20:32 2015 +0300 +++ b/xml/en/GNUmakefile Thu Jun 18 21:04:07 2015 +0300 @@ -93,6 +93,7 @@ mail/ngx_mail_ssl_module \ stream/ngx_stream_access_module \ stream/ngx_stream_core_module \ + stream/ngx_stream_limit_conn_module \ stream/ngx_stream_proxy_module \ stream/ngx_stream_ssl_module \ stream/ngx_stream_upstream_module \
--- a/xml/en/docs/index.xml Tue Jun 16 18:20:32 2015 +0300 +++ b/xml/en/docs/index.xml Thu Jun 18 21:04:07 2015 +0300 @@ -8,7 +8,7 @@ <article name="nginx documentation" link="/en/docs/" lang="en" - rev="20" + rev="21" toc="no"> @@ -482,6 +482,11 @@ </listitem> <listitem> +<link doc="stream/ngx_stream_limit_conn_module.xml"> +ngx_stream_limit_conn_module</link> +</listitem> + +<listitem> <link doc="stream/ngx_stream_proxy_module.xml"> ngx_stream_proxy_module</link> </listitem>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/en/docs/stream/ngx_stream_limit_conn_module.xml Thu Jun 18 21:04:07 2015 +0300 @@ -0,0 +1,141 @@ +<?xml version="1.0"?> + +<!-- + Copyright (C) Igor Sysoev + Copyright (C) Nginx, Inc. + --> + +<!DOCTYPE module SYSTEM "../../../../dtd/module.dtd"> + +<module name="Module ngx_stream_limit_conn_module" + link="/en/docs/stream/ngx_stream_limit_conn_module.html" + lang="en" + rev="1"> + +<section id="summary"> + +<para> +The <literal>ngx_stream_limit_conn_module</literal> module (1.9.3) is used to +limit the number of connections per the defined key, in +particular, the number of connections from a single IP address. +</para> + +</section> + + +<section id="example" name="Example Configuration"> + +<para> +<example> +stream { + limit_conn_zone $binary_remote_addr zone=addr:10m; + + ... + + server { + + ... + + limit_conn addr 1; + limit_conn_log_level error; + } +} +</example> +</para> + +</section> + + +<section id="directives" name="Directives"> + +<directive name="limit_conn"> +<syntax><value>zone</value> <value>number</value></syntax> +<default/> +<context>stream</context> +<context>server</context> + +<para> +Sets the shared memory zone +and the maximum allowed number of connections for a given key value. +When this limit is exceeded, the server will close the connection. +For example, the directives +<example> +limit_conn_zone $binary_remote_addr zone=addr:10m; + +server { + ... + limit_conn addr 1; +} +</example> +allow only one connection per an IP address at a time. +</para> + +<para> +When several <literal>limit_conn</literal> directives are specified, +any configured limit will apply. +</para> + +<para> +The directives are inherited from the previous level if and +only if there are no +<literal>limit_conn</literal> +directives on the current level. +</para> + +</directive> + + +<directive name="limit_conn_log_level"> +<syntax> +<literal>info</literal> | +<literal>notice</literal> | +<literal>warn</literal> | +<literal>error</literal></syntax> +<default>error</default> +<context>stream</context> +<context>server</context> + +<para> +Sets the desired logging level for cases when the server +limits the number of connections. +</para> + +</directive> + + +<directive name="limit_conn_zone"> +<syntax> + <value>key</value> + <literal>zone</literal>=<value>name</value>:<value>size</value></syntax> +<default/> +<context>stream</context> + +<para> +Sets parameters for a shared memory zone +that will keep states for various keys. +In particular, the state includes the current number of connections. +Currently, the supported value for the <value>key</value> is +the client address in the binary form specified as +<literal>$binary_remote_addr</literal>. +Connections with an empty key value are not accounted. +Usage example: +<example> +limit_conn_zone $binary_remote_addr zone=addr:10m; +</example> +Here, the key is a client IP address set by the +<literal>$binary_remote_addr</literal> key. +The size of <literal>$binary_remote_addr</literal> +is 4 bytes. +The stored state always occupies 32 bytes +on 32-bit platforms and 64 bytes on 64-bit platforms. +One megabyte zone can keep about 32 thousand 32-byte states +or about 16 thousand 64-byte states. +If the zone storage is exhausted, the server will close the connection. +</para> + +</directive> + + +</section> + +</module>
--- a/xml/ru/GNUmakefile Tue Jun 16 18:20:32 2015 +0300 +++ b/xml/ru/GNUmakefile Thu Jun 18 21:04:07 2015 +0300 @@ -82,6 +82,7 @@ mail/ngx_mail_smtp_module \ mail/ngx_mail_ssl_module \ stream/ngx_stream_access_module \ + stream/ngx_stream_limit_conn_module \ stream/ngx_stream_proxy_module \ TOP = \
--- a/xml/ru/docs/index.xml Tue Jun 16 18:20:32 2015 +0300 +++ b/xml/ru/docs/index.xml Thu Jun 18 21:04:07 2015 +0300 @@ -8,7 +8,7 @@ <article name="nginx: документация" link="/ru/docs/" lang="ru" - rev="20" + rev="21" toc="no"> @@ -486,6 +486,11 @@ </listitem> <listitem> +<link doc="stream/ngx_stream_limit_conn_module.xml"> +ngx_stream_limit_conn_module</link> +</listitem> + +<listitem> <link doc="stream/ngx_stream_proxy_module.xml"> ngx_stream_proxy_module</link> </listitem>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/ru/docs/stream/ngx_stream_limit_conn_module.xml Thu Jun 18 21:04:07 2015 +0300 @@ -0,0 +1,141 @@ +<?xml version="1.0"?> + +<!-- + Copyright (C) Igor Sysoev + Copyright (C) Nginx, Inc. + --> + +<!DOCTYPE module SYSTEM "../../../../dtd/module.dtd"> + +<module name="Модуль ngx_stream_limit_conn_module" + link="/ru/docs/stream/ngx_stream_limit_conn_module.html" + lang="ru" + rev="1"> + +<section id="summary"> + +<para> +Модуль <literal>ngx_stream_limit_conn_module</literal> (1.9.3) позволяет +ограничить +число соединений по заданному ключу, в частности, число соединений с одного +IP-адреса. +</para> + +</section> + + +<section id="example" name="Пример конфигурации"> + +<para> +<example> +stream { + limit_conn_zone $binary_remote_addr zone=addr:10m; + + ... + + server { + + ... + + limit_conn addr 1; + limit_conn_log_level error; + } +} +</example> +</para> + +</section> + + +<section id="directives" name="Директивы"> + +<directive name="limit_conn"> +<syntax><value>зона</value> <value>число</value></syntax> +<default/> +<context>stream</context> +<context>server</context> + +<para> +Задаёт зону разделяемой памяти и максимально допустимое число соединений +для одного значения ключа. +При превышении этого числа сервер закроет соединение. +Например, директивы +<example> +limit_conn_zone $binary_remote_addr zone=addr:10m; + +server { + ... + limit_conn addr 1; +} +</example> +разрешают одновременно обрабатывать не более одного соединения с одного +IP-адреса. +</para> + +<para> +Допустимо одновременное указание нескольких директив +<literal>limit_conn</literal>, +при этом будет срабатывать любое из ограничений. +</para> + +<para> +Директивы наследуются с предыдущего уровня при условии, что на данном уровне +не описаны свои директивы <literal>limit_conn</literal>. +</para> + +</directive> + + +<directive name="limit_conn_log_level"> +<syntax> +<literal>info</literal> | +<literal>notice</literal> | +<literal>warn</literal> | +<literal>error</literal></syntax> +<default>error</default> +<context>stream</context> +<context>server</context> + +<para> +Задаёт желаемый уровень записи в лог случаев ограничения +числа соединений. +</para> + +</directive> + + +<directive name="limit_conn_zone"> +<syntax> + <value>ключ</value> + <literal>zone</literal>=<value>название</value>:<value>размер</value></syntax> +<default/> +<context>stream</context> + +<para> +Задаёт параметры зоны разделяемой памяти, которая хранит состояние +для разных значений ключа. +Состояние в частности содержит текущее число соединений. +На данный момент возможным значением для <value>ключа</value> является +адрес клиента в бинарном виде, указываемый как +<literal>$binary_remote_addr</literal>. +Запросы с пустым значением ключа не учитываются. +Пример использования: +<example> +limit_conn_zone $binary_remote_addr zone=addr:10m; +</example> +Здесь в качестве ключа используется IP-адрес клиента, +задаваемый ключом <literal>$binary_remote_addr</literal>. +Длина значения <literal>$binary_remote_addr</literal> +равна 4 байтам, при этом размер состояния всегда равен 32 байтам +на 32-битных платформах и 64 байтам на 64-битных. +В зоне размером 1 мегабайт может разместиться около 32 тысяч состояний +размером 32 байта или 16 тысяч состояний размером 64 байта. +При переполнении зоны сервер закроет соединение. +</para> + +</directive> + + +</section> + +</module>