# HG changeset patch # User Ruslan Ermilov # Date 1405607992 -14400 # Node ID 954dcc02cb6338e3079e24b9c0c2b8b091088132 # Parent 700487454cf2994f452232dfe8db8b6323619946 Upstream: "session learn" sticky method and upstream_conf changes. diff --git a/xml/en/docs/http/ngx_http_upstream_module.xml b/xml/en/docs/http/ngx_http_upstream_module.xml --- a/xml/en/docs/http/ngx_http_upstream_module.xml +++ b/xml/en/docs/http/ngx_http_upstream_module.xml @@ -10,7 +10,7 @@ + rev="28">
@@ -53,20 +53,20 @@ Dynamically configurable group, available as part of our commercial subscription: -upstream appservers { - zone appservers 64k; +upstream dynamic { + zone upstream_dynamic 64k; - server appserv1.example.com weight=5; - server appserv2.example.com:8080 fail_timeout=5s slow_start=30s; + server backend1.example.com weight=5; + server backend2.example.com:8080 fail_timeout=5s slow_start=30s; server 192.0.2.1 max_fails=3; - server reserve1.example.com:8080 backup; - server reserve2.example.com:8080 backup; + server backup1.example.com:8080 backup; + server backup2.example.com:8080 backup; } server { location / { - proxy_pass http://appservers; + proxy_pass http://dynamic; health_check; } @@ -826,11 +826,19 @@ This directive is available as part of o -cookie name -[expires=time] -[domain=domain] -[path=path] -route variable ... + + cookie name + [expires=time] + [domain=domain] + [path=path] + + route $variable ... + + learn + create=$variable + lookup=$variable + zone=name:size + [timeout=time] upstream 1.5.7 @@ -838,13 +846,14 @@ This directive is available as part of o Enables session affinity, which causes requests from the same client to be passed to the same server in a group of servers. -Two methods are available, -cookie and route. - +Three methods are available: + +cookie + When the cookie method is used, information about the -designated server is passed in an HTTP cookie: +designated server is passed in an HTTP cookie generated by nginx: upstream backend { server backend1.example.com; @@ -858,7 +867,7 @@ upstream backend { A request that comes from a client not yet bound to a particular server is passed to the server selected by the configured balancing method. -Further requests from the same client are passed to the same server. +Further requests with this cookie will be passed to the designated server. If the designated server cannot process a request, the new server is selected as if the client has not been bound yet. @@ -890,6 +899,10 @@ Defines the path for which the cookie is If any parameters are omitted, the corresponding cookie fields are not set. + + +route + When the route method is used, proxied server assigns @@ -933,6 +946,54 @@ if present in a request. Otherwise, the route from the URI is used. + + +learn + + +When the learn method (1.7.1) is used, nginx +analyzes upstream server responses and learns server-initiated sessions +usually passed in an HTTP cookie. + +upstream backend { + server backend1.example.com:8080; + server backend2.example.com:8081; + + sticky learn + create=$upstream_cookie_sessionid + lookup=$cookie_sessionid + zone=client_sessions:1m; +} + + +In the example, the upstream server creates a session by setting the +cookie “SESSIONID” in the response. +Further requests with this cookie will be passed to the same server. +If the server cannot process the request, the new server is +selected as if the client has not been bound yet. + + + +The parameters create and lookup +specify variables that indicate how new sessions are created and existing +sessions are searched, respectively. +Both parameters may be specified more than once, in which case the first +non-empty variable is used. + + + +Sessions are stored in a shared memory zone, whose name and +size are configured by the zone parameter. +One megabyte zone can store about 8000 sessions on the 64-bit platform. +The sessions that are not accessed during the time specified by the +timeout parameter get removed from the zone. +By default, timeout is set to 10 minutes. + + + + + + This directive is available as part of our @@ -982,23 +1043,18 @@ Access to this location should be Configuration commands can be used to: -view all primary or backup servers in a group; - -view an individual server; +view the group configuration; -modify an individual server; +view, modify, or remove an individual server; -add a new server (see the note below); - -remove an individual server. +add a new server. -As noted in the directive, specifying a server -as a domain name may result in several servers being added to the group. Since addresses in a group are not required to be unique, individual -servers in a group can be uniquely referenced to only by their ID. -IDs are assigned automatically and shown on viewing of the group configuration. +servers in a group are referenced by their IDs. +IDs are assigned automatically and shown when adding a new server +or viewing the group configuration. @@ -1006,7 +1062,7 @@ IDs are assigned automatically and shown A configuration command consists of parameters passed as request arguments, for example: -http://127.0.0.1/upstream_conf?upstream=appservers +http://127.0.0.1/upstream_conf?upstream=dynamic @@ -1018,34 +1074,36 @@ The following parameters are supported: upstream=name -Selects a group. +Selects a group to work with. This parameter is mandatory. -backup= - - -If not set, selects primary servers in the group. -If set, selects backup servers in the group. - - - id=number -Selects an individual primary or backup server in the group. +Selects an individual server for viewing, modifying, or removing. remove= -Removes an individual primary or backup server from the group. +Removes an individual server from the group. add= -Adds a new primary or backup server to the group. +Adds a new server to the group. + + + +backup= + +Required to add a backup server. + +Before version 1.7.2, backup= +was also required to view, modify, or remove existing backup servers. + @@ -1053,6 +1111,17 @@ Adds a new primary or backup server to t Same as the “address” parameter of the directive. + +When adding a server, it is possible to specify it as a domain name. +In this case, changes of the IP addresses that correspond to a domain name +will be monitored and automatically applied to the upstream +configuration without the need of restarting nginx (1.7.2). +This requires the + directive in the + block. +See also +the parameter of the directive. + @@ -1106,96 +1175,71 @@ of the directive. -The first three parameters select a target the command applies to. -Without other parameters, the command shows configuration of the selected -target. +The first two parameters select an object. +This can be either the whole group or an individual server. +Without other parameters, the configuration of the selected +group or server is shown. -For example, to view the primary servers in the group, send: +For example, to view the configuration of the whole group, send: -http://127.0.0.1/upstream_conf?upstream=appservers +http://127.0.0.1/upstream_conf?upstream=dynamic -To view the backup servers in the group, send: - -http://127.0.0.1/upstream_conf?upstream=appservers&backup= - - -To view an individual primary server in the group, send: +To view the configuration of an individual server, also specify its ID: -http://127.0.0.1/upstream_conf?upstream=appservers&id=42 - - -To view an individual backup server in the group, send: - -http://127.0.0.1/upstream_conf?upstream=appservers&backup=&id=42 +http://127.0.0.1/upstream_conf?upstream=dynamic&id=42 -To add a new primary or backup server to the group, +To add a new server, specify its address in the “server=” parameter. Without other parameters specified, a server will be added with other parameters set to their default values (see the directive). -For example, to add a new primary server to the group, send: +For example, to add a new primary server, send: -http://127.0.0.1/upstream_conf?add=&upstream=appservers&server=127.0.0.1:8080 +http://127.0.0.1/upstream_conf?add=&upstream=dynamic&server=127.0.0.1:8080 -To add a new backup server to the group, send: +To add a new backup server, send: -http://127.0.0.1/upstream_conf?add=&upstream=appservers&backup=&server=127.0.0.1:8080 +http://127.0.0.1/upstream_conf?add=&upstream=dynamic&backup=&server=127.0.0.1:8080 -To add a new primary server to the group, +To add a new primary server, set its parameters to non-default values and mark it as “down”, send: -http://127.0.0.1/upstream_conf?add=&upstream=appservers&server=127.0.0.1:8080&weight=2&max_fails=3&fail_timeout=3s&down= +http://127.0.0.1/upstream_conf?add=&upstream=dynamic&server=127.0.0.1:8080&weight=2&down= -To remove an individual primary or backup server from the group, -select it with the id= parameter. - - - -For example, to remove an individual primary server from the group, send: +To remove a server, specify its ID: -http://127.0.0.1/upstream_conf?remove=&upstream=appservers&id=42 - - -To remove an individual backup server from the group, send: - -http://127.0.0.1/upstream_conf?remove=&upstream=appservers&backup=&id=42 +http://127.0.0.1/upstream_conf?remove=&upstream=dynamic&id=42 -To modify an individual primary or backup server in the group, -select it with the id= parameter. - - - -For example, to modify an individual primary server in the group -by marking it as “down”, send: +To mark an existing server as “down”, send: -http://127.0.0.1/upstream_conf?upstream=appservers&id=42&down= +http://127.0.0.1/upstream_conf?upstream=dynamic&id=42&down= -To modify the address of an individual backup server in the group, send: +To modify the address of an existing server, send: -http://127.0.0.1/upstream_conf?upstream=appservers&backup=&id=42&server=192.0.2.3:8123 +http://127.0.0.1/upstream_conf?upstream=dynamic&id=42&server=192.0.2.3:8123 -To modify other parameters of an individual primary server in the group, send: +To modify other parameters of an existing server, send: -http://127.0.0.1/upstream_conf?upstream=appservers&id=42&max_fails=3&weight=4 +http://127.0.0.1/upstream_conf?upstream=dynamic&id=42&max_fails=3&weight=4 diff --git a/xml/ru/docs/http/ngx_http_upstream_module.xml b/xml/ru/docs/http/ngx_http_upstream_module.xml --- a/xml/ru/docs/http/ngx_http_upstream_module.xml +++ b/xml/ru/docs/http/ngx_http_upstream_module.xml @@ -10,7 +10,7 @@ + rev="28">
@@ -54,20 +54,20 @@ server { доступна как часть коммерческой подписки: -upstream appservers { - zone appservers 64k; +upstream dynamic { + zone upstream_dynamic 64k; - server appserv1.example.com weight=5; - server appserv2.example.com:8080 fail_timeout=5s slow_start=30s; + server backend1.example.com weight=5; + server backend2.example.com:8080 fail_timeout=5s slow_start=30s; server 192.0.2.1 max_fails=3; - server reserve1.example.com:8080 backup; - server reserve2.example.com:8080 backup; + server backup1.example.com:8080 backup; + server backup2.example.com:8080 backup; } server { location / { - proxy_pass http://appservers; + proxy_pass http://dynamic; health_check; } @@ -832,11 +832,19 @@ match server_ok { -cookie имя -[expires=время] -[domain=домен] -[path=путь] -route переменная ... + + cookie имя + [expires=время] + [domain=домен] + [path=путь] + + route переменная ... + + learn + create=$переменная + lookup=$переменная + zone=имя:размер + [timeout=время] upstream 1.5.7 @@ -844,9 +852,10 @@ match server_ok { Включает режим привязки сеансов, в котором запросы клиента будут передаваться на один и тот же сервер группы. -Доступны два метода: -cookie и route. - +Доступны три метода: + +cookie + При использовании метода cookie информация о @@ -895,6 +904,10 @@ 31 декабря 2037 года 23:55:55 GMT. Если пропущен тот или иной параметр, то соответствующего поля в куке не будет. + + +route + При использовании метода route проксируемый сервер назначает @@ -938,6 +951,55 @@ upstream backend { В противном случае используется маршрут из URI. + + +learn + + +При использовании метода learn (1.7.1) nginx +анализирует ответы от вышестоящего сервера и запоминает +начатые им сессии, которые обычно передаются в HTTP-куке. + +upstream backend { + server backend1.example.com:8080; + server backend2.example.com:8081; + + sticky learn + create=$upstream_cookie_sessionid + lookup=$cookie_sessionid + zone=client_sessions:1m; +} + + +В примере выше сервер группы создаёт сессию путём установки +куки “SESSIONID” в своём ответе. +Последующие запросы с этой кукой будут передаваться на этот же сервер. +Если сервер не может обработать запрос, выбирается новый +сервер как если бы клиент не имел привязки к серверу. + + + +Параметры create и lookup +задают переменные, в которых соответственно указывается способ +создания новых и поиска существующих сессий. +Оба параметра могут быть указаны больше одного раза +(в этом случае используется первая непустая переменная). + + + +Сессии хранятся в зоне разделяемой памяти, имя и +размер которой задаются параметром zone. +Зоны размером в 1 мегабайт достаточно для хранения около 8 тысяч сессий +на 64-битной платформе. +Сессии, к которым не было обращений в течение времени, заданного параметром +timeout, удаляются из зоны. +По умолчанию timeout равен 10 минутам. + + + + + + Эта директива доступна как часть @@ -970,6 +1032,238 @@ upstream backend { + + + + +location + + +Активирует HTTP-интерфейс для настройки групп серверов в содержащем location. +Доступ в location следует +ограничить. + + + +С помощью команд настройки можно: + + +просматривать конфигурацию группы; + + +просматривать или изменять конфигурацию, а также +удалять отдельные серверы; + + +добавлять новые серверы. + + + +Поскольку адреса в группе не обязаны быть уникальными, +обращение к отдельным серверам в группе осуществляется по их идентификаторам. +Идентификаторы назначаются автоматически и показываются при добавлении сервера +или просмотре конфигурации группы. + + + + +Команда настройки состоит из параметров, передаваемых в аргументах запроса, +например: + +http://127.0.0.1/upstream_conf?upstream=dynamic + + + + +Поддерживаются следующие параметры: + + + + +upstream=имя + +Выбирает группу серверов для работы. +Параметр является обязательным. + + + +id=число + +Выбирает отдельный сервер для просмотра, изменения или удаления. + + + +remove= + +Удаляет выбранный сервер из группы. + + + +add= + +Добавляет новый сервер в группу. + + + +backup= + +Необходим для добавления запасного сервера. + +До версии 1.7.2 параметр backup= требовался +также для просмотра, изменения или удаления существующих запасных серверов. + + + + +server=адрес + +То же, что и параметр “адрес” +директивы . + +При добавлении сервер можно задать в виде доменного имени. +В этом случае любые изменения IP-адресов, соответствующих доменному имени +сервера, отслеживаются и автоматически применяются к конфигурации группы +без необходимости перезапуска nginx (1.7.2). +Для этого в блоке должна +быть задана директива . +См. также параметр + директивы . + + + + +weight=число + +То же, что и параметр “weight” +директивы . + + + +max_fails=число + +То же, что и параметр “max_fails” +директивы . + + + +fail_timeout=время + +То же, что и параметр “fail_timeout” +директивы . + + + +slow_start=время + +То же, что и параметр “slow_start” +директивы . + + + +down= + +То же, что и параметр “down” +директивы . + + + +up= + +Параметр, обратный по значению параметру “down” +директивы . + + + +route=строка + +То же, что и параметр “route” +директивы . + + + + +Первые два параметра выбирают объект. +Объектом может быть либо группа серверов, либо отдельный сервер. +Если остальные параметры не указаны, то показывается конфигурация выбранной +группы или сервера. + + + +Например, команда для просмотра конфигурации всей группы +выглядит следующим образом: + +http://127.0.0.1/upstream_conf?upstream=dynamic + + +Для просмотра конфигурации отдельного сервера следует указать его идентификатор: + +http://127.0.0.1/upstream_conf?upstream=dynamic&id=42 + + + + + +Для добавления нового сервера в группу +следует указать его адрес в параметре “server=”. +Если остальные параметры не указаны, то при добавлении сервера +их значения будут установлены по умолчанию (см. директиву ). + + + +Например, команда для добавления нового основного сервера в группу +выглядит следующим образом: + +http://127.0.0.1/upstream_conf?add=&upstream=dynamic&server=127.0.0.1:8080 + + +Добавление нового запасного сервера происходит следующим образом: + +http://127.0.0.1/upstream_conf?add=&upstream=dynamic&backup=&server=127.0.0.1:8080 + + +Добавление нового основного сервера с нестандартными +значениями параметров и с пометкой его как постоянно недоступного +(“down”) происходит следующим образом: + +http://127.0.0.1/upstream_conf?add=&upstream=dynamic&server=127.0.0.1:8080&weight=2&down= + + + + +Для удаления сервера следует указать его идентификатор: + +http://127.0.0.1/upstream_conf?remove=&upstream=dynamic&id=42 + + + + +Пометка существующего сервера как постоянно недоступного +(“down”) происходит следующим образом: + +http://127.0.0.1/upstream_conf?upstream=dynamic&id=42&down= + + +Изменение адреса существующего сервера происходит следующим образом: + +http://127.0.0.1/upstream_conf?upstream=dynamic&id=42&server=192.0.2.3:8123 + + +Изменение других параметров существующего сервера происходит следующим образом: + +http://127.0.0.1/upstream_conf?upstream=dynamic&id=42&max_fails=3&weight=4 + + + + + + +Эта директива доступна как часть +коммерческой подписки. + + + + +