annotate xml/cn/docs/http/ngx_http_rewrite_module.xml @ 2735:ff357b676c2e

Removed trailing spaces.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 10 Jun 2021 18:27:24 +0300
parents ceb8a4e374b7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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_rewrite_module模块"
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
11 link="/cn/docs/http/ngx_http_rewrite_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="cfsego"
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
14 rev="2">
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_rewrite_module</literal>模块允许正则替换URI,返回页面重定向,和按条件选择配置。
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
20 </para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
21
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
22 <para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
23 <literal>ngx_http_rewrite_module</literal>模块指令按以下顺序处理:
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
24 <list type="bullet">
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
25
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
26 <listitem>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
27 处理在<link doc="ngx_http_core_module.xml" id="server"/>级别中定义的模块指令;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
28 </listitem>
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 <listitem>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
31 为请求查找location;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
32 </listitem>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
33
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
34 <listitem>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
35 处理在选中的<link doc="ngx_http_core_module.xml" id="location"/>中定义的模块指令。如果指令改变了URI,按新的URI查找location。这个循环至多重复<link doc="ngx_http_core_module.xml" id="internal">10次</link>,之后nginx返回错误<http-status code="500" text="Internal Server Error"/>。
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
36 </listitem>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
37
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
38 </list>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
39 </para>
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 </section>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
42
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
43
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
44 <section id="directives" name="指令">
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 <directive name="break">
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
47 <syntax/>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
48 <default/>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
49 <context>server</context>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
50 <context>location</context>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
51 <context>if</context>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
52
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
53 <para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
54 停止处理当前这一轮的<literal>ngx_http_rewrite_module</literal>指令集。
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
55 </para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
56
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
57 <para>
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 <example>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
60 if ($slow) {
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
61 limit_rate 10k;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
62 break;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
63 }
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
64 </example>
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 </directive>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
68
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
69
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
70 <directive name="if">
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
71 <syntax block="yes">(<value>condition</value>)</syntax>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
72 <default/>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
73 <context>server</context>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
74 <context>location</context>
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 计算指定的<value>condition</value>的值。如果为真,执行定义在大括号中的rewrite模块指令,并将<literal>if</literal>指令中的配置指定给请求。<literal>if</literal>指令会从上一层配置中继承配置。
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
78 </para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
79
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
80 <para>
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 <list type="bullet">
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
83
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
84 <listitem>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
85 变量名;如果变量值为空或者是以“<literal>0</literal>”开始的字符串,则条件为假;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
86 </listitem>
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 <listitem>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
89 使用“<literal>=</literal>”和“<literal>!=</literal>”运算符比较变量和字符串;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
90 </listitem>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
91
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
92 <listitem>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
93 使用“<literal>~</literal>”(大小写敏感)和“<literal>~*</literal>”(大小写不敏感)运算符匹配变量和正则表达式。正则表达式可以包含匹配组,匹配结果后续可以使用变量<var>$1</var>..<var>$9</var>引用。如果正则表达式中包含字符“<literal>}</literal>”或者“<literal>;</literal>”,整个表达式应该被包含在单引号或双引号的引用中。
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
94 </listitem>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
95
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
96 <listitem>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
97 使用“<literal>-f</literal>”和“<literal>!-f</literal>”运算符检查文件是否存在;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
98 </listitem>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
99
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
100 <listitem>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
101 使用“<literal>-d</literal>”和“<literal>!-d</literal>”运算符检查目录是否存在;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
102 </listitem>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
103
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
104 <listitem>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
105 使用“<literal>-e</literal>”和“<literal>!-e</literal>”运算符检查文件、目录或符号链接是否存在;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
106 </listitem>
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 <listitem>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
109 使用“<literal>-x</literal>”和“<literal>!-x</literal>”运算符检查可执行文件;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
110 </listitem>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
111
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
112 </list>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
113 </para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
114
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
115 <para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
116 举例:
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
117 <example>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
118 if ($http_user_agent ~ MSIE) {
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
119 rewrite ^(.*)$ /msie/$1 break;
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
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
122 if ($http_cookie ~* "id=([^;]+)(?:;|$)") {
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
123 set $id $1;
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
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
126 if ($request_method = POST) {
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
127 return 405;
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
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
130 if ($slow) {
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
131 limit_rate 10k;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
132 }
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
133
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
134 if ($invalid_referer) {
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
135 return 403;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
136 }
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
137 </example>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
138 <note>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
139 内嵌变量<var>$invalid_referer</var>的值是通过<link doc="ngx_http_referer_module.xml" id="valid_referers"/>指令设置的。
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
140 </note>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
141 </para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
142
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
143 </directive>
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
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
146 <directive name="return">
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
147 <syntax><value>code</value> [<value>text</value>]</syntax>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
148 <syntax><value>code</value> <value>URL</value></syntax>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
149 <syntax><value>URL</value></syntax>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
150 <default/>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
151 <context>server</context>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
152 <context>location</context>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
153 <context>if</context>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
154
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
155 <para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
156 停止处理并返回指定<value>code</value>给客户端。返回非标准的状态码444可以直接关闭连接而不返回响应头。
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
157 </para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
158
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 从0.8.42版开始,可以在指令中指定重定向的URL(状态码为301、302、303和307),或者指定响应体<value>文本</value>(状态码为其它值)。响应体文本或重定向URL中可以包含变量。作为一种特殊情况,重定向URL可以简化为当前server的本地URI,那么完整的重定向URL将按照请求协议(<var>$scheme</var>)、<link doc="ngx_http_core_module.xml" id="server_name_in_redirect"/>指令和<link doc="ngx_http_core_module.xml" id="port_in_redirect"/>指令的配置进行补全。
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
161 </para>
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 <para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
164 另外,状态码为302的临时重定向使用的<value>URL</value>可以作为指令的唯一参数。该参数应该以“<literal>http://</literal>”、“<literal>https://</literal>”或者“<literal>https://</literal>”开始。<value>URL</value>中可以包含变量。
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
165 </para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
166
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
167 <para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
168 <note>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
169 0.7.51版本以前只能返回下面状态码:
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
170 204、400、402 — 406、408、410、411、413、416 和 500 — 504。
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
171 </note>
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.1.16和1.0.13版,状态码307才被认为是一种重定向。
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 </directive>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
179
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
180
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
181 <directive name="rewrite">
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
182 <syntax>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
183 <value>regex</value>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
184 <value>replacement</value>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
185 [<value>flag</value>]</syntax>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
186 <default/>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
187 <context>server</context>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
188 <context>location</context>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
189 <context>if</context>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
190
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
191 <para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
192 如果指定的正则表达式能匹配URI,此URI将被<value>replacement</value>参数定义的字符串改写。<literal>rewrite</literal>指令按其在配置文件中出现的顺序执行。flag可以终止后续指令的执行。如果replacement的字符串以“<literal>http://</literal>”或“<literal>https://</literal>”开头,nginx将结束执行过程,并返回给客户端一个重定向。
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
193 </para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
194
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
195 <para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
196 可选的<value>flag</value>参数可以是其中之一:
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
197 <list type="tag">
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
198
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
199 <tag-name><literal>last</literal></tag-name>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
200 <tag-desc>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
201 停止执行当前这一轮的<literal>ngx_http_rewrite_module</literal>指令集,然后查找匹配改变后URI的新location;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
202 </tag-desc>
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 <tag-name><literal>break</literal></tag-name>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
205 <tag-desc>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
206 停止执行当前这一轮的<literal>ngx_http_rewrite_module</literal>指令集;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
207 </tag-desc>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
208
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
209 <tag-name><literal>redirect</literal></tag-name>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
210 <tag-desc>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
211 在replacement字符串未以“<literal>http://</literal>”或“<literal>https://</literal>”开头时,使用返回状态码为302的临时重定向;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
212 </tag-desc>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
213
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
214 <tag-name><literal>permanent</literal></tag-name>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
215 <tag-desc>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
216 返回状态码为301的永久重定向。
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
217 </tag-desc>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
218
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
219 </list>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
220 完整的重定向URL将按照请求协议(<var>$scheme</var>)、<link doc="ngx_http_core_module.xml" id="server_name_in_redirect"/>指令和<link doc="ngx_http_core_module.xml" id="port_in_redirect"/>指令的配置进行补全。
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
221 </para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
222
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 <example>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
226 server {
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
227 ...
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
228 rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
229 rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra last;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
230 return 403;
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 }
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
233 </example>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
234 </para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
235
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
236 <para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
237 但是当上述指令写在“<literal>/download/</literal>”的location中时,应使用标志<literal>break</literal>代替<literal>last</literal>,否则nginx会重复10轮循环,然后返回错误500:
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
238 <example>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
239 location /download/ {
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
240 rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 break;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
241 rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra break;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
242 return 403;
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 如果<value>replacement</value>字符串包括新的请求参数,以往的请求参数会添加到新参数后面。如果不希望这样,在replacement字符串末尾加一个问号“?”,就可以避免,比如:
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 rewrite ^/users/(.*)$ /show?user=$1? last;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
251 </example>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
252 </para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
253
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
254 <para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
255 如果正则表达式中包含字符“<literal>}</literal>”或者“<literal>;</literal>”,整个表达式应该被包含在单引号或双引号的引用中。
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
256 </para>
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 </directive>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
259
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
260
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
261 <directive name="rewrite_log">
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
262 <syntax><literal>on</literal> | <literal>off</literal></syntax>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
263 <default>off</default>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
264 <context>http</context>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
265 <context>server</context>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
266 <context>location</context>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
267 <context>if</context>
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 开启或者关闭将<literal>ngx_http_rewrite_module</literal>模块指令的处理日志以<literal>notice</literal>级别记录到错误日志中。
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
271 </para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
272
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
273 </directive>
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
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
276 <directive name="set">
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
277 <syntax><value>variable</value> <value>value</value></syntax>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
278 <default/>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
279 <context>server</context>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
280 <context>location</context>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
281 <context>if</context>
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 <para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
284 为指定变量<value>variable</value>设置变量值<value>value</value>。<value>value</value>可以包含文本、变量或者它们的组合。
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
285 </para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
286
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
287 </directive>
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
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
290 <directive name="uninitialized_variable_warn">
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
291 <syntax><literal>on</literal> | <literal>off</literal></syntax>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
292 <default>on</default>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
293 <context>http</context>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
294 <context>server</context>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
295 <context>location</context>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
296 <context>if</context>
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 控制是否记录变量未初始化的警告到日志。
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
300 </para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
301
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
302 </directive>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
303
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
304 </section>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
305
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
306
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
307 <section id="internals" name="内部实现">
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
308
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
309 <para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
310 <literal>ngx_http_rewrite_module</literal>模块的指令在解析配置阶段被编译成nginx内部指令。这些内部指令在处理请求时被解释执行。而解释器是一个简单的堆栈机器。
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
311 </para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
312
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
313 <para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
314 比如,下面指令
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
315 <example>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
316 location /download/ {
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
317 if ($forbidden) {
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
318 return 403;
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 if ($slow) {
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
322 limit_rate 10k;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
323 }
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 rewrite ^/(download/.*)/media/(.*)\..*$ /$1/mp3/$2.mp3 break;
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 </example>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
328 将被翻译成下面这些指令:
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
329 <example>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
330 variable $forbidden
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
331 check against zero
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
332 return 403
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
333 end of code
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
334 variable $slow
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
335 check against zero
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
336 match of regular expression
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
337 copy "/"
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
338 copy $1
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
339 copy "/mp3/"
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
340 copy $2
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
341 copy ".mp3"
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
342 end of regular expression
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
343 end of code
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
344 </example>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
345 </para>
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 <para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
348 请注意没有对应上面的<link doc="ngx_http_core_module.xml" id="limit_rate"/>指令的内部指令,因为这个指令与<literal>ngx_http_rewrite_module</literal>模块无关。nginx会为这个<link id="if"/>块单独创建一个配置,包含<literal>limit_rate</literal>等于10k。如果条件为真,nginx将把这个配置指派给请求。
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
349 </para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
350
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
351 <para>
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 <example>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
354 rewrite ^/(download/.*)/media/(.*)\..*$ /$1/mp3/$2.mp3 break;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
355 </example>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
356 可以通过将正则表达式中的第一个斜线“/”放入圆括号,来实现节约一个内部指令:
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
357 <example>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
358 rewrite ^(<emphasis>/</emphasis>download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 break;
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
359 </example>
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 <example>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
362 match of regular expression
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
363 copy $1
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
364 copy "/mp3/"
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
365 copy $2
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
366 copy ".mp3"
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
367 end of regular expression
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
368 end of code
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
369 </example>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
370 </para>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
371
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
372 </section>
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
373
ceb8a4e374b7 Updated the Chinese documentation.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
374 </module>