Mercurial > hg > nginx-site
comparison xml/cn/docs/http/ngx_http_limit_req_module.xml @ 792:ceb8a4e374b7
Updated the Chinese documentation.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Tue, 25 Dec 2012 06:34:37 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
791:15f2bab0740d | 792:ceb8a4e374b7 |
---|---|
1 <?xml version="1.0"?> | |
2 | |
3 <!-- | |
4 Copyright (C) Igor Sysoev | |
5 Copyright (C) Nginx, Inc. | |
6 --> | |
7 | |
8 <!DOCTYPE module SYSTEM "../../../../dtd/module.dtd"> | |
9 | |
10 <module name="ngx_http_limit_req_module 模块" | |
11 link="/cn/docs/http/ngx_http_limit_req_module.html" | |
12 lang="cn" | |
13 translator="Weibin Yao" | |
14 rev="1"> | |
15 | |
16 <section id="summary"> | |
17 | |
18 <para> | |
19 <literal>ngx_http_limit_req_module</literal>模块(0.7.21)可以通过定义的 | |
20 键值来限制请求处理的频率。特别的,它可以限制来自单个IP地址的请求处理频率。 | |
21 限制的方法是通过一种“漏桶”的方法——固定每秒处理的请求数,推迟过多的请求处理。 | |
22 </para> | |
23 | |
24 | |
25 </section> | |
26 | |
27 | |
28 <section id="example" name="配置示例"> | |
29 | |
30 <para> | |
31 <example> | |
32 http { | |
33 limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s; | |
34 | |
35 ... | |
36 | |
37 server { | |
38 | |
39 ... | |
40 | |
41 location /search/ { | |
42 limit_req zone=one burst=5; | |
43 } | |
44 </example> | |
45 </para> | |
46 | |
47 </section> | |
48 | |
49 | |
50 <section id="directives" name="指令"> | |
51 | |
52 <directive name="limit_req"> | |
53 <syntax> | |
54 <literal>zone</literal>=<value>name</value> | |
55 [<literal>burst</literal>=<value>number</value>] | |
56 [<literal>nodelay</literal>]</syntax> | |
57 <default/> | |
58 <context>http</context> | |
59 <context>server</context> | |
60 <context>location</context> | |
61 | |
62 <para> | |
63 设置对应的共享内存限制域和允许被处理的最大请求数阈值。 | |
64 如果请求的频率超过了限制域配置的值,请求处理会被延迟,所以 | |
65 所有的请求都是以定义的频率被处理的。 | |
66 超过频率限制的请求会被延迟,直到被延迟的请求数超过了定义的阈值 | |
67 这时,这个请求会被终止,并返回<http-status code="503" text="Service Temporarily Unavailable"/> | |
68 错误。这个阈值的默认值等于0。 | |
69 比如这些指令: | |
70 <example> | |
71 limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s; | |
72 | |
73 server { | |
74 location /search/ { | |
75 limit_req zone=one burst=5; | |
76 } | |
77 </example> | |
78 限制平均每秒不超过一个请求,同时允许超过频率限制的请求数不多于5个。 | |
79 </para> | |
80 | |
81 <para> | |
82 如果不希望超过的请求被延迟,可以用<literal>nodelay</literal>参数: | |
83 <example> | |
84 limit_req zone=one burst=5 nodelay; | |
85 </example> | |
86 </para> | |
87 | |
88 </directive> | |
89 | |
90 | |
91 <directive name="limit_req_log_level"> | |
92 <syntax> | |
93 <literal>info</literal> | | |
94 <literal>notice</literal> | | |
95 <literal>warn</literal> | | |
96 <literal>error</literal></syntax> | |
97 <default>error</default> | |
98 <context>http</context> | |
99 <context>server</context> | |
100 <context>location</context> | |
101 <appeared-in>0.8.18</appeared-in> | |
102 | |
103 <para> | |
104 设置你所希望的日志级别,当服务器因为频率过高拒绝或者延迟处理请求时可以记下相应级别的日志。 | |
105 延迟记录的日志级别比拒绝的低一个级别;比如, | |
106 如果设置“<literal>limit_req_log_level notice</literal>”, | |
107 延迟的日志就是<literal>info</literal>级别。 | |
108 </para> | |
109 | |
110 </directive> | |
111 | |
112 | |
113 <directive name="limit_req_zone"> | |
114 <syntax> | |
115 <value>$variable</value> | |
116 <literal>zone</literal>=<value>name</value>:<value>size</value> | |
117 <literal>rate</literal>=<value>rate</value></syntax> | |
118 <default/> | |
119 <context>http</context> | |
120 | |
121 <para> | |
122 设置一块共享内存限制域的参数,它可以用来保存键值的状态。 | |
123 它特别保存了当前超出请求的数量。 | |
124 键的值就是指定的变量(空值不会被计算)。 | |
125 示例用法: | |
126 <example> | |
127 limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s; | |
128 </example> | |
129 </para> | |
130 | |
131 <para> | |
132 这里,状态被存在名为“one”,最大10M字节的共享内存里面。对于这个限制域来说 | |
133 平均处理的请求频率不能超过每秒一次。 | |
134 </para> | |
135 | |
136 <para> | |
137 键值是客户端的IP地址。 | |
138 如果不使用<var>$remote_addr</var>变量,而用<var>$binary_remote_addr</var>变量, | |
139 可以将每条状态记录的大小减少到64个字节,这样1M的内存可以保存大约1万6千个64字节的记录。 | |
140 如果限制域的存储空间耗尽了,对于后续所有请求,服务器都会返回 | |
141 <http-status code="503" text="Service Temporarily Unavailable"/>错误。 | |
142 </para> | |
143 | |
144 <para> | |
145 请求频率可以设置为每秒几次(r/s)。如果请求的频率不到每秒一次, | |
146 你可以设置每分钟几次(r/m)。比如每秒半次就是30r/m。 | |
147 </para> | |
148 | |
149 </directive> | |
150 | |
151 </section> | |
152 | |
153 </module> |