annotate xml/en/docs/http/request_processing.xml @ 521:3481a91d46ab

Minor revision in preparation for translation.
author Ruslan Ermilov <ru@nginx.com>
date Thu, 24 May 2012 12:24:25 +0000
parents 9913f1d51c07
children be54c443235a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
50
9d544687d02c Fixed DOCTYPE declaration.
Ruslan Ermilov <ru@nginx.com>
parents: 0
diff changeset
1 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd">
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
2
123
7db449e89e92 Unified the use of the "name" attribute instead of "title".
Ruslan Ermilov <ru@nginx.com>
parents: 121
diff changeset
3 <article name="How nginx processes a request"
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
4 link="/en/docs/http/request_processing.html"
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
5 lang="en"
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
6 author="Igor Sysoev"
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
7 editor="Brian Mercer">
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
8
121
49443032011c Unified <section> syntax for "article" and "module" documents.
Ruslan Ermilov <ru@nginx.com>
parents: 74
diff changeset
9 <section name="Name-based virtual servers">
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
10
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
11 <para>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
12 nginx first decides which <i>server</i> should process the request.
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
13 Let’s start with a simple configuration
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
14 where all three virtual servers listen on port *:80:
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
15 <programlisting>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
16 server {
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
17 listen 80;
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
18 server_name example.org www.example.org;
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
19 ...
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
20 }
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
21
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
22 server {
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
23 listen 80;
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
24 server_name example.net www.example.net;
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
25 ...
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
26 }
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
27
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
28 server {
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
29 listen 80;
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
30 server_name example.com www.example.com;
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
31 ...
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
32 }
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
33 </programlisting>
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
34
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
35 </para>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
36
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
37 <para>
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
38 In this configuration nginx tests only the request’s header field
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
39 <header>Host</header> to determine which server the request should be routed to.
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
40 If its value does not match any server name,
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
41 or the request does not contain this header field at all,
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
42 then nginx will route the request to the default server for this port.
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
43 In the configuration above, the default server is the first
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
44 one&mdash;which is nginx’s standard default behaviour.
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
45 It can also be set explicitly which server should be default,
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
46 with the <literal>default_server</literal> parameter
271
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
47 in the <link doc="ngx_http_core_module.xml" id="listen"/> directive:
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
48 <programlisting>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
49 server {
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
50 listen 80 <b>default_server</b>;
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
51 server_name example.net www.example.net;
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
52 ...
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
53 }
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
54 </programlisting>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
55
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
56 <note>
271
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
57 The <literal>default_server</literal> parameter has been available since
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
58 version 0.8.21.
271
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
59 In earlier versions the <literal>default</literal> parameter should be used
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
60 instead.
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
61 </note>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
62 Note that the default server is a property of the listen port
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
63 and not of the server name.
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
64 More about this later.
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
65 </para>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
66
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
67 </section>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
68
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
69
121
49443032011c Unified <section> syntax for "article" and "module" documents.
Ruslan Ermilov <ru@nginx.com>
parents: 74
diff changeset
70 <section id="how_to_prevent_undefined_server_names"
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
71 name="How to prevent processing requests with undefined server names">
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
72
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
73 <para>
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
74 If requests without the <header>Host</header> header field should not be
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
75 allowed, a server that just drops the requests can be defined:
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
76 <programlisting>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
77 server {
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
78 listen 80;
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
79 server_name "";
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
80 return 444;
73
6327603448e2 Updated the "How to prevent processing requests with undefined server names"
Ruslan Ermilov <ru@nginx.com>
parents: 50
diff changeset
81 }
6327603448e2 Updated the "How to prevent processing requests with undefined server names"
Ruslan Ermilov <ru@nginx.com>
parents: 50
diff changeset
82 </programlisting>
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
83 Here, the server name is set to an empty string that will match
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
84 requests without the <header>Host</header> header field,
73
6327603448e2 Updated the "How to prevent processing requests with undefined server names"
Ruslan Ermilov <ru@nginx.com>
parents: 50
diff changeset
85 and a special nginx’s non-standard code 444
6327603448e2 Updated the "How to prevent processing requests with undefined server names"
Ruslan Ermilov <ru@nginx.com>
parents: 50
diff changeset
86 is returned that closes the connection.
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
87 <note>
73
6327603448e2 Updated the "How to prevent processing requests with undefined server names"
Ruslan Ermilov <ru@nginx.com>
parents: 50
diff changeset
88 Since version 0.8.48, this is the default setting for the
271
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
89 server name, so the <literal>server_name ""</literal> can be omitted.
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
90 In earlier versions, the machine’s <i>hostname</i> was used as
73
6327603448e2 Updated the "How to prevent processing requests with undefined server names"
Ruslan Ermilov <ru@nginx.com>
parents: 50
diff changeset
91 a default server name.
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
92 </note>
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
93 </para>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
94
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
95 </section>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
96
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
97
121
49443032011c Unified <section> syntax for "article" and "module" documents.
Ruslan Ermilov <ru@nginx.com>
parents: 74
diff changeset
98 <section id="mixed_name_ip_based_servers"
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
99 name="Mixed name-based and IP-based virtual servers">
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
100
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
101 <para>
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
102 Let’s look at a more complex configuration
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
103 where some virtual servers listen on different addresses:
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
104 <programlisting>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
105 server {
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
106 listen 192.168.1.1:80;
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
107 server_name example.org www.example.org;
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
108 ...
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
109 }
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
110
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
111 server {
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
112 listen 192.168.1.1:80;
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
113 server_name example.net www.example.net;
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
114 ...
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
115 }
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
116
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
117 server {
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
118 listen 192.168.1.2:80;
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
119 server_name example.com www.example.com;
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
120 ...
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
121 }
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
122 </programlisting>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
123 In this configuration, nginx first tests the IP address and port
271
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
124 of the request against the
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
125 <link doc="ngx_http_core_module.xml" id="listen"/> directives
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
126 of the
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
127 <link doc="ngx_http_core_module.xml" id="server"/> blocks.
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
128 It then tests the <header>Host</header>
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
129 header field of the request against the
271
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
130 <link doc="ngx_http_core_module.xml" id="server_name"/>
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
131 entries of the
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
132 <link doc="ngx_http_core_module.xml" id="server"/>
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
133 blocks that matched
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
134 the IP address and port.
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
135 If the server name is not found, the request will be processed by
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
136 the default server.
490
9913f1d51c07 Replaced "nginx" domain names with example domains.
Ruslan Ermilov <ru@nginx.com>
parents: 461
diff changeset
137 For example, a request for <url>www.example.com</url> received on
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
138 the 192.168.1.1:80 port will be handled by the default server
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
139 of the 192.168.1.1:80 port, i.e., by the first server,
490
9913f1d51c07 Replaced "nginx" domain names with example domains.
Ruslan Ermilov <ru@nginx.com>
parents: 461
diff changeset
140 since there is no <url>www.example.com</url> defined for this port.
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
141 </para>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
142
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
143 <para>
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
144 As already stated, a default server is a property of the listen port,
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
145 and different default servers may be defined for different ports:
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
146 <programlisting>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
147 server {
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
148 listen 192.168.1.1:80;
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
149 server_name example.org www.example.org;
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
150 ...
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
151 }
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
152
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
153 server {
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
154 listen 192.168.1.1:80 <b>default_server</b>;
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
155 server_name example.net www.example.net;
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
156 ...
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
157 }
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
158
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
159 server {
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
160 listen 192.168.1.2:80 <b>default_server</b>;
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
161 server_name example.com www.example.com;
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
162 ...
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
163 }
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
164 </programlisting>
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
165
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
166 </para>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
167
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
168 </section>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
169
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
170
121
49443032011c Unified <section> syntax for "article" and "module" documents.
Ruslan Ermilov <ru@nginx.com>
parents: 74
diff changeset
171 <section id="simple_php_site_configuration"
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
172 name="A simple PHP site configuration">
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
173
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
174 <para>
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
175 Now let’s look at how nginx chooses a <i>location</i> to process a request
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
176 for a typical, simple PHP site:
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
177 <programlisting>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
178 server {
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
179 listen 80;
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
180 server_name example.org www.example.org;
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
181 root /data/www;
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
182
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
183 location / {
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
184 index index.html index.php;
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
185 }
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
186
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
187 location ~* \.(gif|jpg|png)$ {
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
188 expires 30d;
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
189 }
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
190
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
191 location ~ \.php$ {
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
192 fastcgi_pass localhost:9000;
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
193 fastcgi_param SCRIPT_FILENAME
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
194 $document_root$fastcgi_script_name;
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
195 include fastcgi_params;
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
196 }
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
197 }
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
198 </programlisting>
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
199
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
200 </para>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
201
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
202 <para>
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
203 nginx first searches for the most specific prefix location given by
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
204 literal strings regardless of the listed order.
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
205 In the configuration above
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
206 the only prefix location is “<literal>/</literal>” and since it matches
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
207 any request it will be used as a last resort.
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
208 Then nginx checks locations given by
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
209 regular expression in the order listed in the configuration file.
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
210 The first matching expression stops the search and nginx will use this
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
211 location.
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
212 If no regular expression matches a request, then nginx uses
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
213 the most specific prefix location found earlier.
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
214 </para>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
215
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
216 <para>
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
217 Note that locations of all types test only a URI part of request line
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
218 without arguments.
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
219 This is done because arguments in the query string may be given in
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
220 several ways, for example:
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
221 <programlisting>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
222 /index.php?user=john&amp;page=1
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
223 /index.php?page=1&amp;user=john
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
224 </programlisting>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
225 Besides, anyone may request anything in the query string:
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
226 <programlisting>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
227 /index.php?page=1&amp;something+else&amp;user=john
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
228 </programlisting>
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
229
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
230 </para>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
231
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
232 <para>
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
233 Now let’s look at how requests would be processed
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
234 in the configuration above:
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
235 <list type="bullet" compact="no">
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
236
461
6135f3c95bf6 Unified markup for lists.
Ruslan Ermilov <ru@nginx.com>
parents: 271
diff changeset
237 <listitem>
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
238 A request “<literal>/logo.gif</literal>” is matched by the prefix location
271
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
239 “<literal>/</literal>” first and then by the regular expression
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
240 “<literal>\.(gif|jpg|png)$</literal>”,
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
241 therefore, it is handled by the latter location.
271
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
242 Using the directive “<literal>root&nbsp;/data/www</literal>” the request
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
243 is mapped to the file <path>/data/www/logo.gif</path>, and the file
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
244 is sent to the client.
461
6135f3c95bf6 Unified markup for lists.
Ruslan Ermilov <ru@nginx.com>
parents: 271
diff changeset
245 </listitem>
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
246
461
6135f3c95bf6 Unified markup for lists.
Ruslan Ermilov <ru@nginx.com>
parents: 271
diff changeset
247 <listitem>
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
248 A request “<literal>/index.php</literal>” is also matched by the prefix location
271
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
249 “<literal>/</literal>” first and then by the regular expression
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
250 “<literal>\.(php)$</literal>”.
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
251 Therefore, it is handled by the latter location
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
252 and the request is passed to a FastCGI server listening on localhost:9000.
271
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
253 The
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
254 <link doc="ngx_http_fastcgi_module.xml" id="fastcgi_param"/>
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
255 directive sets the FastCGI parameter
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
256 <literal>SCRIPT_FILENAME</literal> to “<literal>/data/www/index.php</literal>”,
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
257 and the FastCGI server executes the file.
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
258 The variable <var>$document_root</var> is equal to
271
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
259 the value of the
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
260 <link doc="ngx_http_core_module.xml" id="root"/>
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
261 directive and the variable <var>$fastcgi_script_name</var> is equal to
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
262 the request URI, i.e. “<literal>/index.php</literal>”.
461
6135f3c95bf6 Unified markup for lists.
Ruslan Ermilov <ru@nginx.com>
parents: 271
diff changeset
263 </listitem>
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
264
461
6135f3c95bf6 Unified markup for lists.
Ruslan Ermilov <ru@nginx.com>
parents: 271
diff changeset
265 <listitem>
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
266 A request “<literal>/about.html</literal>” is matched by the prefix location
271
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
267 “<literal>/</literal>” only, therefore, it is handled in this location.
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
268 Using the directive “<literal>root /data/www</literal>” the request is mapped
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
269 to the file <path>/data/www/about.html</path>, and the file is sent
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
270 to the client.
461
6135f3c95bf6 Unified markup for lists.
Ruslan Ermilov <ru@nginx.com>
parents: 271
diff changeset
271 </listitem>
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
272
461
6135f3c95bf6 Unified markup for lists.
Ruslan Ermilov <ru@nginx.com>
parents: 271
diff changeset
273 <listitem>
271
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
274 Handling a request “<literal>/</literal>” is more complex.
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
275 It is matched by the prefix location “<literal>/</literal>” only,
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
276 therefore, it is handled by this location.
271
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
277 Then the
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
278 <link doc="ngx_http_index_module.xml" id="index"/>
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
279 directive tests for the existence
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
280 of index files according to its parameters and
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
281 the “<literal>root /data/www</literal>” directive.
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
282 If the file <path>/data/www/index.html</path> does not exist,
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
283 and the file <path>/data/www/index.php</path> exists,
271
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
284 then the directive does an internal redirect to “<literal>/index.php</literal>”,
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
285 and nginx searches the locations again
4c6d2c614d2c Cleaned up XML tag mess:
Ruslan Ermilov <ru@nginx.com>
parents: 148
diff changeset
286 as if the request had been sent by a client.
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
287 As we saw before, the redirected request will eventually be handled
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
288 by the FastCGI server.
461
6135f3c95bf6 Unified markup for lists.
Ruslan Ermilov <ru@nginx.com>
parents: 271
diff changeset
289 </listitem>
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
290
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
291 </list>
521
3481a91d46ab Minor revision in preparation for translation.
Ruslan Ermilov <ru@nginx.com>
parents: 490
diff changeset
292
0
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
293 </para>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
294
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
295 </section>
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
296
61e04fc01027 Initial import of the nginx.org website.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
297 </article>