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, 64 insertions(+), 195 deletions(-) [+] |
line wrap: on
line diff
--- 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 \
--- a/xml/en/docs/index.xml +++ b/xml/en/docs/index.xml @@ -8,7 +8,7 @@ <article name="nginx documentation" link="/en/docs/" lang="en" - rev="20" + rev="21" toc="no"> @@ -482,6 +482,11 @@ ngx_stream_access_module</link> </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>
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 @@ <!DOCTYPE module SYSTEM "../../../../dtd/module.dtd"> -<module name="Module ngx_http_limit_conn_module" - link="/en/docs/http/ngx_http_limit_conn_module.html" +<module name="Module ngx_stream_limit_conn_module" + link="/en/docs/stream/ngx_stream_limit_conn_module.html" lang="en" - rev="5"> + rev="1"> <section id="summary"> <para> -The <literal>ngx_http_limit_conn_module</literal> module is used to +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> -<para> -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. -</para> - </section> @@ -33,7 +27,7 @@ and the whole request header has already <para> <example> -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; + } +} </example> </para> @@ -56,52 +51,32 @@ http { <directive name="limit_conn"> <syntax><value>zone</value> <value>number</value></syntax> <default/> -<context>http</context> +<context>stream</context> <context>server</context> -<context>location</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 return the -<http-status code="503" text="Service Temporarily Unavailable"/> -error in reply to a request. +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 { - location /download/ { - limit_conn addr 1; - } + ... + limit_conn addr 1; +} </example> allow only one connection per an IP address at a time. -<note> -In SPDY, each concurrent request is considered a separate connection. -</note> </para> <para> When several <literal>limit_conn</literal> 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: -<example> -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; -} -</example> - </para> <para> -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 <literal>limit_conn</literal> directives on the current level. @@ -117,10 +92,8 @@ directives on the current level. <literal>warn</literal> | <literal>error</literal></syntax> <default>error</default> -<context>http</context> +<context>stream</context> <context>server</context> -<context>location</context> -<appeared-in>0.8.18</appeared-in> <para> Sets the desired logging level for cases when the server @@ -130,85 +103,39 @@ limits the number of connections. </directive> -<directive name="limit_conn_status"> -<syntax><value>code</value></syntax> -<default>503</default> -<context>http</context> -<context>server</context> -<context>location</context> -<appeared-in>1.3.15</appeared-in> - -<para> -Sets the status code to return in response to rejected requests. -</para> - -</directive> - - <directive name="limit_conn_zone"> <syntax> <value>key</value> <literal>zone</literal>=<value>name</value>:<value>size</value></syntax> <default/> -<context>http</context> +<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. -The <value>key</value> can contain text, variables, and their combination. -Requests with an empty key value are not accounted. -<note> -Prior to version 1.7.6, a <value>key</value> could contain exactly one variable. -</note> +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, a client IP address serves as a key. -Note that instead of <var>$remote_addr</var>, the -<var>$binary_remote_addr</var> variable is used here. -The <var>$remote_addr</var> 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 <var>$binary_remote_addr</var> variable’s size -is always 4 bytes. +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 return the -<http-status code="503" text="Service Temporarily Unavailable"/> -error to all further requests. +If the zone storage is exhausted, the server will close the connection. </para> </directive> -<directive name="limit_zone"> -<syntax> - <value>name</value> - <value>$variable</value> - <value>size</value></syntax> -<default/> -<context>http</context> - -<para> -This directive was made obsolete in version 1.1.8 -and was removed in version 1.7.6. -An equivalent <link id="limit_conn_zone"/> directive -with a changed syntax should be used instead: -<note> -<literal>limit_conn_zone</literal> -<value>$variable</value> -<literal>zone</literal>=<value>name</value>:<value>size</value>; -</note> -</para> - -</directive> - </section> </module>
--- 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 = \
--- a/xml/ru/docs/index.xml +++ b/xml/ru/docs/index.xml @@ -8,7 +8,7 @@ <article name="nginx: документация" link="/ru/docs/" lang="ru" - rev="20" + rev="21" toc="no"> @@ -486,6 +486,11 @@ ngx_stream_access_module</link> </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>
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 @@ <!DOCTYPE module SYSTEM "../../../../dtd/module.dtd"> -<module name="Модуль ngx_http_limit_conn_module" - link="/ru/docs/http/ngx_http_limit_conn_module.html" +<module name="Модуль ngx_stream_limit_conn_module" + link="/ru/docs/stream/ngx_stream_limit_conn_module.html" lang="ru" - rev="5"> + rev="1"> <section id="summary"> <para> -Модуль <literal>ngx_http_limit_conn_module</literal> позволяет ограничить +Модуль <literal>ngx_stream_limit_conn_module</literal> (1.9.3) позволяет +ограничить число соединений по заданному ключу, в частности, число соединений с одного IP-адреса. </para> -<para> -Учитываются не все соединения, а лишь те, в которых имеются -запросы, обрабатываемые сервером, и заголовок запроса уже прочитан. -</para> - </section> @@ -32,7 +28,7 @@ IP-адреса. <para> <example> -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; + } +} </example> </para> @@ -55,49 +52,30 @@ http { <directive name="limit_conn"> <syntax><value>зона</value> <value>число</value></syntax> <default/> -<context>http</context> +<context>stream</context> <context>server</context> -<context>location</context> <para> Задаёт зону разделяемой памяти и максимально допустимое число соединений для одного значения ключа. -При превышении этого числа в ответ на запрос сервер вернёт ошибку -<http-status code="503" text="Service Temporarily Unavailable"/>. +При превышении этого числа сервер закроет соединение. Например, директивы <example> limit_conn_zone $binary_remote_addr zone=addr:10m; server { - location /download/ { - limit_conn addr 1; - } + ... + limit_conn addr 1; +} </example> разрешают одновременно обрабатывать не более одного соединения с одного IP-адреса. -<note> -В SPDY каждый параллельный запрос считается отдельным соединением. -</note> </para> <para> Допустимо одновременное указание нескольких директив <literal>limit_conn</literal>, при этом будет срабатывать любое из ограничений. -Например, следующая конфигурация ограничивает число соединений с сервером -с одного клиентского IP-адреса и в то же время ограничивает общее число -соединений с виртуальным хостом: -<example> -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; -} -</example> - </para> <para> @@ -115,10 +93,8 @@ server { <literal>warn</literal> | <literal>error</literal></syntax> <default>error</default> -<context>http</context> +<context>stream</context> <context>server</context> -<context>location</context> -<appeared-in>0.8.18</appeared-in> <para> Задаёт желаемый уровень записи в лог случаев ограничения @@ -128,84 +104,38 @@ server { </directive> -<directive name="limit_conn_status"> -<syntax><value>код</value></syntax> -<default>503</default> -<context>http</context> -<context>server</context> -<context>location</context> -<appeared-in>1.3.15</appeared-in> - -<para> -Позволяет переопределить код ответа, используемый при отклонении запросов. -</para> - -</directive> - - <directive name="limit_conn_zone"> <syntax> <value>ключ</value> <literal>zone</literal>=<value>название</value>:<value>размер</value></syntax> <default/> -<context>http</context> +<context>stream</context> <para> Задаёт параметры зоны разделяемой памяти, которая хранит состояние для разных значений ключа. Состояние в частности содержит текущее число соединений. -В качестве ключа можно использовать текст, переменные и их комбинации. +На данный момент возможным значением для <value>ключа</value> является +адрес клиента в бинарном виде, указываемый как +<literal>$binary_remote_addr</literal>. Запросы с пустым значением ключа не учитываются. -<note> -До версии 1.7.6 в качестве ключа можно было задать ровно одну переменную. -</note> Пример использования: <example> limit_conn_zone $binary_remote_addr zone=addr:10m; </example> -Здесь в качестве ключа используется IP-адрес клиента. -Обратите внимание, что вместо переменной <var>$remote_addr</var> -использована переменная <var>$binary_remote_addr</var>. -Длина значения переменной <var>$remote_addr</var> может колебаться -от 7 до 15 байт, при этом размер хранимого состояния составляет -либо 32, либо 64 байта на 32-битных платформах и всегда 64 -байта на 64-битных. -Длина значения переменной <var>$binary_remote_addr</var> всегда +Здесь в качестве ключа используется IP-адрес клиента, +задаваемый ключом <literal>$binary_remote_addr</literal>. +Длина значения <literal>$binary_remote_addr</literal> равна 4 байтам, при этом размер состояния всегда равен 32 байтам на 32-битных платформах и 64 байтам на 64-битных. В зоне размером 1 мегабайт может разместиться около 32 тысяч состояний размером 32 байта или 16 тысяч состояний размером 64 байта. -При переполнении зоны в ответ на последующие запросы сервер будет -возвращать ошибку -<http-status code="503" text="Service Temporarily Unavailable"/>. +При переполнении зоны сервер закроет соединение. </para> </directive> -<directive name="limit_zone"> -<syntax> - <value>название</value> - <value>$переменная</value> - <value>размер</value></syntax> -<default/> -<context>http</context> - -<para> -Эта директива устарела в версии 1.1.8 -и была удалена в версии 1.7.6. -Вместо неё следует -использовать аналогичную директиву <link id="limit_conn_zone"/> -с изменённым синтаксисом: -<note> -<literal>limit_conn_zone</literal> -<value>$переменная</value> -<literal>zone</literal>=<value>название</value>:<value>размер</value>; -</note> -</para> - -</directive> - </section> </module>