# HG changeset patch # User Yaroslav Zhuravlev # Date 1434650647 -10800 # Node ID 53ae63cb4cfaa80e5b7c564885d1f37a981e8452 # Parent 7ece86947201c8669e0daa39b853d8d923f8472b Added the limit_conn module for stream. diff --git a/xml/en/GNUmakefile b/xml/en/GNUmakefile --- a/xml/en/GNUmakefile +++ b/xml/en/GNUmakefile @@ -93,6 +93,7 @@ REFS = \ 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 --git a/xml/en/docs/index.xml b/xml/en/docs/index.xml --- a/xml/en/docs/index.xml +++ b/xml/en/docs/index.xml @@ -8,7 +8,7 @@
@@ -482,6 +482,11 @@ ngx_stream_access_module + +ngx_stream_limit_conn_module + + + ngx_stream_proxy_module diff --git a/xml/en/docs/http/ngx_http_limit_conn_module.xml b/xml/en/docs/stream/ngx_stream_limit_conn_module.xml copy from xml/en/docs/http/ngx_http_limit_conn_module.xml copy to xml/en/docs/stream/ngx_stream_limit_conn_module.xml --- a/xml/en/docs/http/ngx_http_limit_conn_module.xml +++ b/xml/en/docs/stream/ngx_stream_limit_conn_module.xml @@ -7,25 +7,19 @@ - + rev="1">
-The ngx_http_limit_conn_module module is used to +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. - -Not all connections are counted. -A connection is counted only if it has a request processed by the server -and the whole request header has already been read. - -
@@ -33,7 +27,7 @@ and the whole request header has already -http { +stream { limit_conn_zone $binary_remote_addr zone=addr:10m; ... @@ -42,9 +36,10 @@ http { ... - location /download/ { - limit_conn addr 1; - } + limit_conn addr 1; + limit_conn_log_level error; + } +} @@ -56,52 +51,32 @@ http { zone number -http +stream server -location 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 return the - -error in reply to a request. +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 { - location /download/ { - limit_conn addr 1; - } + ... + limit_conn addr 1; +} allow only one connection per an IP address at a time. - -In SPDY, each concurrent request is considered a separate connection. - When several limit_conn directives are specified, any configured limit will apply. -For example, the following configuration will limit the number -of connections to the server per a client IP and, at the same time, -the total number of connections to the virtual host: - -limit_conn_zone $binary_remote_addr zone=perip:10m; -limit_conn_zone $server_name zone=perserver:10m; - -server { - ... - limit_conn perip 10; - limit_conn perserver 100; -} - - -These directives are inherited from the previous level if and +The directives are inherited from the previous level if and only if there are no limit_conn directives on the current level. @@ -117,10 +92,8 @@ directives on the current level. warn | error error -http +stream server -location -0.8.18 Sets the desired logging level for cases when the server @@ -130,85 +103,39 @@ limits the number of connections. - -code -503 -http -server -location -1.3.15 - - -Sets the status code to return in response to rejected requests. - - - - - key zone=name:size -http +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. -The key can contain text, variables, and their combination. -Requests with an empty key value are not accounted. - -Prior to version 1.7.6, a key could contain exactly one variable. - +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, a client IP address serves as a key. -Note that instead of $remote_addr, the -$binary_remote_addr variable is used here. -The $remote_addr variable’s size can -vary from 7 to 15 bytes. -The stored state occupies either -32 or 64 bytes of memory on 32-bit platforms and always 64 -bytes on 64-bit platforms. -The $binary_remote_addr variable’s size -is always 4 bytes. +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 return the - -error to all further requests. +If the zone storage is exhausted, the server will close the connection. - - - name - $variable - size - -http - - -This directive was made obsolete in version 1.1.8 -and was removed in version 1.7.6. -An equivalent directive -with a changed syntax should be used instead: - -limit_conn_zone -$variable -zone=name:size; - - - - -
diff --git a/xml/ru/GNUmakefile b/xml/ru/GNUmakefile --- a/xml/ru/GNUmakefile +++ b/xml/ru/GNUmakefile @@ -82,6 +82,7 @@ REFS = \ 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 --git a/xml/ru/docs/index.xml b/xml/ru/docs/index.xml --- a/xml/ru/docs/index.xml +++ b/xml/ru/docs/index.xml @@ -8,7 +8,7 @@
@@ -486,6 +486,11 @@ ngx_stream_access_module + +ngx_stream_limit_conn_module + + + ngx_stream_proxy_module diff --git a/xml/ru/docs/http/ngx_http_limit_conn_module.xml b/xml/ru/docs/stream/ngx_stream_limit_conn_module.xml copy from xml/ru/docs/http/ngx_http_limit_conn_module.xml copy to xml/ru/docs/stream/ngx_stream_limit_conn_module.xml --- a/xml/ru/docs/http/ngx_http_limit_conn_module.xml +++ b/xml/ru/docs/stream/ngx_stream_limit_conn_module.xml @@ -7,24 +7,20 @@ - + rev="1">
-Модуль ngx_http_limit_conn_module позволяет ограничить +Модуль ngx_stream_limit_conn_module (1.9.3) позволяет +ограничить число соединений по заданному ключу, в частности, число соединений с одного IP-адреса. - -Учитываются не все соединения, а лишь те, в которых имеются -запросы, обрабатываемые сервером, и заголовок запроса уже прочитан. - -
@@ -32,7 +28,7 @@ IP-адреса. -http { +stream { limit_conn_zone $binary_remote_addr zone=addr:10m; ... @@ -41,9 +37,10 @@ http { ... - location /download/ { - limit_conn addr 1; - } + limit_conn addr 1; + limit_conn_log_level error; + } +} @@ -55,49 +52,30 @@ http { зона число -http +stream server -location Задаёт зону разделяемой памяти и максимально допустимое число соединений для одного значения ключа. -При превышении этого числа в ответ на запрос сервер вернёт ошибку -. +При превышении этого числа сервер закроет соединение. Например, директивы limit_conn_zone $binary_remote_addr zone=addr:10m; server { - location /download/ { - limit_conn addr 1; - } + ... + limit_conn addr 1; +} разрешают одновременно обрабатывать не более одного соединения с одного IP-адреса. - -В SPDY каждый параллельный запрос считается отдельным соединением. - Допустимо одновременное указание нескольких директив limit_conn, при этом будет срабатывать любое из ограничений. -Например, следующая конфигурация ограничивает число соединений с сервером -с одного клиентского IP-адреса и в то же время ограничивает общее число -соединений с виртуальным хостом: - -limit_conn_zone $binary_remote_addr zone=perip:10m; -limit_conn_zone $server_name zone=perserver:10m; - -server { - ... - limit_conn perip 10; - limit_conn perserver 100; -} - - @@ -115,10 +93,8 @@ server { warn | error error -http +stream server -location -0.8.18 Задаёт желаемый уровень записи в лог случаев ограничения @@ -128,84 +104,38 @@ server { - -код -503 -http -server -location -1.3.15 - - -Позволяет переопределить код ответа, используемый при отклонении запросов. - - - - - ключ zone=название:размер -http +stream Задаёт параметры зоны разделяемой памяти, которая хранит состояние для разных значений ключа. Состояние в частности содержит текущее число соединений. -В качестве ключа можно использовать текст, переменные и их комбинации. +На данный момент возможным значением для ключа является +адрес клиента в бинарном виде, указываемый как +$binary_remote_addr. Запросы с пустым значением ключа не учитываются. - -До версии 1.7.6 в качестве ключа можно было задать ровно одну переменную. - Пример использования: limit_conn_zone $binary_remote_addr zone=addr:10m; -Здесь в качестве ключа используется IP-адрес клиента. -Обратите внимание, что вместо переменной $remote_addr -использована переменная $binary_remote_addr. -Длина значения переменной $remote_addr может колебаться -от 7 до 15 байт, при этом размер хранимого состояния составляет -либо 32, либо 64 байта на 32-битных платформах и всегда 64 -байта на 64-битных. -Длина значения переменной $binary_remote_addr всегда +Здесь в качестве ключа используется IP-адрес клиента, +задаваемый ключом $binary_remote_addr. +Длина значения $binary_remote_addr равна 4 байтам, при этом размер состояния всегда равен 32 байтам на 32-битных платформах и 64 байтам на 64-битных. В зоне размером 1 мегабайт может разместиться около 32 тысяч состояний размером 32 байта или 16 тысяч состояний размером 64 байта. -При переполнении зоны в ответ на последующие запросы сервер будет -возвращать ошибку -. +При переполнении зоны сервер закроет соединение. - - - название - $переменная - размер - -http - - -Эта директива устарела в версии 1.1.8 -и была удалена в версии 1.7.6. -Вместо неё следует -использовать аналогичную директиву -с изменённым синтаксисом: - -limit_conn_zone -$переменная -zone=название:размер; - - - - -