# HG changeset patch # User Yaroslav Zhuravlev # Date 1434650647 -10800 # Node ID 53ae63cb4cfaa80e5b7c564885d1f37a981e8452 # Parent 7ece86947201c8669e0daa39b853d8d923f8472b Added the limit_conn module for stream. diff -r 7ece86947201 -r 53ae63cb4cfa xml/en/GNUmakefile --- 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 \ diff -r 7ece86947201 -r 53ae63cb4cfa xml/en/docs/index.xml --- 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 @@
@@ -482,6 +482,11 @@ + +ngx_stream_limit_conn_module + + + ngx_stream_proxy_module diff -r 7ece86947201 -r 53ae63cb4cfa xml/en/docs/stream/ngx_stream_limit_conn_module.xml --- /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 @@ + + + + + + + + +
+ + +The ngx_stream_limit_conn_module 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. + + +
+ + +
+ + + +stream { + limit_conn_zone $binary_remote_addr zone=addr:10m; + + ... + + server { + + ... + + limit_conn addr 1; + limit_conn_log_level error; + } +} + + + +
+ + +
+ + +zone number + +stream +server + + +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 + +limit_conn_zone $binary_remote_addr zone=addr:10m; + +server { + ... + limit_conn addr 1; +} + +allow only one connection per an IP address at a time. + + + +When several limit_conn directives are specified, +any configured limit will apply. + + + +The directives are inherited from the previous level if and +only if there are no +limit_conn +directives on the current level. + + + + + + + +info | +notice | +warn | +error +error +stream +server + + +Sets the desired logging level for cases when the server +limits the number of connections. + + + + + + + + key + zone=name:size + +stream + + +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 key is +the client address in the binary form specified as +$binary_remote_addr. +Connections with an empty key value are not accounted. +Usage example: + +limit_conn_zone $binary_remote_addr zone=addr:10m; + +Here, the key is a client IP address set by the +$binary_remote_addr key. +The size of $binary_remote_addr +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. + + + + + +
+ +
diff -r 7ece86947201 -r 53ae63cb4cfa xml/ru/GNUmakefile --- 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 = \ diff -r 7ece86947201 -r 53ae63cb4cfa xml/ru/docs/index.xml --- 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 @@
@@ -486,6 +486,11 @@ + +ngx_stream_limit_conn_module + + + ngx_stream_proxy_module diff -r 7ece86947201 -r 53ae63cb4cfa xml/ru/docs/stream/ngx_stream_limit_conn_module.xml --- /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 @@ + + + + + + + + +
+ + +Модуль ngx_stream_limit_conn_module (1.9.3) позволяет +ограничить +число соединений по заданному ключу, в частности, число соединений с одного +IP-адреса. + + +
+ + +
+ + + +stream { + limit_conn_zone $binary_remote_addr zone=addr:10m; + + ... + + server { + + ... + + limit_conn addr 1; + limit_conn_log_level error; + } +} + + + +
+ + +
+ + +зона число + +stream +server + + +Задаёт зону разделяемой памяти и максимально допустимое число соединений +для одного значения ключа. +При превышении этого числа сервер закроет соединение. +Например, директивы + +limit_conn_zone $binary_remote_addr zone=addr:10m; + +server { + ... + limit_conn addr 1; +} + +разрешают одновременно обрабатывать не более одного соединения с одного +IP-адреса. + + + +Допустимо одновременное указание нескольких директив +limit_conn, +при этом будет срабатывать любое из ограничений. + + + +Директивы наследуются с предыдущего уровня при условии, что на данном уровне +не описаны свои директивы limit_conn. + + + + + + + +info | +notice | +warn | +error +error +stream +server + + +Задаёт желаемый уровень записи в лог случаев ограничения +числа соединений. + + + + + + + + ключ + zone=название:размер + +stream + + +Задаёт параметры зоны разделяемой памяти, которая хранит состояние +для разных значений ключа. +Состояние в частности содержит текущее число соединений. +На данный момент возможным значением для ключа является +адрес клиента в бинарном виде, указываемый как +$binary_remote_addr. +Запросы с пустым значением ключа не учитываются. +Пример использования: + +limit_conn_zone $binary_remote_addr zone=addr:10m; + +Здесь в качестве ключа используется IP-адрес клиента, +задаваемый ключом $binary_remote_addr. +Длина значения $binary_remote_addr +равна 4 байтам, при этом размер состояния всегда равен 32 байтам +на 32-битных платформах и 64 байтам на 64-битных. +В зоне размером 1 мегабайт может разместиться около 32 тысяч состояний +размером 32 байта или 16 тысяч состояний размером 64 байта. +При переполнении зоны сервер закроет соединение. + + + + + +
+ +