Mercurial > hg > nginx-site
annotate xml/cn/docs/http/ngx_http_upstream_module.xml @ 1419:33e5af4c10d9
Typo fixed in the beginners guide.
author | Yaroslav Zhuravlev <yar@nginx.com> |
---|---|
date | Tue, 17 Feb 2015 13:45:51 +0300 |
parents | ceb8a4e374b7 |
children | ff357b676c2e |
rev | line source |
---|---|
792
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
1 <?xml version="1.0"?> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
2 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
3 <!-- |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
4 Copyright (C) Igor Sysoev |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
5 Copyright (C) Nginx, Inc. |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
6 --> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
7 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
8 <!DOCTYPE module SYSTEM "../../../../dtd/module.dtd"> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
9 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
10 <module name="ngx_http_upstream_module模块" |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
11 link="/cn/docs/http/ngx_http_upstream_module.html" |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
12 lang="cn" |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
13 translator="Weibin Yao" |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
14 rev="1"> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
15 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
16 <section id="summary"> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
17 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
18 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
19 <literal>ngx_http_upstream_module</literal>模块 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
20 允许定义一组服务器。它们可以在指令<link doc="ngx_http_proxy_module.xml" id="proxy_pass"/>、 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
21 <link doc="ngx_http_fastcgi_module.xml" id="fastcgi_pass"/>和 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
22 <link doc="ngx_http_memcached_module.xml" id="memcached_pass"/>中被引用到。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
23 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
24 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
25 </section> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
26 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
27 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
28 <section id="example" name="配置例子"> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
29 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
30 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
31 <example> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
32 upstream <emphasis>backend</emphasis> { |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
33 server backend1.example.com weight=5; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
34 server backend2.example.com:8080; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
35 server unix:/tmp/backend3; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
36 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
37 server backup1.example.com:8080 backup; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
38 server backup2.example.com:8080 backup; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
39 } |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
40 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
41 server { |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
42 location / { |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
43 proxy_pass http://<emphasis>backend</emphasis>; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
44 } |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
45 } |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
46 </example> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
47 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
48 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
49 </section> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
50 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
51 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
52 <section id="directives" name="指令"> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
53 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
54 <directive name="upstream"> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
55 <syntax block="yes"><value>name</value></syntax> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
56 <default/> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
57 <context>http</context> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
58 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
59 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
60 定义一组服务器。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
61 这些服务器可以监听不同的端口。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
62 而且,监听在TCP和UNIX域套接字的服务器可以混用。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
63 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
64 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
65 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
66 例子: |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
67 <example> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
68 upstream backend { |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
69 server backend1.example.com weight=5; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
70 server 127.0.0.1:8080 max_fails=3 fail_timeout=30s; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
71 server unix:/tmp/backend3; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
72 } |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
73 </example> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
74 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
75 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
76 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
77 默认情况下,nginx按加权轮转的方式将请求分发到各服务器。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
78 在上面的例子中,每7个请求会通过以下方式分发: |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
79 5个请求分到<literal>backend1.example.com</literal>, |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
80 一个请求分到第二个服务器,一个请求分到第三个服务器。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
81 与服务器通信的时候,如果出现错误,请求会被传给下一个服务器,直到所有可用的服务器都被尝试过。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
82 如果所有服务器都返回失败,客户端将会得到最后通信的那个服务器的(失败)响应结果。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
83 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
84 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
85 </directive> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
86 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
87 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
88 <directive name="server"> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
89 <syntax><value>address</value> [<value>parameters</value>]</syntax> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
90 <default/> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
91 <context>upstream</context> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
92 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
93 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
94 定义服务器的地址<value>address</value>和其他参数<value>parameters</value>。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
95 地址可以是域名或者IP地址,端口是可选的,或者是指定“<literal>unix:</literal>”前缀的UNIX域套接字的路径。如果没有指定端口,就使用80端口。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
96 如果一个域名解析到多个IP,本质上是定义了多个server。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
97 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
98 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
99 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
100 你可以定义下面的参数: |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
101 <list type="tag"> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
102 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
103 <tag-name><literal>weight</literal>=<value>number</value></tag-name> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
104 <tag-desc> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
105 设定服务器的权重,默认是1。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
106 </tag-desc> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
107 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
108 <tag-name><literal>max_fails</literal>=<value>number</value></tag-name> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
109 <tag-desc> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
110 设定Nginx与服务器通信的尝试失败的次数。在<literal>fail_timeout</literal>参数定义的时间段内,如果失败的次数达到此值,Nginx就认为服务器不可用。在下一个<literal>fail_timeout</literal>时间段,服务器不会再被尝试。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
111 失败的尝试次数默认是1。设为0就会停止统计尝试次数,认为服务器是一直可用的。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
112 你可以通过指令<link doc="ngx_http_proxy_module.xml" id="proxy_next_upstream"/>、 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
113 <link doc="ngx_http_fastcgi_module.xml" id="fastcgi_next_upstream"/>和 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
114 <link doc="ngx_http_memcached_module.xml" id="memcached_next_upstream"/>来配置什么是失败的尝试。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
115 默认配置时,<literal>http_404</literal>状态不被认为是失败的尝试。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
116 </tag-desc> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
117 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
118 <tag-name><literal>fail_timeout</literal>=<value>time</value></tag-name> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
119 <tag-desc> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
120 设定 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
121 <list type="bullet"> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
122 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
123 <listitem> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
124 统计失败尝试次数的时间段。在这段时间中,服务器失败次数达到指定的尝试次数,服务器就被认为不可用。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
125 </listitem> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
126 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
127 <listitem> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
128 服务器被认为不可用的时间段。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
129 </listitem> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
130 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
131 </list> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
132 默认情况下,该超时时间是10秒。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
133 </tag-desc> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
134 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
135 <tag-name><literal>backup</literal></tag-name> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
136 <tag-desc> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
137 标记为备用服务器。当主服务器不可用以后,请求会被传给这些服务器。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
138 </tag-desc> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
139 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
140 <tag-name><literal>down</literal></tag-name> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
141 <tag-desc> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
142 标记服务器永久不可用,可以跟<link id="ip_hash"/>指令一起使用。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
143 </tag-desc> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
144 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
145 </list> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
146 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
147 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
148 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
149 Example: |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
150 <example> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
151 upstream backend { |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
152 server backend1.example.com weight=5; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
153 server 127.0.0.1:8080 max_fails=3 fail_timeout=30s; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
154 server unix:/tmp/backend3; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
155 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
156 server backup1.example.com:8080 backup; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
157 } |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
158 </example> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
159 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
160 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
161 </directive> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
162 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
163 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
164 <directive name="ip_hash"> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
165 <syntax/> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
166 <default/> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
167 <context>upstream</context> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
168 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
169 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
170 指定服务器组的负载均衡方法,请求基于客户端的IP地址在服务器间进行分发。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
171 IPv4地址的前三个字节或者IPv6的整个地址,会被用来作为一个散列key。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
172 这种方法可以确保从同一个客户端过来的请求,会被传给同一台服务器。除了当服务器被认为不可用的时候,这些客户端的请求会被传给其他服务器,而且很有可能也是同一台服务器。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
173 <note> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
174 从1.3.2和1.2.2版本开始支持IPv6地址。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
175 </note> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
176 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
177 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
178 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
179 如果其中一个服务器想暂时移除,应该加上<literal>down</literal>参数。这样可以保留当前客户端IP地址散列分布。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
180 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
181 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
182 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
183 例子: |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
184 <example> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
185 upstream backend { |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
186 ip_hash; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
187 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
188 server backend1.example.com; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
189 server backend2.example.com; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
190 server backend3.example.com <emphasis>down</emphasis>; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
191 server backend4.example.com; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
192 } |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
193 </example> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
194 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
195 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
196 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
197 <note> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
198 从1.3.1和1.2.2版本开始,<literal>ip_hash</literal>的负载均衡方法才支持设置服务器权重值。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
199 </note> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
200 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
201 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
202 </directive> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
203 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
204 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
205 <directive name="keepalive"> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
206 <syntax><value>connections</value></syntax> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
207 <default/> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
208 <context>upstream</context> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
209 <appeared-in>1.1.4</appeared-in> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
210 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
211 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
212 激活对上游服务器的连接进行缓存。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
213 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
214 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
215 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
216 <value>connections</value>参数设置每个worker进程与后端服务器保持连接的最大数量。这些保持的连接会被放入缓存。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
217 如果连接数大于这个值时,最久未使用的连接会被关闭。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
218 <note> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
219 需要注意的是,<literal>keepalive</literal>指令不会限制Nginx进程与上游服务器的连接总数。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
220 新的连接总会按需被创建。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
221 <value>connections</value>参数应该稍微设低一点,以便上游服务器也能处理额外新进来的连接。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
222 </note> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
223 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
224 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
225 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
226 配置memcached上游服务器连接keepalive的例子: |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
227 <example> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
228 upstream memcached_backend { |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
229 server 127.0.0.1:11211; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
230 server 10.0.0.2:11211; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
231 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
232 keepalive 32; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
233 } |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
234 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
235 server { |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
236 ... |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
237 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
238 location /memcached/ { |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
239 set $memcached_key $uri; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
240 memcached_pass memcached_backend; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
241 } |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
242 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
243 } |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
244 </example> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
245 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
246 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
247 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
248 对于HTTP代理,<link doc="ngx_http_proxy_module.xml" id="proxy_http_version"/>指令应该设置为“<literal>1.1</literal>”,同时<header>Connection</header>头的值也应被清空。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
249 <example> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
250 upstream http_backend { |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
251 server 127.0.0.1:8080; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
252 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
253 keepalive 16; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
254 } |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
255 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
256 server { |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
257 ... |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
258 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
259 location /http/ { |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
260 proxy_pass http://http_backend; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
261 proxy_http_version 1.1; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
262 proxy_set_header Connection ""; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
263 ... |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
264 } |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
265 } |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
266 </example> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
267 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
268 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
269 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
270 <note> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
271 另外一种选择是,HTTP/1.0协议的持久连接也可以通过发送<header>Connection: Keep-Alive</header>头来实现。不过不建议这样用。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
272 </note> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
273 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
274 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
275 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
276 对于FastCGI的服务器,需要设置 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
277 <link doc="ngx_http_fastcgi_module.xml" id="fastcgi_keep_conn"/> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
278 指令来让连接keepalive工作: |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
279 <example> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
280 upstream fastcgi_backend { |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
281 server 127.0.0.1:9000; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
282 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
283 keepalive 8; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
284 } |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
285 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
286 server { |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
287 ... |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
288 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
289 location /fastcgi/ { |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
290 fastcgi_pass fastcgi_backend; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
291 fastcgi_keep_conn on; |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
292 ... |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
293 } |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
294 } |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
295 </example> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
296 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
297 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
298 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
299 <note> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
300 当使用的负载均衡方法不是默认的轮转法时,必须在<literal>keepalive</literal> 指令之前配置。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
301 </note> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
302 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
303 <note> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
304 针对SCGI和uwsgi协议,还没有实现其keepalive连接的打算。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
305 </note> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
306 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
307 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
308 </directive> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
309 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
310 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
311 <directive name="least_conn"> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
312 <syntax/> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
313 <default/> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
314 <context>upstream</context> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
315 <appeared-in>1.3.1</appeared-in> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
316 <appeared-in>1.2.2</appeared-in> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
317 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
318 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
319 指定服务器组的负载均衡方法,根据其权重值,将请求发送到活跃连接数最少的那台服务器。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
320 如果这样的服务器有多台,那就采取有权重的轮转法进行尝试。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
321 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
322 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
323 </directive> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
324 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
325 </section> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
326 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
327 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
328 <section id="variables" name="嵌入的变量"> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
329 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
330 <para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
331 <literal>ngx_http_upstream_module</literal>模块支持以下嵌入变量: |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
332 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
333 <list type="tag"> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
334 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
335 <tag-name><var>$upstream_addr</var></tag-name> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
336 <tag-desc> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
337 保存服务器的IP地址和端口或者是UNIX域套接字的路径。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
338 在请求处理过程中,如果有多台服务器被尝试了,它们的地址会被拼接起来,以逗号隔开,比如: |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
339 “<literal>192.168.1.1:80, 192.168.1.2:80, unix:/tmp/sock</literal>”。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
340 如果在服务器之间通过<header>X-Accel-Redirect</header>头或者<link doc="ngx_http_core_module.xml" id="error_page"/>有内部跳转,那么这些服务器组之间会以冒号隔开,比如:“<literal>192.168.1.1:80, 192.168.1.2:80, unix:/tmp/sock : 192.168.10.1:80, 192.168.10.2:80</literal>”。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
341 </tag-desc> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
342 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
343 <tag-name><var>$upstream_response_time</var></tag-name> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
344 <tag-desc> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
345 以毫秒的精度保留服务器的响应时间,(输出)单位是秒。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
346 出现多个响应时,也是以逗号和冒号隔开。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
347 </tag-desc> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
348 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
349 <tag-name><var>$upstream_status</var></tag-name> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
350 <tag-desc> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
351 保存服务器的响应代码。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
352 出现多个响应时,也是以逗号和冒号隔开。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
353 </tag-desc> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
354 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
355 <tag-name><var>$upstream_http_...</var></tag-name> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
356 <tag-desc> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
357 保存服务器的响应头的值。比如<header>Server</header>响应头的值可以通过<var>$upstream_http_server</var>变量来获取。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
358 需要注意的是只有最后一个响应的头会被保留下来。 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
359 </tag-desc> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
360 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
361 </list> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
362 </para> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
363 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
364 </section> |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
365 |
ceb8a4e374b7
Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
366 </module> |