Mercurial > hg > nginx-site
comparison xml/cn/docs/http/ngx_http_log_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_log_module模块" | |
11 link="/cn/docs/http/ngx_http_log_module.html" | |
12 lang="cn" | |
13 translator="nigelzeng" | |
14 rev="3"> | |
15 | |
16 <section id="summary"> | |
17 | |
18 <para> | |
19 <literal>ngx_http_log_module</literal>模块按指定的格式写访问日志。 | |
20 </para> | |
21 | |
22 <para> | |
23 请求在处理结束时,会按请求路径的配置上下文记访问日志。 | |
24 如果在请求处理期间产生了<link doc="ngx_http_core_module.xml" id="internal">内部跳转</link>, | |
25 请求结束时的路径可能不同于原始的请求路径。 | |
26 </para> | |
27 | |
28 </section> | |
29 | |
30 | |
31 <section id="example" name="配置实例"> | |
32 | |
33 <para> | |
34 <example> | |
35 log_format gzip '$remote_addr - $remote_user [$time_local] ' | |
36 '"$request" $status $bytes_sent ' | |
37 '"$http_referer" "$http_user_agent" "$gzip_ratio"'; | |
38 | |
39 access_log /spool/logs/nginx-access.log gzip buffer=32k; | |
40 </example> | |
41 </para> | |
42 | |
43 </section> | |
44 | |
45 | |
46 <section id="directives" name="指令"> | |
47 | |
48 <directive name="access_log"> | |
49 <syntax> | |
50 <value>path</value> | |
51 [<value>format</value> | |
52 [<literal>buffer</literal>=<value>size</value>]]</syntax> | |
53 <syntax><literal>off</literal></syntax> | |
54 <default>logs/access.log combined</default> | |
55 <context>http</context> | |
56 <context>server</context> | |
57 <context>location</context> | |
58 <context>if in location</context> | |
59 <context>limit_except</context> | |
60 | |
61 <para> | |
62 为访问日志设置路径,格式和缓冲区大小(nginx访问日志支持缓存)。 | |
63 在同一个配置层级里可以指定多个日志。 | |
64 特定值<literal>off</literal>会取消当前配置层级里的所有<literal>access_log</literal>指令。 | |
65 如果没有指定日志格式则会使用预定义的“<literal>combined</literal>”格式。 | |
66 </para> | |
67 | |
68 <para> | |
69 缓冲区的大小不能超过磁盘文件原子性写入的大小。 | |
70 对于FreeBSD来说缓冲区大小是无限制的。 | |
71 </para> | |
72 | |
73 <para> | |
74 日志文件的路径可以包含变量(0.7.6+), | |
75 但此类日志存在一些限制: | |
76 <list type="bullet"> | |
77 | |
78 <listitem> | |
79 工作进程使用的<link doc="../ngx_core_module.xml" id="user"/> | |
80 应拥有在目录里创建文件的权限; | |
81 </listitem> | |
82 | |
83 <listitem> | |
84 写缓冲无效; | |
85 </listitem> | |
86 | |
87 <listitem> | |
88 每条日志写入都会打开和关闭文件。然而,频繁使用的文件描述符可以存储在 | |
89 <link id="open_log_file_cache">缓存</link>中, | |
90 在<link id="open_log_file_cache"/>指令的<literal>valid</literal>参数指定的时间里, | |
91 写操作能持续写到旧文件。 | |
92 </listitem> | |
93 | |
94 <listitem> | |
95 每次日志写入的操作都会检查请求的 | |
96 <link doc="ngx_http_core_module.xml" id="root">根目录</link>是否存在, | |
97 如果不存在则日志不会被创建。 | |
98 因此在一个层级里同时指定<link doc="ngx_http_core_module.xml" id="root"/> | |
99 和<literal>access_log</literal>是一个不错的想法: | |
100 <example> | |
101 server { | |
102 root /spool/vhost/data/$host; | |
103 access_log /spool/vhost/logs/$host; | |
104 ... | |
105 </example> | |
106 </listitem> | |
107 | |
108 </list> | |
109 </para> | |
110 | |
111 </directive> | |
112 | |
113 | |
114 <directive name="log_format"> | |
115 <syntax> | |
116 <value>name</value> | |
117 <value>string</value> ...</syntax> | |
118 <default>combined "..."</default> | |
119 <context>http</context> | |
120 | |
121 <para> | |
122 指定日志的格式。 | |
123 </para> | |
124 | |
125 <para> | |
126 日志格式允许包含普通变量和只在日志写入时存在的变量: | |
127 <list type="tag"> | |
128 | |
129 <tag-name><var>$body_bytes_sent</var></tag-name> | |
130 <tag-desc> | |
131 发送给客户端的字节数,不包括响应头的大小; | |
132 该变量与Apache模块<literal>mod_log_config</literal>里的“<literal>%B</literal>”参数兼容。 | |
133 </tag-desc> | |
134 | |
135 <tag-name><var>$bytes_sent</var></tag-name> | |
136 <tag-desc> | |
137 发送给客户端的总字节数。 | |
138 </tag-desc> | |
139 | |
140 <tag-name><var>$connection</var></tag-name> | |
141 <tag-desc> | |
142 连接的序列号。 | |
143 </tag-desc> | |
144 | |
145 <tag-name><var>$connection_requests</var></tag-name> | |
146 <tag-desc> | |
147 当前通过一个连接获得的请求数量。 | |
148 </tag-desc> | |
149 | |
150 <tag-name><var>$msec</var></tag-name> | |
151 <tag-desc> | |
152 日志写入时间。单位为秒,精度是毫秒。 | |
153 </tag-desc> | |
154 | |
155 <tag-name><var>$pipe</var></tag-name> | |
156 <tag-desc> | |
157 如果请求是通过HTTP流水线(pipelined)发送,pipe值为“<literal>p</literal>”,否则为“<literal>.</literal>”。 | |
158 </tag-desc> | |
159 | |
160 <tag-name><var>$request_length</var></tag-name> | |
161 <tag-desc> | |
162 请求的长度(包括请求行,请求头和请求正文)。 | |
163 </tag-desc> | |
164 | |
165 <tag-name><var>$request_time</var></tag-name> | |
166 <tag-desc> | |
167 请求处理时间,单位为秒,精度毫秒; | |
168 从读入客户端的第一个字节开始,直到把最后一个字符发送给客户端后进行日志写入为止。 | |
169 </tag-desc> | |
170 | |
171 <tag-name><var>$status</var></tag-name> | |
172 <tag-desc> | |
173 响应状态。 | |
174 </tag-desc> | |
175 | |
176 <tag-name><var>$time_iso8601</var></tag-name> | |
177 <tag-desc> | |
178 ISO8601标准格式下的本地时间。 | |
179 </tag-desc> | |
180 | |
181 <tag-name><var>$time_local</var></tag-name> | |
182 <tag-desc> | |
183 通用日志格式下的本地时间。 | |
184 </tag-desc> | |
185 | |
186 </list> | |
187 </para> | |
188 | |
189 <para> | |
190 发送给客户端的响应头拥有“<literal>sent_http_</literal>”前缀。 | |
191 比如<var>$sent_http_content_range</var>。 | |
192 </para> | |
193 | |
194 <para> | |
195 配置始终包含预先定义的“<literal>combined</literal>”日志格式: | |
196 <example> | |
197 log_format combined '$remote_addr - $remote_user [$time_local] ' | |
198 '"$request" $status $body_bytes_sent ' | |
199 '"$http_referer" "$http_user_agent"'; | |
200 </example> | |
201 </para> | |
202 | |
203 </directive> | |
204 | |
205 | |
206 <directive name="open_log_file_cache"> | |
207 | |
208 <syntax> | |
209 <literal>max</literal>=<value>N</value> | |
210 [<literal>inactive</literal>=<value>time</value>] | |
211 [<literal>min_uses</literal>=<value>N</value>] | |
212 [<literal>valid</literal>=<value>time</value>]</syntax> | |
213 <syntax><literal>off</literal></syntax> | |
214 <default>off</default> | |
215 <context>http</context> | |
216 <context>server</context> | |
217 <context>location</context> | |
218 | |
219 <para> | |
220 定义一个缓存,用来存储频繁使用的文件名中包含变量的日志文件描述符。 | |
221 该指令包含以下参数: | |
222 <list type="tag"> | |
223 | |
224 <tag-name><literal>max</literal></tag-name> | |
225 <tag-desc> | |
226 设置缓存中描述符的最大数量;如果缓存被占满,最近最少使用(LRU)的描述符将被关闭。 | |
227 </tag-desc> | |
228 | |
229 <tag-name><literal>inactive</literal></tag-name> | |
230 <tag-desc> | |
231 设置缓存文件描述符在多长时间内没有被访问就关闭; | |
232 默认为10秒。 | |
233 </tag-desc> | |
234 | |
235 <tag-name><literal>min_uses</literal></tag-name> | |
236 <tag-desc> | |
237 设置在<literal>inactive</literal>参数指定的时间里, | |
238 最少访问多少次才能使文件描述符保留在缓存中;默认为1。 | |
239 </tag-desc> | |
240 | |
241 <tag-name><literal>valid</literal></tag-name> | |
242 <tag-desc> | |
243 设置一段用于检查超时后文件是否仍以同样名字存在的时间; | |
244 默认为60秒。 | |
245 </tag-desc> | |
246 | |
247 <tag-name><literal>off</literal></tag-name> | |
248 <tag-desc> | |
249 禁用缓存。 | |
250 </tag-desc> | |
251 | |
252 </list> | |
253 </para> | |
254 | |
255 <para> | |
256 使用实例: | |
257 <example> | |
258 open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2; | |
259 </example> | |
260 </para> | |
261 | |
262 </directive> | |
263 | |
264 </section> | |
265 | |
266 </module> |