annotate xml/en/docs/http/ngx_http_rewrite_module.xml @ 392:5fd99d37a3e6

English translation of ngx_http_rewrite_module.
author Ruslan Ermilov <ru@nginx.com>
date Fri, 03 Feb 2012 12:42:07 +0000
parents
children 0491cb7e874b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1 <?xml version="1.0"?>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
2
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
3 <!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
4
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
5 <module name="Module ngx_http_rewrite_module"
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
6 link="/en/docs/http/ngx_http_rewrite_module.html"
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
7 lang="en">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
8
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
9 <section id="summary">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
10
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
11 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
12 The <literal>ngx_http_rewrite_module</literal> module allows to
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
13 change URIs using regular expressions, return redirects, and
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
14 conditionally select configurations.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
15 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
16
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
17 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
18 The <literal>ngx_http_rewrite_module</literal> module directives are
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
19 processed in the following order:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
20 <list type="bullet">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
21
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
22 <listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
23 the directives of this module specified on the
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
24 <link doc="ngx_http_core_module.xml" id="server"/> level are processed;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
25 </listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
26
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
27 <listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
28 a location for a request is searched;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
29 </listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
30
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
31 <listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
32 the directives of this module specified in the selected
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
33 <link doc="ngx_http_core_module.xml" id="location"/> are processed,
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
34 and if they changed a URI, a new location is searched for the new URI.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
35 This cycle may be repeated up to 10 times after which the error
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
36 <http-status code="500" text="Internal Server Error"/> is returned.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
37 </listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
38
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
39 </list>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
40 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
41
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
42 </section>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
43
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
44
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
45 <section id="directives" name="Directives">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
46
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
47 <directive name="break">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
48 <syntax/>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
49 <default/>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
50 <context>server</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
51 <context>location</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
52 <context>if</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
53
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
54 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
55 Stops processing the current set of
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
56 <literal>ngx_http_rewrite_module</literal> directives.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
57 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
58
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
59 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
60 Example:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
61 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
62 if ($slow) {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
63 limit_rate 10k;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
64 break;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
65 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
66 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
67 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
68
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
69 </directive>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
70
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
71
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
72 <directive name="if">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
73 <syntax block="yes">(<value>condition</value>)</syntax>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
74 <default/>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
75 <context>server</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
76 <context>location</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
77
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
78 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
79 The specified <value>condition</value> is evaluated.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
80 If true, the directives of this module specified inside the braces are
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
81 executed, and a request is assigned the configuration inside the
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
82 <literal>if</literal> directive.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
83 Configurations inside the <literal>if</literal> directives are
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
84 inherited from the previous configuration level.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
85 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
86
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
87 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
88 A condition may be any of the following:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
89 <list type="bullet">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
90
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
91 <listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
92 a variable name; false if the value of a variable is an empty string
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
93 or any string starting with “<literal>0</literal>”;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
94 </listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
95
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
96 <listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
97 comparing a variable with a string using the
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
98 “<literal>=</literal>” and “<literal>!=</literal>” operators;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
99 </listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
100
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
101 <listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
102 matching a variable against a regular expression using the
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
103 “<literal>~</literal>” (for case-sensitive matching) and
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
104 “<literal>~*</literal>” (for case-insensitive matching) operators.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
105 Regular expressions can contain captures that are made available for
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
106 later reuse in the <var>$1</var>..<var>$9</var> variables.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
107 Negative operators “<literal>!~</literal>” and “<literal>!~*</literal>”
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
108 are also available.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
109 If a regular expression includes the characters “<literal>}</literal>”
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
110 or “<literal>;</literal>”, the whole expressions should be enclosed
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
111 in single or double quotes.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
112 </listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
113
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
114 <listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
115 checking a file existence with the “<literal>-f</literal>” and
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
116 “<literal>!-f</literal>” operators;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
117 </listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
118
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
119 <listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
120 checking a directory existence with the “<literal>-d</literal>” and
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
121 “<literal>!-d</literal>” operators;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
122 </listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
123
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
124 <listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
125 checking a file, directory, or symbolic link existence with the
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
126 “<literal>-e</literal>” and “<literal>!-e</literal>” operators;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
127 </listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
128
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
129 <listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
130 checking for an executable file with operators “<literal>-x</literal>”
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
131 and “<literal>!-x</literal>” operators.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
132 </listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
133
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
134 </list>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
135 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
136
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
137 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
138 Examples:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
139 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
140 if ($http_user_agent ~ MSIE) {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
141 rewrite ^(.*)$ /msie/$1 break;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
142 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
143
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
144 if ($http_cookie ~* "id=([^;]+)(?:;|$)") {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
145 set $id $1;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
146 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
147
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
148 if ($request_method = POST) {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
149 return 405;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
150 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
151
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
152 if ($slow) {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
153 limit_rate 10k;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
154 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
155
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
156 if ($invalid_referer) {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
157 return 403;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
158 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
159 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
160 <note>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
161 A value of the embedded variable <var>$invalid_referer</var> is set by the
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
162 <link doc="ngx_http_referer_module.xml" id="valid_referers"/> directive.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
163 </note>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
164 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
165
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
166 </directive>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
167
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
168
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
169 <directive name="return">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
170 <syntax><value>code</value></syntax>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
171 <default/>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
172 <context>server</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
173 <context>location</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
174 <context>if</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
175
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
176 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
177 Stops processing and returns the specified <value>code</value> to a client.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
178 The following codes can be returned: 204, 400,
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
179 402 — 406, 408, 410, 411, 413, 416 и 500 — 504.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
180 In addition, the non-standard code 444 closes a connection without sending
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
181 a response header.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
182 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
183
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
184 </directive>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
185
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
186
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
187 <directive name="rewrite">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
188 <syntax>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
189 <value>regex</value>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
190 <value>replacement</value>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
191 [<value>flag</value>]</syntax>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
192 <default/>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
193 <context>server</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
194 <context>location</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
195 <context>if</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
196
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
197 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
198 If the specified regular expression matches a URI, the URI is changed
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
199 as specified in the <value>replacement</value> string.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
200 The <literal>rewrite</literal> directives are executed sequentially
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
201 in order of their appearance in the configuration file.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
202 Flags make it possible to terminate further processing of directives.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
203 If a replacement string starts with “<literal>http://</literal>”
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
204 or “<literal>https://</literal>”, the processing stops and a
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
205 redirect is returned to a client.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
206 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
207
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
208 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
209 An optional <value>flag</value> parameter can be one of:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
210 <list type="tag">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
211
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
212 <tag-name><literal>last</literal></tag-name>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
213 <tag-desc>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
214 stops processing the current set of
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
215 <literal>ngx_http_rewrite_module</literal> directives
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
216 followed by a search for a new location matching the changed URI;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
217 </tag-desc>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
218
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
219 <tag-name><literal>break</literal></tag-name>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
220 <tag-desc>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
221 stops processing the current set of
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
222 <literal>ngx_http_rewrite_module</literal> directives;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
223 </tag-desc>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
224
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
225 <tag-name><literal>redirect</literal></tag-name>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
226 <tag-desc>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
227 returns a temporary redirect with the code 302;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
228 used if a replacement string does not start with
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
229 “<literal>http://</literal>” or “<literal>https://</literal>”;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
230 </tag-desc>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
231
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
232 <tag-name><literal>permanent</literal></tag-name>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
233 <tag-desc>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
234 returns a permanent redirect with the code 301.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
235 </tag-desc>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
236
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
237 </list>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
238 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
239
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
240 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
241 Example:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
242 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
243 server {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
244 ...
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
245 rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
246 rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra last;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
247 return 403;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
248 ...
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
249 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
250 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
251 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
252
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
253 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
254 But if these directives are put inside the “<literal>/download/</literal>”
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
255 location, the <literal>last</literal> flag should be replaced by
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
256 <literal>break</literal>, otherwise nginx will make 10 cycles and
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
257 return the error 500:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
258 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
259 location /download/ {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
260 rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 break;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
261 rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra break;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
262 return 403;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
263 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
264 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
265 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
266
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
267 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
268 If a <value>replacement</value> string includes the new request arguments,
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
269 the previous request arguments are appended after them.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
270 If this is undesired, putting a question mark at the end of a replacement
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
271 string avoids having them appended, for example:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
272 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
273 rewrite ^/users/(.*)$ /show?user=$1? last;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
274 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
275 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
276
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
277 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
278 If a regular expression includes the characters “<literal>}</literal>”
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
279 or “<literal>;</literal>”, the whole expressions should be enclosed
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
280 in single or double quotes.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
281 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
282
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
283 </directive>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
284
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
285
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
286 <directive name="set">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
287 <syntax><value>variable</value> <value>value</value></syntax>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
288 <default/>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
289 <context>server</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
290 <context>location</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
291 <context>if</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
292
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
293 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
294 Sets a <value>value</value> for the specified <value>variable</value>.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
295 A <value>value</value> can contain text, variables, and their combination.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
296 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
297
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
298 </directive>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
299
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
300
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
301 <directive name="uninitialized_variable_warn">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
302 <syntax><literal>on</literal> | <literal>off</literal></syntax>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
303 <default>on</default>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
304 <context>http</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
305 <context>server</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
306 <context>location</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
307 <context>if</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
308
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
309 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
310 Controls whether warnings about uninitialized variables are logged.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
311 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
312
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
313 </directive>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
314
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
315 </section>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
316
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
317
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
318 <section id="internals" name="Internal Implementation">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
319
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
320 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
321 The <literal>ngx_http_rewrite_module</literal> module directives
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
322 are compiled during the configuration stage into internal instructions
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
323 that are interpreted during request processing.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
324 An interpreter is a simple virtual stack machine.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
325 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
326
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
327 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
328 For example, the directives
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
329 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
330 location /download/ {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
331 if ($forbidden) {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
332 return 403;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
333 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
334
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
335 if ($slow) {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
336 limit_rate 10k;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
337 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
338
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
339 rewrite ^/(download/.*)/media/(.*)\..*$ /$1/mp3/$2.mp3 break;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
340 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
341 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
342 will be translated into these instructions:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
343 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
344 variable $forbidden
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
345 check against zero
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
346 return 403
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
347 end of code
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
348 variable $slow
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
349 check against zero
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
350 match of regular expression
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
351 copy "/"
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
352 copy $1
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
353 copy "/mp3/"
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
354 copy $2
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
355 copy ".mp3"
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
356 end of regular expression
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
357 end of code
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
358 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
359 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
360
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
361 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
362 Note that there are no instructions for the
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
363 <link doc="ngx_http_core_module.xml" id="limit_rate"/>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
364 directive above as it is unrelated to the
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
365 <literal>ngx_http_rewrite_module</literal> module.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
366 A separate configuration is created for the <link id="if"/> block.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
367 If the condition holds true, a request is assigned this configuration
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
368 where <literal>limit_rate</literal> equals to 10k.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
369 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
370
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
371 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
372 The directive
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
373 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
374 rewrite ^/(download/.*)/media/(.*)\..*$ /$1/mp3/$2.mp3 break;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
375 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
376 can be made smaller by one instruction if the first slash in the regular expression
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
377 is put inside the parentheses:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
378 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
379 rewrite ^(<emphasis>/</emphasis>download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 break;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
380 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
381 The corresponding instructions will then look like this:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
382 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
383 match of regular expression
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
384 copy $1
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
385 copy "/mp3/"
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
386 copy $2
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
387 copy ".mp3"
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
388 end of regular expression
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
389 end of code
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
390 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
391 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
393 </section>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
394
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
395 </module>