# HG changeset patch # User Ruslan Ermilov # Date 1326478234 0 # Node ID 1fb1c077658b1056906ab7899db0fd87e1db10c9 # Parent e00f8f8c0486a6cd1d031edfcaf49f84f73f329e Documented the following directives: "keepalive", "proxy_http_version", and "fastcgi_keep_conn". diff -r e00f8f8c0486 -r 1fb1c077658b xml/en/docs/http/ngx_http_fastcgi_module.xml --- a/xml/en/docs/http/ngx_http_fastcgi_module.xml Fri Jan 13 18:05:01 2012 +0000 +++ b/xml/en/docs/http/ngx_http_fastcgi_module.xml Fri Jan 13 18:10:34 2012 +0000 @@ -417,6 +417,26 @@ + +on | off +off +http +server +location + + +By default, a FastCGI server will close a connection right after +sending the response. +When set to the value on, nginx will instruct +a FastCGI server to keep connections open. +This in particular is necessary for + +connections to FastCGI servers to function. + + + + + error | diff -r e00f8f8c0486 -r 1fb1c077658b xml/en/docs/http/ngx_http_proxy_module.xml --- a/xml/en/docs/http/ngx_http_proxy_module.xml Fri Jan 13 18:05:01 2012 +0000 +++ b/xml/en/docs/http/ngx_http_proxy_module.xml Fri Jan 13 18:10:34 2012 +0000 @@ -372,6 +372,25 @@ + +1.0 | 1.1 +1.0 +http +server +location +1.1.4 + + +Sets the HTTP protocol version for proxying. +By default, version 1.0 is used. +Version 1.1 is recommended for use with + +connections. + + + + + on | off off diff -r e00f8f8c0486 -r 1fb1c077658b xml/en/docs/http/ngx_http_upstream_module.xml --- a/xml/en/docs/http/ngx_http_upstream_module.xml Fri Jan 13 18:05:01 2012 +0000 +++ b/xml/en/docs/http/ngx_http_upstream_module.xml Fri Jan 13 18:10:34 2012 +0000 @@ -84,6 +84,126 @@ + +connections + +upstream +1.1.4 + + +Activates cache of connections to upstream servers. + + + +The connections parameter sets the maximum number of +keepalive connections to upstream servers that are retained in +the cache per one worker process. +If there are more idle connections to retain to an upstream than +are specified by this number, the least recently used ones will +be closed. + +It should be noted that keepalive directive +does not limit the total number of connections that nginx worker +process can open to upstream servers. +The new connections are always created on demand. +The connections parameter should be set low enough +to allow upstream servers to process additional new incoming +connections as well. + + + + +Example configuration of memcached upstream with keepalive connections: + +upstream memcached_backend { + server 127.0.0.1:11211; + server 10.0.0.2:11211; + + keepalive 32; +} + +server { + ... + + location /memcached/ { + set $memcached_key $uri; + memcached_pass memcached_backend; + } + +} + + + + +For HTTP, the +directive should be set to “1.1” +and the
Connection
header field should be cleared: + +upstream http_backend { + server 127.0.0.1:8080; + + keepalive 16; +} + +server { + ... + + location /http/ { + proxy_pass http://http_backend; + proxy_http_version 1.1; + proxy_set_header Connection ""; + ... + } +} + +
+ + + +Alternatively, HTTP/1.0 persistent connections can be used by passing the +
Connection: Keep-Alive
header field to an upstream server, +though this is not recommended. +
+
+ + +For FastCGI servers, it is required to set + +for keepalive connections to work: + +upstream fastcgi_backend { + server 127.0.0.1:9000; + + keepalive 8; +} + +server { + ... + + location /fastcgi/ { + fastcgi_pass fastcgi_backend; + fastcgi_keep_conn on; + ... + } +} + + + + + +When using load balancer modules other than the default +round-robin, it is necessary to activate them before +the keepalive directive. + + + +SCGI and uwsgi protocols do not define keepalive connections. + + + +
+ + name [parameters] diff -r e00f8f8c0486 -r 1fb1c077658b xml/ru/docs/http/ngx_http_fastcgi_module.xml --- a/xml/ru/docs/http/ngx_http_fastcgi_module.xml Fri Jan 13 18:05:01 2012 +0000 +++ b/xml/ru/docs/http/ngx_http_fastcgi_module.xml Fri Jan 13 18:10:34 2012 +0000 @@ -412,6 +412,25 @@ + +on | off +off +http +server +location + + +По умолчанию FastCGI-сервер будет закрывать соединение сразу же +после отправки ответа. +При установке значения on nginx указывает +FastCGI-серверу оставлять соединения открытыми. +Это в частности требуется для функционирования +постоянных +соединений с FastCGI-серверами. + + + + diff -r e00f8f8c0486 -r 1fb1c077658b xml/ru/docs/http/ngx_http_proxy_module.xml --- a/xml/ru/docs/http/ngx_http_proxy_module.xml Fri Jan 13 18:05:01 2012 +0000 +++ b/xml/ru/docs/http/ngx_http_proxy_module.xml Fri Jan 13 18:10:34 2012 +0000 @@ -368,6 +368,25 @@ + +1.0 | 1.1 +1.0 +http +server +location +1.1.4 + + +Задаёт версию протокола HTTP для проксирования. +По умолчанию используется версия 1.0. +Для работы +постоянных +соединений рекомендуется версия 1.1. + + + + + on | off off diff -r e00f8f8c0486 -r 1fb1c077658b xml/ru/docs/http/ngx_http_upstream_module.xml --- a/xml/ru/docs/http/ngx_http_upstream_module.xml Fri Jan 13 18:05:01 2012 +0000 +++ b/xml/ru/docs/http/ngx_http_upstream_module.xml Fri Jan 13 18:10:34 2012 +0000 @@ -87,6 +87,126 @@ + +соединения + +upstream +1.1.4 + + +Задействует кэш соединений для группы серверов. + + + +Параметр соединения устанавливает максимальное число +постоянных соединений с серверами группы, которые будут сохраняться +в кэше каждого рабочего процесса. +При превышении указанного числа неактивных постоянных соединений +с серверами группы самые старые соединения закрываются. + +Следует отметить, что директива keepalive +не ограничивает общее число соединений, которые рабочие процессы +nginx могут открыть с серверами группы. +Новые соединения всегда создаются по мере необходимости. +Параметр соединения следует устанавливать +достаточно консервативно для обеспечения возможности +обработки серверами группы новых входящих соединений. + + + + +Пример конфигурации группы серверов memcached с постоянными соединениями: + +upstream memcached_backend { + server 127.0.0.1:11211; + server 10.0.0.2:11211; + + keepalive 32; +} + +server { + ... + + location /memcached/ { + set $memcached_key $uri; + memcached_pass memcached_backend; + } + +} + + + + +Для HTTP директиву + +следует установить в “1.1”, +а строку заголовка
Connection
— очистить: + +upstream http_backend { + server 127.0.0.1:8080; + + keepalive 16; +} + +server { + ... + + location /http/ { + proxy_pass http://http_backend; + proxy_http_version 1.1; + proxy_set_header Connection ""; + ... + } +} + +
+ + + +Хоть это и не рекомендуется, но также возможно использование постоянных +соединений в HTTP/1.0, путём передачи строки заголовка +
Connection: Keep-Alive
серверу группы. +
+
+ + +Для работы постоянных соединений с FastCGI-серверами потребуется +включить директиву +: + +upstream fastcgi_backend { + server 127.0.0.1:9000; + + keepalive 8; +} + +server { + ... + + location /fastcgi/ { + fastcgi_pass fastcgi_backend; + fastcgi_keep_conn on; + ... + } +} + + + + + +При использовании модулей балансировки нагрузки, отличных +от стандартного round-robin, следует активировать их до +директивы keepalive. + + + +Протоколы SCGI и uwsgi не определяют семантику постоянных соединений. + + + +
+ + название [параметры]