Mercurial > hg > nginx-site
comparison xml/en/docs/http/ngx_http_upstream_module.xml @ 316:1fb1c077658b
Documented the following directives: "keepalive", "proxy_http_version",
and "fastcgi_keep_conn".
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Fri, 13 Jan 2012 18:10:34 +0000 |
parents | 34246e706f48 |
children | 4f907cde0382 |
comparison
equal
deleted
inserted
replaced
315:e00f8f8c0486 | 316:1fb1c077658b |
---|---|
77 server backend2.example.com; | 77 server backend2.example.com; |
78 server backend3.example.com <emphasis>down</emphasis>; | 78 server backend3.example.com <emphasis>down</emphasis>; |
79 server backend4.example.com; | 79 server backend4.example.com; |
80 } | 80 } |
81 </example> | 81 </example> |
82 </para> | |
83 | |
84 </directive> | |
85 | |
86 | |
87 <directive name="keepalive"> | |
88 <syntax><value>connections</value></syntax> | |
89 <default/> | |
90 <context>upstream</context> | |
91 <appeared-in>1.1.4</appeared-in> | |
92 | |
93 <para> | |
94 Activates cache of connections to upstream servers. | |
95 </para> | |
96 | |
97 <para> | |
98 The <value>connections</value> parameter sets the maximum number of | |
99 keepalive connections to upstream servers that are retained in | |
100 the cache per one worker process. | |
101 If there are more idle connections to retain to an upstream than | |
102 are specified by this number, the least recently used ones will | |
103 be closed. | |
104 <note> | |
105 It should be noted that <literal>keepalive</literal> directive | |
106 does not limit the total number of connections that nginx worker | |
107 process can open to upstream servers. | |
108 The new connections are always created on demand. | |
109 The <value>connections</value> parameter should be set low enough | |
110 to allow upstream servers to process additional new incoming | |
111 connections as well. | |
112 </note> | |
113 </para> | |
114 | |
115 <para> | |
116 Example configuration of memcached upstream with keepalive connections: | |
117 <example> | |
118 upstream memcached_backend { | |
119 server 127.0.0.1:11211; | |
120 server 10.0.0.2:11211; | |
121 | |
122 keepalive 32; | |
123 } | |
124 | |
125 server { | |
126 ... | |
127 | |
128 location /memcached/ { | |
129 set $memcached_key $uri; | |
130 memcached_pass memcached_backend; | |
131 } | |
132 | |
133 } | |
134 </example> | |
135 </para> | |
136 | |
137 <para> | |
138 For HTTP, the <link doc="ngx_http_proxy_module.xml" id="proxy_http_version"/> | |
139 directive should be set to “<literal>1.1</literal>” | |
140 and the <header>Connection</header> header field should be cleared: | |
141 <example> | |
142 upstream http_backend { | |
143 server 127.0.0.1:8080; | |
144 | |
145 keepalive 16; | |
146 } | |
147 | |
148 server { | |
149 ... | |
150 | |
151 location /http/ { | |
152 proxy_pass http://http_backend; | |
153 proxy_http_version 1.1; | |
154 proxy_set_header Connection ""; | |
155 ... | |
156 } | |
157 } | |
158 </example> | |
159 </para> | |
160 | |
161 <para> | |
162 <note> | |
163 Alternatively, HTTP/1.0 persistent connections can be used by passing the | |
164 <header>Connection: Keep-Alive</header> header field to an upstream server, | |
165 though this is not recommended. | |
166 </note> | |
167 </para> | |
168 | |
169 <para> | |
170 For FastCGI servers, it is required to set | |
171 <link doc="ngx_http_fastcgi_module.xml" id="fastcgi_keep_conn"/> | |
172 for keepalive connections to work: | |
173 <example> | |
174 upstream fastcgi_backend { | |
175 server 127.0.0.1:9000; | |
176 | |
177 keepalive 8; | |
178 } | |
179 | |
180 server { | |
181 ... | |
182 | |
183 location /fastcgi/ { | |
184 fastcgi_pass fastcgi_backend; | |
185 fastcgi_keep_conn on; | |
186 ... | |
187 } | |
188 } | |
189 </example> | |
190 </para> | |
191 | |
192 <para> | |
193 <note> | |
194 When using load balancer modules other than the default | |
195 round-robin, it is necessary to activate them before | |
196 the <literal>keepalive</literal> directive. | |
197 </note> | |
198 | |
199 <note> | |
200 SCGI and uwsgi protocols do not define keepalive connections. | |
201 </note> | |
82 </para> | 202 </para> |
83 | 203 |
84 </directive> | 204 </directive> |
85 | 205 |
86 | 206 |