Mercurial > hg > nginx-site
comparison xml/en/docs/http/request_processing.xml @ 271:4c6d2c614d2c
Cleaned up XML tag mess:
- all of <parameter> and <code>, and some of <dirname>, <value>,
and <command> were replaced by <literal>;
- the rest of <dirname> were replaced by links;
- <argument> were replaced by <value>;
- <value> is now rendered in HTML in italic;
- <literal> and <path> can now contain <value>.
Cleaned up terminology mess:
- directives take "parameters".
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Fri, 23 Dec 2011 17:29:59 +0000 |
parents | 682163f2b298 |
children | 6135f3c95bf6 |
comparison
equal
deleted
inserted
replaced
270:945d7299c26c | 271:4c6d2c614d2c |
---|---|
42 or the request does not contain this line at all, | 42 or the request does not contain this line at all, |
43 then nginx will route the request to the default server. | 43 then nginx will route the request to the default server. |
44 In the configuration above, the default server is the first | 44 In the configuration above, the default server is the first |
45 one—which is nginx’s standard default behaviour. | 45 one—which is nginx’s standard default behaviour. |
46 If you do not want the first server listed to be the default server, | 46 If you do not want the first server listed to be the default server, |
47 you may set it explicitly with the <dirname>default_server</dirname> parameter | 47 you may set it explicitly with the <literal>default_server</literal> parameter |
48 in the <dirname>listen</dirname> directive: | 48 in the <link doc="ngx_http_core_module.xml" id="listen"/> directive: |
49 | 49 |
50 <programlisting> | 50 <programlisting> |
51 server { | 51 server { |
52 listen 80 <b>default_server</b>; | 52 listen 80 <b>default_server</b>; |
53 server_name nginx.net www.nginx.net; | 53 server_name nginx.net www.nginx.net; |
54 ... | 54 ... |
55 } | 55 } |
56 </programlisting> | 56 </programlisting> |
57 | 57 |
58 <note> | 58 <note> |
59 The <dirname>default_server</dirname> parameter has been available since | 59 The <literal>default_server</literal> parameter has been available since |
60 version 0.8.21. | 60 version 0.8.21. |
61 In earlier versions the <dirname>default</dirname> parameter should be used | 61 In earlier versions the <literal>default</literal> parameter should be used |
62 instead. | 62 instead. |
63 </note> | 63 </note> |
64 | 64 |
65 Note that the default server is a property of the listen port | 65 Note that the default server is a property of the listen port |
66 and not of the server name. More about this later. | 66 and not of the server name. More about this later. |
87 Here, the server name is set to an empty string which will match | 87 Here, the server name is set to an empty string which will match |
88 requests without the <header>Host</header> header line, | 88 requests without the <header>Host</header> header line, |
89 and a special nginx’s non-standard code 444 | 89 and a special nginx’s non-standard code 444 |
90 is returned that closes the connection. | 90 is returned that closes the connection. |
91 Since version 0.8.48, this is the default setting for the | 91 Since version 0.8.48, this is the default setting for the |
92 server name, so the <code>server_name ""</code> can be omitted. | 92 server name, so the <literal>server_name ""</literal> can be omitted. |
93 In earlier versions, the machine's <i>hostname</i> was used as | 93 In earlier versions, the machine's <i>hostname</i> was used as |
94 a default server name. | 94 a default server name. |
95 </para> | 95 </para> |
96 | 96 |
97 </section> | 97 </section> |
123 ... | 123 ... |
124 } | 124 } |
125 </programlisting> | 125 </programlisting> |
126 | 126 |
127 In this configuration, nginx first tests the IP address and port | 127 In this configuration, nginx first tests the IP address and port |
128 of the request against the <dirname>listen</dirname> directives | 128 of the request against the |
129 of the <dirname>server</dirname> blocks. It then tests the “Host” | 129 <link doc="ngx_http_core_module.xml" id="listen"/> directives |
130 header line of the request against the <dirname>server_name</dirname> | 130 of the |
131 entries of the <dirname>server</dirname> blocks that matched | 131 <link doc="ngx_http_core_module.xml" id="server"/> blocks. |
132 It then tests the “Host” | |
133 header line of the request against the | |
134 <link doc="ngx_http_core_module.xml" id="server_name"/> | |
135 entries of the | |
136 <link doc="ngx_http_core_module.xml" id="server"/> | |
137 blocks that matched | |
132 the IP address and port. | 138 the IP address and port. |
133 | 139 |
134 If the server name is not found, the request will be processed by | 140 If the server name is not found, the request will be processed by |
135 the default server. | 141 the default server. |
136 For example, a request for <url>www.nginx.com</url> received on | 142 For example, a request for <url>www.nginx.com</url> received on |
199 </para> | 205 </para> |
200 | 206 |
201 <para> | 207 <para> |
202 nginx first searches for the most specific location given by literal strings | 208 nginx first searches for the most specific location given by literal strings |
203 regardless of the listed order. In the configuration above | 209 regardless of the listed order. In the configuration above |
204 the only literal location is “<code>/</code>” and since it matches | 210 the only literal location is “<literal>/</literal>” and since it matches |
205 any request it will be used as a last resort. | 211 any request it will be used as a last resort. |
206 Then nginx checks locations given by | 212 Then nginx checks locations given by |
207 regular expression in the order listed in the configuration file. | 213 regular expression in the order listed in the configuration file. |
208 The first matching expression stops the search and nginx will use this | 214 The first matching expression stops the search and nginx will use this |
209 location. If no regular expression matches a request, then nginx uses | 215 location. If no regular expression matches a request, then nginx uses |
233 | 239 |
234 <list> | 240 <list> |
235 | 241 |
236 <item> | 242 <item> |
237 <para> | 243 <para> |
238 A request “<code>/logo.gif</code>” is matched by the literal location | 244 A request “<literal>/logo.gif</literal>” is matched by the literal location |
239 “<code>/</code>” first and then by the regular expression | 245 “<literal>/</literal>” first and then by the regular expression |
240 “<code>\.(gif|jpg|png)$</code>”, | 246 “<literal>\.(gif|jpg|png)$</literal>”, |
241 therefore, it is handled by the latter location. | 247 therefore, it is handled by the latter location. |
242 Using the directive “<code>root /data/www</code>” the request | 248 Using the directive “<literal>root /data/www</literal>” the request |
243 is mapped to a file <path>/data/www/logo.gif</path>, and the file | 249 is mapped to a file <path>/data/www/logo.gif</path>, and the file |
244 is sent to the client. | 250 is sent to the client. |
245 </para> | 251 </para> |
246 </item> | 252 </item> |
247 | 253 |
248 <item> | 254 <item> |
249 <para> | 255 <para> |
250 A request “<code>/index.php</code>” is also matched by the literal location | 256 A request “<literal>/index.php</literal>” is also matched by the literal location |
251 “<code>/</code>” first and then by the regular expression | 257 “<literal>/</literal>” first and then by the regular expression |
252 “<code>\.(php)$</code>”. Therefore, it is handled by the latter location | 258 “<literal>\.(php)$</literal>”. Therefore, it is handled by the latter location |
253 and the request is passed to a FastCGI server listening on localhost:9000. | 259 and the request is passed to a FastCGI server listening on localhost:9000. |
254 The <dirname>fastcgi_param</dirname> directive sets the FastCGI parameter | 260 The |
255 SCRIPT_FILENAME to “<code>/data/www/index.php</code>”, | 261 <link doc="ngx_http_fastcgi_module.xml" id="fastcgi_param"/> |
262 directive sets the FastCGI parameter | |
263 SCRIPT_FILENAME to “<literal>/data/www/index.php</literal>”, | |
256 and the FastCGI server executes the file. | 264 and the FastCGI server executes the file. |
257 The variable $document_root is equal to | 265 The variable $document_root is equal to |
258 the value of the <dirname>root</dirname> directive and | 266 the value of the |
267 <link doc="ngx_http_core_module.xml" id="root"/> | |
268 directive and | |
259 the variable $fastcgi_script_name is equal to the request URI, | 269 the variable $fastcgi_script_name is equal to the request URI, |
260 i.e. “<code>/index.php</code>”. | 270 i.e. “<literal>/index.php</literal>”. |
261 </para> | 271 </para> |
262 </item> | 272 </item> |
263 | 273 |
264 <item> | 274 <item> |
265 <para> | 275 <para> |
266 A request “<code>/about.html</code>” is matched by the literal location | 276 A request “<literal>/about.html</literal>” is matched by the literal location |
267 “<code>/</code>” only, therefore, it is handled in this location. | 277 “<literal>/</literal>” only, therefore, it is handled in this location. |
268 Using the directive “<code>root /data/www</code>” the request is mapped | 278 Using the directive “<literal>root /data/www</literal>” the request is mapped |
269 to the file <path>/data/www/about.html</path>, and the file is sent | 279 to the file <path>/data/www/about.html</path>, and the file is sent |
270 to the client. | 280 to the client. |
271 </para> | 281 </para> |
272 </item> | 282 </item> |
273 | 283 |
274 <item> | 284 <item> |
275 <para> | 285 <para> |
276 Handling a request “<code>/</code>” is more complex. | 286 Handling a request “<literal>/</literal>” is more complex. |
277 It is matched by the literal location “<code>/</code>” only, | 287 It is matched by the literal location “<literal>/</literal>” only, |
278 therefore, it is handled by this location. | 288 therefore, it is handled by this location. |
279 Then the <dirname>index</dirname> directive tests for the existence | 289 Then the |
290 <link doc="ngx_http_index_module.xml" id="index"/> | |
291 directive tests for the existence | |
280 of an index file according to its parameters and | 292 of an index file according to its parameters and |
281 the “<code>root /data/www</code>” directive. | 293 the “<literal>root /data/www</literal>” directive. |
282 If a file <path>/data/www/index.php</path> exists, | 294 If a file <path>/data/www/index.php</path> exists, |
283 then the directive does an internal redirect to “<code>/index.php</code>”, and | 295 then the directive does an internal redirect to “<literal>/index.php</literal>”, |
284 nginx searches the locations again as if the request had been sent by a client. | 296 and nginx searches the locations again |
297 as if the request had been sent by a client. | |
285 As we saw before, the redirected request will eventually be handled | 298 As we saw before, the redirected request will eventually be handled |
286 by the FastCGI server. | 299 by the FastCGI server. |
287 </para> | 300 </para> |
288 </item> | 301 </item> |
289 | 302 |