0
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #include <ngx_config.h>
|
|
8 #include <ngx_core.h>
|
|
9 #include <ngx_http.h>
|
|
10
|
10
|
11
|
180
|
12 typedef struct {
|
286
|
13 u_char *name;
|
180
|
14 uint32_t method;
|
|
15 } ngx_http_method_name_t;
|
|
16
|
|
17
|
278
|
18 #define NGX_HTTP_REQUEST_BODY_FILE_OFF 0
|
|
19 #define NGX_HTTP_REQUEST_BODY_FILE_ON 1
|
|
20 #define NGX_HTTP_REQUEST_BODY_FILE_CLEAN 2
|
|
21
|
|
22
|
378
|
23 static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r);
|
|
24 static ngx_int_t ngx_http_core_find_static_location(ngx_http_request_t *r,
|
|
25 ngx_http_location_tree_node_t *node);
|
0
|
26
|
58
|
27 static ngx_int_t ngx_http_core_preconfiguration(ngx_conf_t *cf);
|
0
|
28 static void *ngx_http_core_create_main_conf(ngx_conf_t *cf);
|
|
29 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf);
|
|
30 static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf);
|
|
31 static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
|
36
|
32 void *parent, void *child);
|
0
|
33 static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf);
|
|
34 static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
|
36
|
35 void *parent, void *child);
|
0
|
36
|
34
|
37 static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
38 void *dummy);
|
34
|
39 static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
40 void *dummy);
|
430
|
41 static ngx_int_t ngx_http_core_regex_location(ngx_conf_t *cf,
|
|
42 ngx_http_core_loc_conf_t *clcf, ngx_str_t *regex, ngx_uint_t caseless);
|
34
|
43
|
|
44 static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
45 void *conf);
|
34
|
46 static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy,
|
36
|
47 void *conf);
|
0
|
48
|
34
|
49 static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
50 void *conf);
|
34
|
51 static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
52 void *conf);
|
34
|
53 static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
180
|
54 static char *ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
55 void *conf);
|
390
|
56 static char *ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
57 void *conf);
|
34
|
58 static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
59 void *conf);
|
430
|
60 static char *ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
61 void *conf);
|
332
|
62 static char *ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
63 void *conf);
|
34
|
64 static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
65 void *conf);
|
34
|
66 static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
67 void *conf);
|
58
|
68 static char *ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
69 void *conf);
|
354
|
70 static char *ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
|
348
|
71 void *conf);
|
358
|
72 #if (NGX_HTTP_GZIP)
|
|
73 static char *ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
74 void *conf);
|
|
75 #endif
|
0
|
76
|
34
|
77 static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data);
|
300
|
78 static char *ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data);
|
34
|
79
|
|
80 static ngx_conf_post_t ngx_http_core_lowat_post =
|
300
|
81 { ngx_http_core_lowat_check };
|
|
82
|
|
83 static ngx_conf_post_handler_pt ngx_http_core_pool_size_p =
|
|
84 ngx_http_core_pool_size;
|
0
|
85
|
378
|
86 static ngx_conf_deprecated_t ngx_conf_deprecated_optimize_server_names = {
|
|
87 ngx_conf_deprecated, "optimize_server_names", "server_name_in_redirect"
|
158
|
88 };
|
|
89
|
358
|
90 static ngx_conf_deprecated_t ngx_conf_deprecated_open_file_cache_retest = {
|
|
91 ngx_conf_deprecated, "open_file_cache_retest", "open_file_cache_valid"
|
|
92 };
|
|
93
|
362
|
94 static ngx_conf_deprecated_t ngx_conf_deprecated_satisfy_any = {
|
|
95 ngx_conf_deprecated, "satisfy_any", "satisfy"
|
|
96 };
|
|
97
|
0
|
98
|
278
|
99 static ngx_conf_enum_t ngx_http_core_request_body_in_file[] = {
|
|
100 { ngx_string("off"), NGX_HTTP_REQUEST_BODY_FILE_OFF },
|
|
101 { ngx_string("on"), NGX_HTTP_REQUEST_BODY_FILE_ON },
|
|
102 { ngx_string("clean"), NGX_HTTP_REQUEST_BODY_FILE_CLEAN },
|
|
103 { ngx_null_string, 0 }
|
|
104 };
|
|
105
|
|
106
|
520
|
107 #if (NGX_HAVE_FILE_AIO)
|
|
108
|
|
109 static ngx_conf_enum_t ngx_http_core_aio[] = {
|
|
110 { ngx_string("off"), NGX_HTTP_AIO_OFF },
|
|
111 { ngx_string("on"), NGX_HTTP_AIO_ON },
|
|
112 #if (NGX_HAVE_AIO_SENDFILE)
|
|
113 { ngx_string("sendfile"), NGX_HTTP_AIO_SENDFILE },
|
|
114 #endif
|
|
115 { ngx_null_string, 0 }
|
|
116 };
|
|
117
|
|
118 #endif
|
|
119
|
|
120
|
362
|
121 static ngx_conf_enum_t ngx_http_core_satisfy[] = {
|
|
122 { ngx_string("all"), NGX_HTTP_SATISFY_ALL },
|
|
123 { ngx_string("any"), NGX_HTTP_SATISFY_ANY },
|
|
124 { ngx_null_string, 0 }
|
|
125 };
|
|
126
|
|
127
|
424
|
128 static ngx_conf_enum_t ngx_http_core_if_modified_since[] = {
|
444
|
129 { ngx_string("off"), NGX_HTTP_IMS_OFF },
|
|
130 { ngx_string("exact"), NGX_HTTP_IMS_EXACT },
|
|
131 { ngx_string("before"), NGX_HTTP_IMS_BEFORE },
|
424
|
132 { ngx_null_string, 0 }
|
|
133 };
|
|
134
|
|
135
|
464
|
136 static ngx_path_init_t ngx_http_client_temp_path = {
|
|
137 ngx_string(NGX_HTTP_CLIENT_TEMP_PATH), { 0, 0, 0 }
|
|
138 };
|
|
139
|
|
140
|
358
|
141 #if (NGX_HTTP_GZIP)
|
|
142
|
|
143 static ngx_conf_enum_t ngx_http_gzip_http_version[] = {
|
|
144 { ngx_string("1.0"), NGX_HTTP_VERSION_10 },
|
|
145 { ngx_string("1.1"), NGX_HTTP_VERSION_11 },
|
|
146 { ngx_null_string, 0 }
|
|
147 };
|
|
148
|
|
149
|
|
150 static ngx_conf_bitmask_t ngx_http_gzip_proxied_mask[] = {
|
|
151 { ngx_string("off"), NGX_HTTP_GZIP_PROXIED_OFF },
|
|
152 { ngx_string("expired"), NGX_HTTP_GZIP_PROXIED_EXPIRED },
|
|
153 { ngx_string("no-cache"), NGX_HTTP_GZIP_PROXIED_NO_CACHE },
|
|
154 { ngx_string("no-store"), NGX_HTTP_GZIP_PROXIED_NO_STORE },
|
|
155 { ngx_string("private"), NGX_HTTP_GZIP_PROXIED_PRIVATE },
|
|
156 { ngx_string("no_last_modified"), NGX_HTTP_GZIP_PROXIED_NO_LM },
|
|
157 { ngx_string("no_etag"), NGX_HTTP_GZIP_PROXIED_NO_ETAG },
|
|
158 { ngx_string("auth"), NGX_HTTP_GZIP_PROXIED_AUTH },
|
|
159 { ngx_string("any"), NGX_HTTP_GZIP_PROXIED_ANY },
|
|
160 { ngx_null_string, 0 }
|
|
161 };
|
|
162
|
|
163
|
|
164 static ngx_str_t ngx_http_gzip_no_cache = ngx_string("no-cache");
|
|
165 static ngx_str_t ngx_http_gzip_no_store = ngx_string("no-store");
|
|
166 static ngx_str_t ngx_http_gzip_private = ngx_string("private");
|
|
167
|
|
168 #endif
|
|
169
|
|
170
|
0
|
171 static ngx_command_t ngx_http_core_commands[] = {
|
|
172
|
160
|
173 { ngx_string("variables_hash_max_size"),
|
|
174 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
|
175 ngx_conf_set_num_slot,
|
|
176 NGX_HTTP_MAIN_CONF_OFFSET,
|
|
177 offsetof(ngx_http_core_main_conf_t, variables_hash_max_size),
|
|
178 NULL },
|
|
179
|
|
180 { ngx_string("variables_hash_bucket_size"),
|
|
181 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
|
182 ngx_conf_set_num_slot,
|
|
183 NGX_HTTP_MAIN_CONF_OFFSET,
|
|
184 offsetof(ngx_http_core_main_conf_t, variables_hash_bucket_size),
|
|
185 NULL },
|
|
186
|
142
|
187 { ngx_string("server_names_hash_max_size"),
|
26
|
188 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
|
189 ngx_conf_set_num_slot,
|
|
190 NGX_HTTP_MAIN_CONF_OFFSET,
|
142
|
191 offsetof(ngx_http_core_main_conf_t, server_names_hash_max_size),
|
26
|
192 NULL },
|
|
193
|
142
|
194 { ngx_string("server_names_hash_bucket_size"),
|
26
|
195 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
|
196 ngx_conf_set_num_slot,
|
|
197 NGX_HTTP_MAIN_CONF_OFFSET,
|
142
|
198 offsetof(ngx_http_core_main_conf_t, server_names_hash_bucket_size),
|
26
|
199 NULL },
|
|
200
|
0
|
201 { ngx_string("server"),
|
200
|
202 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_MULTI|NGX_CONF_NOARGS,
|
34
|
203 ngx_http_core_server,
|
0
|
204 0,
|
|
205 0,
|
|
206 NULL },
|
|
207
|
|
208 { ngx_string("connection_pool_size"),
|
|
209 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
210 ngx_conf_set_size_slot,
|
|
211 NGX_HTTP_SRV_CONF_OFFSET,
|
|
212 offsetof(ngx_http_core_srv_conf_t, connection_pool_size),
|
300
|
213 &ngx_http_core_pool_size_p },
|
0
|
214
|
|
215 { ngx_string("request_pool_size"),
|
|
216 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
217 ngx_conf_set_size_slot,
|
|
218 NGX_HTTP_SRV_CONF_OFFSET,
|
|
219 offsetof(ngx_http_core_srv_conf_t, request_pool_size),
|
300
|
220 &ngx_http_core_pool_size_p },
|
0
|
221
|
|
222 { ngx_string("client_header_timeout"),
|
|
223 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
224 ngx_conf_set_msec_slot,
|
|
225 NGX_HTTP_SRV_CONF_OFFSET,
|
|
226 offsetof(ngx_http_core_srv_conf_t, client_header_timeout),
|
|
227 NULL },
|
|
228
|
|
229 { ngx_string("client_header_buffer_size"),
|
|
230 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
231 ngx_conf_set_size_slot,
|
|
232 NGX_HTTP_SRV_CONF_OFFSET,
|
|
233 offsetof(ngx_http_core_srv_conf_t, client_header_buffer_size),
|
|
234 NULL },
|
|
235
|
|
236 { ngx_string("large_client_header_buffers"),
|
|
237 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE2,
|
|
238 ngx_conf_set_bufs_slot,
|
|
239 NGX_HTTP_SRV_CONF_OFFSET,
|
|
240 offsetof(ngx_http_core_srv_conf_t, large_client_header_buffers),
|
|
241 NULL },
|
|
242
|
158
|
243 { ngx_string("optimize_server_names"),
|
|
244 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
|
|
245 ngx_conf_set_flag_slot,
|
378
|
246 NGX_HTTP_LOC_CONF_OFFSET,
|
|
247 offsetof(ngx_http_core_loc_conf_t, server_name_in_redirect),
|
|
248 &ngx_conf_deprecated_optimize_server_names },
|
152
|
249
|
60
|
250 { ngx_string("ignore_invalid_headers"),
|
|
251 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
|
|
252 ngx_conf_set_flag_slot,
|
|
253 NGX_HTTP_SRV_CONF_OFFSET,
|
|
254 offsetof(ngx_http_core_srv_conf_t, ignore_invalid_headers),
|
|
255 NULL },
|
|
256
|
342
|
257 { ngx_string("merge_slashes"),
|
|
258 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
|
|
259 ngx_conf_set_flag_slot,
|
|
260 NGX_HTTP_SRV_CONF_OFFSET,
|
|
261 offsetof(ngx_http_core_srv_conf_t, merge_slashes),
|
|
262 NULL },
|
|
263
|
412
|
264 { ngx_string("underscores_in_headers"),
|
|
265 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
|
|
266 ngx_conf_set_flag_slot,
|
|
267 NGX_HTTP_SRV_CONF_OFFSET,
|
|
268 offsetof(ngx_http_core_srv_conf_t, underscores_in_headers),
|
|
269 NULL },
|
|
270
|
0
|
271 { ngx_string("location"),
|
|
272 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12,
|
34
|
273 ngx_http_core_location,
|
0
|
274 NGX_HTTP_SRV_CONF_OFFSET,
|
|
275 0,
|
|
276 NULL },
|
|
277
|
|
278 { ngx_string("listen"),
|
72
|
279 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
|
34
|
280 ngx_http_core_listen,
|
0
|
281 NGX_HTTP_SRV_CONF_OFFSET,
|
|
282 0,
|
|
283 NULL },
|
|
284
|
|
285 { ngx_string("server_name"),
|
|
286 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
|
34
|
287 ngx_http_core_server_name,
|
0
|
288 NGX_HTTP_SRV_CONF_OFFSET,
|
|
289 0,
|
|
290 NULL },
|
|
291
|
138
|
292 { ngx_string("types_hash_max_size"),
|
|
293 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
294 ngx_conf_set_num_slot,
|
|
295 NGX_HTTP_LOC_CONF_OFFSET,
|
|
296 offsetof(ngx_http_core_loc_conf_t, types_hash_max_size),
|
|
297 NULL },
|
|
298
|
|
299 { ngx_string("types_hash_bucket_size"),
|
|
300 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
301 ngx_conf_set_num_slot,
|
|
302 NGX_HTTP_LOC_CONF_OFFSET,
|
|
303 offsetof(ngx_http_core_loc_conf_t, types_hash_bucket_size),
|
|
304 NULL },
|
|
305
|
0
|
306 { ngx_string("types"),
|
|
307 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF
|
|
308 |NGX_CONF_BLOCK|NGX_CONF_NOARGS,
|
34
|
309 ngx_http_core_types,
|
0
|
310 NGX_HTTP_LOC_CONF_OFFSET,
|
|
311 0,
|
|
312 NULL },
|
|
313
|
|
314 { ngx_string("default_type"),
|
|
315 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
316 ngx_conf_set_str_slot,
|
|
317 NGX_HTTP_LOC_CONF_OFFSET,
|
|
318 offsetof(ngx_http_core_loc_conf_t, default_type),
|
|
319 NULL },
|
|
320
|
|
321 { ngx_string("root"),
|
58
|
322 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
323 |NGX_CONF_TAKE1,
|
34
|
324 ngx_http_core_root,
|
0
|
325 NGX_HTTP_LOC_CONF_OFFSET,
|
|
326 0,
|
|
327 NULL },
|
|
328
|
|
329 { ngx_string("alias"),
|
|
330 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
34
|
331 ngx_http_core_root,
|
0
|
332 NGX_HTTP_LOC_CONF_OFFSET,
|
|
333 0,
|
|
334 NULL },
|
|
335
|
180
|
336 { ngx_string("limit_except"),
|
|
337 NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_1MORE,
|
|
338 ngx_http_core_limit_except,
|
|
339 NGX_HTTP_LOC_CONF_OFFSET,
|
|
340 0,
|
|
341 NULL },
|
|
342
|
0
|
343 { ngx_string("client_max_body_size"),
|
|
344 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
212
|
345 ngx_conf_set_off_slot,
|
0
|
346 NGX_HTTP_LOC_CONF_OFFSET,
|
|
347 offsetof(ngx_http_core_loc_conf_t, client_max_body_size),
|
|
348 NULL },
|
|
349
|
|
350 { ngx_string("client_body_buffer_size"),
|
|
351 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
352 ngx_conf_set_size_slot,
|
|
353 NGX_HTTP_LOC_CONF_OFFSET,
|
|
354 offsetof(ngx_http_core_loc_conf_t, client_body_buffer_size),
|
|
355 NULL },
|
|
356
|
|
357 { ngx_string("client_body_timeout"),
|
|
358 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
359 ngx_conf_set_msec_slot,
|
|
360 NGX_HTTP_LOC_CONF_OFFSET,
|
|
361 offsetof(ngx_http_core_loc_conf_t, client_body_timeout),
|
|
362 NULL },
|
|
363
|
28
|
364 { ngx_string("client_body_temp_path"),
|
|
365 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
|
|
366 ngx_conf_set_path_slot,
|
|
367 NGX_HTTP_LOC_CONF_OFFSET,
|
|
368 offsetof(ngx_http_core_loc_conf_t, client_body_temp_path),
|
464
|
369 NULL },
|
28
|
370
|
182
|
371 { ngx_string("client_body_in_file_only"),
|
492
|
372 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
278
|
373 ngx_conf_set_enum_slot,
|
182
|
374 NGX_HTTP_LOC_CONF_OFFSET,
|
|
375 offsetof(ngx_http_core_loc_conf_t, client_body_in_file_only),
|
278
|
376 &ngx_http_core_request_body_in_file },
|
182
|
377
|
492
|
378 { ngx_string("client_body_in_single_buffer"),
|
|
379 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
380 ngx_conf_set_flag_slot,
|
|
381 NGX_HTTP_LOC_CONF_OFFSET,
|
|
382 offsetof(ngx_http_core_loc_conf_t, client_body_in_single_buffer),
|
|
383 NULL },
|
|
384
|
0
|
385 { ngx_string("sendfile"),
|
278
|
386 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
387 |NGX_CONF_TAKE1,
|
0
|
388 ngx_conf_set_flag_slot,
|
|
389 NGX_HTTP_LOC_CONF_OFFSET,
|
|
390 offsetof(ngx_http_core_loc_conf_t, sendfile),
|
|
391 NULL },
|
|
392
|
300
|
393 { ngx_string("sendfile_max_chunk"),
|
|
394 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
395 ngx_conf_set_size_slot,
|
|
396 NGX_HTTP_LOC_CONF_OFFSET,
|
|
397 offsetof(ngx_http_core_loc_conf_t, sendfile_max_chunk),
|
|
398 NULL },
|
|
399
|
518
|
400 #if (NGX_HAVE_FILE_AIO)
|
|
401
|
|
402 { ngx_string("aio"),
|
520
|
403 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
404 ngx_conf_set_enum_slot,
|
518
|
405 NGX_HTTP_LOC_CONF_OFFSET,
|
|
406 offsetof(ngx_http_core_loc_conf_t, aio),
|
520
|
407 &ngx_http_core_aio },
|
518
|
408
|
|
409 #endif
|
|
410
|
532
|
411 { ngx_string("read_ahead"),
|
|
412 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
413 ngx_conf_set_size_slot,
|
|
414 NGX_HTTP_LOC_CONF_OFFSET,
|
|
415 offsetof(ngx_http_core_loc_conf_t, read_ahead),
|
|
416 NULL },
|
|
417
|
390
|
418 { ngx_string("directio"),
|
|
419 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
420 ngx_http_core_directio,
|
|
421 NGX_HTTP_LOC_CONF_OFFSET,
|
|
422 0,
|
|
423 NULL },
|
|
424
|
518
|
425 { ngx_string("directio_alignment"),
|
|
426 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
427 ngx_conf_set_off_slot,
|
|
428 NGX_HTTP_LOC_CONF_OFFSET,
|
|
429 offsetof(ngx_http_core_loc_conf_t, directio_alignment),
|
|
430 NULL },
|
|
431
|
0
|
432 { ngx_string("tcp_nopush"),
|
|
433 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
434 ngx_conf_set_flag_slot,
|
|
435 NGX_HTTP_LOC_CONF_OFFSET,
|
|
436 offsetof(ngx_http_core_loc_conf_t, tcp_nopush),
|
|
437 NULL },
|
|
438
|
2
|
439 { ngx_string("tcp_nodelay"),
|
|
440 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
441 ngx_conf_set_flag_slot,
|
|
442 NGX_HTTP_LOC_CONF_OFFSET,
|
|
443 offsetof(ngx_http_core_loc_conf_t, tcp_nodelay),
|
|
444 NULL },
|
|
445
|
0
|
446 { ngx_string("send_timeout"),
|
|
447 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
448 ngx_conf_set_msec_slot,
|
|
449 NGX_HTTP_LOC_CONF_OFFSET,
|
|
450 offsetof(ngx_http_core_loc_conf_t, send_timeout),
|
|
451 NULL },
|
|
452
|
|
453 { ngx_string("send_lowat"),
|
|
454 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
455 ngx_conf_set_size_slot,
|
|
456 NGX_HTTP_LOC_CONF_OFFSET,
|
|
457 offsetof(ngx_http_core_loc_conf_t, send_lowat),
|
34
|
458 &ngx_http_core_lowat_post },
|
0
|
459
|
|
460 { ngx_string("postpone_output"),
|
|
461 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
462 ngx_conf_set_size_slot,
|
|
463 NGX_HTTP_LOC_CONF_OFFSET,
|
|
464 offsetof(ngx_http_core_loc_conf_t, postpone_output),
|
|
465 NULL },
|
|
466
|
|
467 { ngx_string("limit_rate"),
|
34
|
468 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
469 |NGX_CONF_TAKE1,
|
0
|
470 ngx_conf_set_size_slot,
|
|
471 NGX_HTTP_LOC_CONF_OFFSET,
|
|
472 offsetof(ngx_http_core_loc_conf_t, limit_rate),
|
|
473 NULL },
|
|
474
|
496
|
475 { ngx_string("limit_rate_after"),
|
|
476 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
477 |NGX_CONF_TAKE1,
|
|
478 ngx_conf_set_size_slot,
|
|
479 NGX_HTTP_LOC_CONF_OFFSET,
|
|
480 offsetof(ngx_http_core_loc_conf_t, limit_rate_after),
|
|
481 NULL },
|
|
482
|
0
|
483 { ngx_string("keepalive_timeout"),
|
|
484 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
|
34
|
485 ngx_http_core_keepalive,
|
0
|
486 NGX_HTTP_LOC_CONF_OFFSET,
|
|
487 0,
|
|
488 NULL },
|
|
489
|
496
|
490 { ngx_string("keepalive_requests"),
|
|
491 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
492 ngx_conf_set_num_slot,
|
|
493 NGX_HTTP_LOC_CONF_OFFSET,
|
|
494 offsetof(ngx_http_core_loc_conf_t, keepalive_requests),
|
|
495 NULL },
|
|
496
|
362
|
497 { ngx_string("satisfy"),
|
|
498 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
499 ngx_conf_set_enum_slot,
|
|
500 NGX_HTTP_LOC_CONF_OFFSET,
|
|
501 offsetof(ngx_http_core_loc_conf_t, satisfy),
|
|
502 &ngx_http_core_satisfy },
|
|
503
|
92
|
504 { ngx_string("satisfy_any"),
|
|
505 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
506 ngx_conf_set_flag_slot,
|
|
507 NGX_HTTP_LOC_CONF_OFFSET,
|
362
|
508 offsetof(ngx_http_core_loc_conf_t, satisfy),
|
|
509 &ngx_conf_deprecated_satisfy_any },
|
92
|
510
|
58
|
511 { ngx_string("internal"),
|
|
512 NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
|
|
513 ngx_http_core_internal,
|
|
514 NGX_HTTP_LOC_CONF_OFFSET,
|
|
515 0,
|
|
516 NULL },
|
|
517
|
0
|
518 { ngx_string("lingering_time"),
|
|
519 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
520 ngx_conf_set_msec_slot,
|
|
521 NGX_HTTP_LOC_CONF_OFFSET,
|
|
522 offsetof(ngx_http_core_loc_conf_t, lingering_time),
|
|
523 NULL },
|
|
524
|
|
525 { ngx_string("lingering_timeout"),
|
|
526 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
527 ngx_conf_set_msec_slot,
|
|
528 NGX_HTTP_LOC_CONF_OFFSET,
|
|
529 offsetof(ngx_http_core_loc_conf_t, lingering_timeout),
|
|
530 NULL },
|
|
531
|
|
532 { ngx_string("reset_timedout_connection"),
|
|
533 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
534 ngx_conf_set_flag_slot,
|
|
535 NGX_HTTP_LOC_CONF_OFFSET,
|
|
536 offsetof(ngx_http_core_loc_conf_t, reset_timedout_connection),
|
|
537 NULL },
|
|
538
|
362
|
539 { ngx_string("server_name_in_redirect"),
|
|
540 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
541 ngx_conf_set_flag_slot,
|
|
542 NGX_HTTP_LOC_CONF_OFFSET,
|
|
543 offsetof(ngx_http_core_loc_conf_t, server_name_in_redirect),
|
|
544 NULL },
|
|
545
|
70
|
546 { ngx_string("port_in_redirect"),
|
|
547 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
548 ngx_conf_set_flag_slot,
|
|
549 NGX_HTTP_LOC_CONF_OFFSET,
|
|
550 offsetof(ngx_http_core_loc_conf_t, port_in_redirect),
|
|
551 NULL },
|
|
552
|
0
|
553 { ngx_string("msie_padding"),
|
|
554 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
555 ngx_conf_set_flag_slot,
|
|
556 NGX_HTTP_LOC_CONF_OFFSET,
|
|
557 offsetof(ngx_http_core_loc_conf_t, msie_padding),
|
|
558 NULL },
|
|
559
|
228
|
560 { ngx_string("msie_refresh"),
|
|
561 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
562 ngx_conf_set_flag_slot,
|
|
563 NGX_HTTP_LOC_CONF_OFFSET,
|
|
564 offsetof(ngx_http_core_loc_conf_t, msie_refresh),
|
|
565 NULL },
|
|
566
|
76
|
567 { ngx_string("log_not_found"),
|
|
568 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
569 ngx_conf_set_flag_slot,
|
|
570 NGX_HTTP_LOC_CONF_OFFSET,
|
|
571 offsetof(ngx_http_core_loc_conf_t, log_not_found),
|
|
572 NULL },
|
|
573
|
412
|
574 { ngx_string("log_subrequest"),
|
|
575 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
576 ngx_conf_set_flag_slot,
|
|
577 NGX_HTTP_LOC_CONF_OFFSET,
|
|
578 offsetof(ngx_http_core_loc_conf_t, log_subrequest),
|
|
579 NULL },
|
|
580
|
228
|
581 { ngx_string("recursive_error_pages"),
|
|
582 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
583 ngx_conf_set_flag_slot,
|
|
584 NGX_HTTP_LOC_CONF_OFFSET,
|
|
585 offsetof(ngx_http_core_loc_conf_t, recursive_error_pages),
|
|
586 NULL },
|
|
587
|
342
|
588 { ngx_string("server_tokens"),
|
|
589 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
590 ngx_conf_set_flag_slot,
|
|
591 NGX_HTTP_LOC_CONF_OFFSET,
|
|
592 offsetof(ngx_http_core_loc_conf_t, server_tokens),
|
|
593 NULL },
|
|
594
|
424
|
595 { ngx_string("if_modified_since"),
|
|
596 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
597 ngx_conf_set_enum_slot,
|
|
598 NGX_HTTP_LOC_CONF_OFFSET,
|
|
599 offsetof(ngx_http_core_loc_conf_t, if_modified_since),
|
|
600 &ngx_http_core_if_modified_since },
|
|
601
|
566
|
602 { ngx_string("chunked_transfer_encoding"),
|
|
603 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
604 ngx_conf_set_flag_slot,
|
|
605 NGX_HTTP_LOC_CONF_OFFSET,
|
|
606 offsetof(ngx_http_core_loc_conf_t, chunked_transfer_encoding),
|
|
607 NULL },
|
|
608
|
0
|
609 { ngx_string("error_page"),
|
58
|
610 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
611 |NGX_CONF_2MORE,
|
34
|
612 ngx_http_core_error_page,
|
0
|
613 NGX_HTTP_LOC_CONF_OFFSET,
|
|
614 0,
|
|
615 NULL },
|
|
616
|
430
|
617 { ngx_string("try_files"),
|
464
|
618 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_2MORE,
|
430
|
619 ngx_http_core_try_files,
|
|
620 NGX_HTTP_LOC_CONF_OFFSET,
|
|
621 0,
|
|
622 NULL },
|
|
623
|
126
|
624 { ngx_string("post_action"),
|
|
625 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
626 |NGX_CONF_TAKE1,
|
|
627 ngx_conf_set_str_slot,
|
|
628 NGX_HTTP_LOC_CONF_OFFSET,
|
|
629 offsetof(ngx_http_core_loc_conf_t, post_action),
|
|
630 NULL },
|
|
631
|
0
|
632 { ngx_string("error_log"),
|
|
633 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
34
|
634 ngx_http_core_error_log,
|
0
|
635 NGX_HTTP_LOC_CONF_OFFSET,
|
|
636 0,
|
|
637 NULL },
|
|
638
|
|
639 { ngx_string("open_file_cache"),
|
332
|
640 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
|
|
641 ngx_http_core_open_file_cache,
|
|
642 NGX_HTTP_LOC_CONF_OFFSET,
|
|
643 offsetof(ngx_http_core_loc_conf_t, open_file_cache),
|
|
644 NULL },
|
|
645
|
358
|
646 { ngx_string("open_file_cache_valid"),
|
|
647 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
648 ngx_conf_set_sec_slot,
|
|
649 NGX_HTTP_LOC_CONF_OFFSET,
|
|
650 offsetof(ngx_http_core_loc_conf_t, open_file_cache_valid),
|
|
651 NULL },
|
|
652
|
332
|
653 { ngx_string("open_file_cache_retest"),
|
|
654 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
655 ngx_conf_set_sec_slot,
|
0
|
656 NGX_HTTP_LOC_CONF_OFFSET,
|
358
|
657 offsetof(ngx_http_core_loc_conf_t, open_file_cache_valid),
|
|
658 &ngx_conf_deprecated_open_file_cache_retest },
|
|
659
|
|
660 { ngx_string("open_file_cache_min_uses"),
|
|
661 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
662 ngx_conf_set_num_slot,
|
|
663 NGX_HTTP_LOC_CONF_OFFSET,
|
|
664 offsetof(ngx_http_core_loc_conf_t, open_file_cache_min_uses),
|
0
|
665 NULL },
|
|
666
|
332
|
667 { ngx_string("open_file_cache_errors"),
|
|
668 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
669 ngx_conf_set_flag_slot,
|
|
670 NGX_HTTP_LOC_CONF_OFFSET,
|
|
671 offsetof(ngx_http_core_loc_conf_t, open_file_cache_errors),
|
|
672 NULL },
|
|
673
|
|
674 { ngx_string("open_file_cache_events"),
|
|
675 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
676 ngx_conf_set_flag_slot,
|
|
677 NGX_HTTP_LOC_CONF_OFFSET,
|
|
678 offsetof(ngx_http_core_loc_conf_t, open_file_cache_events),
|
|
679 NULL },
|
0
|
680
|
348
|
681 { ngx_string("resolver"),
|
|
682 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
683 ngx_http_core_resolver,
|
|
684 NGX_HTTP_LOC_CONF_OFFSET,
|
|
685 0,
|
|
686 NULL },
|
|
687
|
|
688 { ngx_string("resolver_timeout"),
|
|
689 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
690 ngx_conf_set_msec_slot,
|
|
691 NGX_HTTP_LOC_CONF_OFFSET,
|
|
692 offsetof(ngx_http_core_loc_conf_t, resolver_timeout),
|
|
693 NULL },
|
|
694
|
358
|
695 #if (NGX_HTTP_GZIP)
|
|
696
|
|
697 { ngx_string("gzip_vary"),
|
|
698 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
699 ngx_conf_set_flag_slot,
|
|
700 NGX_HTTP_LOC_CONF_OFFSET,
|
|
701 offsetof(ngx_http_core_loc_conf_t, gzip_vary),
|
|
702 NULL },
|
|
703
|
|
704 { ngx_string("gzip_http_version"),
|
|
705 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
706 ngx_conf_set_enum_slot,
|
|
707 NGX_HTTP_LOC_CONF_OFFSET,
|
|
708 offsetof(ngx_http_core_loc_conf_t, gzip_http_version),
|
|
709 &ngx_http_gzip_http_version },
|
|
710
|
|
711 { ngx_string("gzip_proxied"),
|
|
712 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
713 ngx_conf_set_bitmask_slot,
|
|
714 NGX_HTTP_LOC_CONF_OFFSET,
|
|
715 offsetof(ngx_http_core_loc_conf_t, gzip_proxied),
|
|
716 &ngx_http_gzip_proxied_mask },
|
|
717
|
|
718 { ngx_string("gzip_disable"),
|
|
719 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
720 ngx_http_gzip_disable,
|
|
721 NGX_HTTP_LOC_CONF_OFFSET,
|
|
722 0,
|
|
723 NULL },
|
|
724
|
|
725 #endif
|
|
726
|
0
|
727 ngx_null_command
|
|
728 };
|
|
729
|
|
730
|
216
|
731 static ngx_http_module_t ngx_http_core_module_ctx = {
|
58
|
732 ngx_http_core_preconfiguration, /* preconfiguration */
|
122
|
733 NULL, /* postconfiguration */
|
0
|
734
|
|
735 ngx_http_core_create_main_conf, /* create main configuration */
|
|
736 ngx_http_core_init_main_conf, /* init main configuration */
|
|
737
|
|
738 ngx_http_core_create_srv_conf, /* create server configuration */
|
|
739 ngx_http_core_merge_srv_conf, /* merge server configuration */
|
|
740
|
|
741 ngx_http_core_create_loc_conf, /* create location configuration */
|
|
742 ngx_http_core_merge_loc_conf /* merge location configuration */
|
|
743 };
|
|
744
|
|
745
|
|
746 ngx_module_t ngx_http_core_module = {
|
58
|
747 NGX_MODULE_V1,
|
0
|
748 &ngx_http_core_module_ctx, /* module context */
|
|
749 ngx_http_core_commands, /* module directives */
|
|
750 NGX_HTTP_MODULE, /* module type */
|
90
|
751 NULL, /* init master */
|
58
|
752 NULL, /* init module */
|
90
|
753 NULL, /* init process */
|
|
754 NULL, /* init thread */
|
|
755 NULL, /* exit thread */
|
|
756 NULL, /* exit process */
|
|
757 NULL, /* exit master */
|
|
758 NGX_MODULE_V1_PADDING
|
0
|
759 };
|
|
760
|
|
761
|
480
|
762 ngx_str_t ngx_http_core_get_method = { 3, (u_char *) "GET " };
|
364
|
763
|
|
764
|
36
|
765 void
|
|
766 ngx_http_handler(ngx_http_request_t *r)
|
0
|
767 {
|
230
|
768 ngx_http_core_main_conf_t *cmcf;
|
|
769
|
32
|
770 r->connection->log->action = NULL;
|
0
|
771
|
|
772 r->connection->unexpected_eof = 0;
|
|
773
|
224
|
774 if (!r->internal) {
|
92
|
775 switch (r->headers_in.connection_type) {
|
|
776 case 0:
|
|
777 if (r->http_version > NGX_HTTP_VERSION_10) {
|
|
778 r->keepalive = 1;
|
|
779 } else {
|
|
780 r->keepalive = 0;
|
|
781 }
|
|
782 break;
|
|
783
|
|
784 case NGX_HTTP_CONNECTION_CLOSE:
|
|
785 r->keepalive = 0;
|
|
786 break;
|
|
787
|
|
788 case NGX_HTTP_CONNECTION_KEEP_ALIVE:
|
0
|
789 r->keepalive = 1;
|
92
|
790 break;
|
|
791 }
|
|
792
|
562
|
793 if (r->keepalive) {
|
|
794
|
|
795 if (r->headers_in.msie6) {
|
|
796 if (r->method == NGX_HTTP_POST) {
|
564
|
797 /*
|
|
798 * MSIE may wait for some time if an response for
|
|
799 * a POST request was sent over a keepalive connection
|
|
800 */
|
|
801 r->keepalive = 0;
|
562
|
802 }
|
|
803
|
|
804 } else if (r->headers_in.safari) {
|
|
805 /*
|
|
806 * Safari may send a POST request to a closed keepalive
|
|
807 * connection and stalls for some time
|
|
808 */
|
|
809 r->keepalive = 0;
|
|
810 }
|
0
|
811 }
|
92
|
812
|
|
813 if (r->headers_in.content_length_n > 0) {
|
|
814 r->lingering_close = 1;
|
|
815
|
|
816 } else {
|
|
817 r->lingering_close = 0;
|
|
818 }
|
236
|
819
|
230
|
820 r->phase_handler = 0;
|
|
821
|
|
822 } else {
|
|
823 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
|
|
824 r->phase_handler = cmcf->phase_engine.server_rewrite_index;
|
|
825 }
|
|
826
|
236
|
827 r->valid_location = 1;
|
546
|
828 #if (NGX_HTTP_GZIP)
|
|
829 r->gzip_tested = 0;
|
|
830 r->gzip_ok = 0;
|
|
831 r->gzip_vary = 0;
|
|
832 #endif
|
236
|
833
|
230
|
834 r->write_event_handler = ngx_http_core_run_phases;
|
34
|
835 ngx_http_core_run_phases(r);
|
0
|
836 }
|
|
837
|
|
838
|
230
|
839 void
|
36
|
840 ngx_http_core_run_phases(ngx_http_request_t *r)
|
0
|
841 {
|
|
842 ngx_int_t rc;
|
230
|
843 ngx_http_phase_handler_t *ph;
|
0
|
844 ngx_http_core_main_conf_t *cmcf;
|
|
845
|
|
846 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
|
|
847
|
230
|
848 ph = cmcf->phase_engine.handlers;
|
|
849
|
|
850 while (ph[r->phase_handler].checker) {
|
|
851
|
|
852 rc = ph[r->phase_handler].checker(r, &ph[r->phase_handler]);
|
|
853
|
|
854 if (rc == NGX_OK) {
|
92
|
855 return;
|
0
|
856 }
|
|
857 }
|
|
858 }
|
|
859
|
|
860
|
36
|
861 ngx_int_t
|
230
|
862 ngx_http_core_generic_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
|
|
863 {
|
|
864 ngx_int_t rc;
|
|
865
|
|
866 /*
|
|
867 * generic phase checker,
|
580
|
868 * used by the post read and pre-access phases
|
230
|
869 */
|
|
870
|
|
871 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
872 "generic phase: %ui", r->phase_handler);
|
|
873
|
|
874 rc = ph->handler(r);
|
|
875
|
|
876 if (rc == NGX_OK) {
|
|
877 r->phase_handler = ph->next;
|
|
878 return NGX_AGAIN;
|
|
879 }
|
|
880
|
|
881 if (rc == NGX_DECLINED) {
|
|
882 r->phase_handler++;
|
|
883 return NGX_AGAIN;
|
|
884 }
|
|
885
|
|
886 if (rc == NGX_AGAIN || rc == NGX_DONE) {
|
|
887 return NGX_OK;
|
|
888 }
|
|
889
|
|
890 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
|
|
891
|
|
892 ngx_http_finalize_request(r, rc);
|
|
893
|
|
894 return NGX_OK;
|
|
895 }
|
|
896
|
|
897
|
|
898 ngx_int_t
|
580
|
899 ngx_http_core_rewrite_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
|
|
900 {
|
|
901 ngx_int_t rc;
|
|
902
|
|
903 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
904 "rewrite phase: %ui", r->phase_handler);
|
|
905
|
|
906 rc = ph->handler(r);
|
|
907
|
|
908 if (rc == NGX_DECLINED) {
|
|
909 r->phase_handler++;
|
|
910 return NGX_AGAIN;
|
|
911 }
|
|
912
|
604
|
913 if (rc == NGX_DONE) {
|
|
914 return NGX_OK;
|
|
915 }
|
|
916
|
|
917 /* NGX_OK, NGX_AGAIN, NGX_ERROR, NGX_HTTP_... */
|
580
|
918
|
|
919 ngx_http_finalize_request(r, rc);
|
|
920
|
|
921 return NGX_OK;
|
|
922 }
|
|
923
|
|
924
|
|
925 ngx_int_t
|
230
|
926 ngx_http_core_find_config_phase(ngx_http_request_t *r,
|
|
927 ngx_http_phase_handler_t *ph)
|
0
|
928 {
|
328
|
929 u_char *p;
|
|
930 size_t len;
|
438
|
931 ngx_int_t rc;
|
0
|
932 ngx_http_core_loc_conf_t *clcf;
|
|
933
|
38
|
934 r->content_handler = NULL;
|
|
935 r->uri_changed = 0;
|
|
936
|
378
|
937 rc = ngx_http_core_find_location(r);
|
0
|
938
|
398
|
939 if (rc == NGX_ERROR) {
|
230
|
940 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
941 return NGX_OK;
|
0
|
942 }
|
|
943
|
|
944 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
945
|
58
|
946 if (!r->internal && clcf->internal) {
|
230
|
947 ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
|
|
948 return NGX_OK;
|
58
|
949 }
|
|
950
|
104
|
951 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
952 "using configuration \"%s%V\"",
|
|
953 (clcf->noname ? "*" : (clcf->exact_match ? "=" : "")),
|
|
954 &clcf->name);
|
|
955
|
84
|
956 ngx_http_update_location_config(r);
|
0
|
957
|
|
958 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
212
|
959 "http cl:%O max:%O",
|
10
|
960 r->headers_in.content_length_n, clcf->client_max_body_size);
|
0
|
961
|
|
962 if (r->headers_in.content_length_n != -1
|
222
|
963 && !r->discard_body
|
0
|
964 && clcf->client_max_body_size
|
212
|
965 && clcf->client_max_body_size < r->headers_in.content_length_n)
|
0
|
966 {
|
|
967 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
342
|
968 "client intended to send too large body: %O bytes",
|
0
|
969 r->headers_in.content_length_n);
|
|
970
|
524
|
971 (void) ngx_http_discard_request_body(r);
|
230
|
972 ngx_http_finalize_request(r, NGX_HTTP_REQUEST_ENTITY_TOO_LARGE);
|
|
973 return NGX_OK;
|
0
|
974 }
|
|
975
|
378
|
976 if (rc == NGX_DONE) {
|
0
|
977 r->headers_out.location = ngx_list_push(&r->headers_out.headers);
|
|
978 if (r->headers_out.location == NULL) {
|
230
|
979 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
980 return NGX_OK;
|
0
|
981 }
|
|
982
|
58
|
983 /*
|
|
984 * we do not need to set the r->headers_out.location->hash and
|
|
985 * r->headers_out.location->key fields
|
|
986 */
|
|
987
|
328
|
988 if (r->args.len == 0) {
|
|
989 r->headers_out.location->value = clcf->name;
|
|
990
|
|
991 } else {
|
|
992 len = clcf->name.len + 1 + r->args.len;
|
382
|
993 p = ngx_pnalloc(r->pool, len);
|
328
|
994
|
|
995 if (p == NULL) {
|
|
996 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
997 return NGX_OK;
|
|
998 }
|
|
999
|
|
1000 r->headers_out.location->value.len = len;
|
|
1001 r->headers_out.location->value.data = p;
|
|
1002
|
|
1003 p = ngx_cpymem(p, clcf->name.data, clcf->name.len);
|
|
1004 *p++ = '?';
|
|
1005 ngx_memcpy(p, r->args.data, r->args.len);
|
|
1006 }
|
0
|
1007
|
230
|
1008 ngx_http_finalize_request(r, NGX_HTTP_MOVED_PERMANENTLY);
|
|
1009 return NGX_OK;
|
|
1010 }
|
|
1011
|
|
1012 r->phase_handler++;
|
|
1013 return NGX_AGAIN;
|
|
1014 }
|
|
1015
|
|
1016
|
|
1017 ngx_int_t
|
|
1018 ngx_http_core_post_rewrite_phase(ngx_http_request_t *r,
|
|
1019 ngx_http_phase_handler_t *ph)
|
|
1020 {
|
380
|
1021 ngx_http_core_srv_conf_t *cscf;
|
|
1022
|
230
|
1023 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1024 "post rewrite phase: %ui", r->phase_handler);
|
|
1025
|
|
1026 if (!r->uri_changed) {
|
|
1027 r->phase_handler++;
|
|
1028 return NGX_AGAIN;
|
|
1029 }
|
|
1030
|
|
1031 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1032 "uri changes: %d", r->uri_changes);
|
|
1033
|
|
1034 /*
|
|
1035 * gcc before 3.3 compiles the broken code for
|
|
1036 * if (r->uri_changes-- == 0)
|
|
1037 * if the r->uri_changes is defined as
|
|
1038 * unsigned uri_changes:4
|
|
1039 */
|
|
1040
|
|
1041 r->uri_changes--;
|
|
1042
|
|
1043 if (r->uri_changes == 0) {
|
|
1044 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1045 "rewrite or internal redirection cycle "
|
|
1046 "while processing \"%V\"", &r->uri);
|
|
1047
|
|
1048 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
1049 return NGX_OK;
|
|
1050 }
|
|
1051
|
|
1052 r->phase_handler = ph->next;
|
|
1053
|
380
|
1054 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
|
1055 r->loc_conf = cscf->ctx->loc_conf;
|
|
1056
|
230
|
1057 return NGX_AGAIN;
|
|
1058 }
|
|
1059
|
|
1060
|
|
1061 ngx_int_t
|
|
1062 ngx_http_core_access_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
|
|
1063 {
|
|
1064 ngx_int_t rc;
|
|
1065 ngx_http_core_loc_conf_t *clcf;
|
|
1066
|
|
1067 if (r != r->main) {
|
|
1068 r->phase_handler = ph->next;
|
|
1069 return NGX_AGAIN;
|
|
1070 }
|
|
1071
|
|
1072 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1073 "access phase: %ui", r->phase_handler);
|
|
1074
|
|
1075 rc = ph->handler(r);
|
|
1076
|
|
1077 if (rc == NGX_DECLINED) {
|
|
1078 r->phase_handler++;
|
|
1079 return NGX_AGAIN;
|
|
1080 }
|
|
1081
|
|
1082 if (rc == NGX_AGAIN || rc == NGX_DONE) {
|
|
1083 return NGX_OK;
|
0
|
1084 }
|
|
1085
|
230
|
1086 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1087
|
362
|
1088 if (clcf->satisfy == NGX_HTTP_SATISFY_ALL) {
|
230
|
1089
|
|
1090 if (rc == NGX_OK) {
|
|
1091 r->phase_handler++;
|
|
1092 return NGX_AGAIN;
|
|
1093 }
|
|
1094
|
|
1095 } else {
|
|
1096 if (rc == NGX_OK) {
|
|
1097 r->access_code = 0;
|
|
1098
|
|
1099 if (r->headers_out.www_authenticate) {
|
|
1100 r->headers_out.www_authenticate->hash = 0;
|
|
1101 }
|
|
1102
|
|
1103 r->phase_handler = ph->next;
|
|
1104 return NGX_AGAIN;
|
|
1105 }
|
|
1106
|
|
1107 if (rc == NGX_HTTP_FORBIDDEN || rc == NGX_HTTP_UNAUTHORIZED) {
|
|
1108 r->access_code = rc;
|
|
1109
|
|
1110 r->phase_handler++;
|
|
1111 return NGX_AGAIN;
|
|
1112 }
|
|
1113 }
|
|
1114
|
|
1115 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
|
|
1116
|
|
1117 ngx_http_finalize_request(r, rc);
|
|
1118 return NGX_OK;
|
|
1119 }
|
|
1120
|
|
1121
|
|
1122 ngx_int_t
|
|
1123 ngx_http_core_post_access_phase(ngx_http_request_t *r,
|
|
1124 ngx_http_phase_handler_t *ph)
|
|
1125 {
|
|
1126 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1127 "post access phase: %ui", r->phase_handler);
|
|
1128
|
|
1129 if (r->access_code) {
|
|
1130
|
|
1131 if (r->access_code == NGX_HTTP_FORBIDDEN) {
|
|
1132 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1133 "access forbidden by rule");
|
|
1134 }
|
|
1135
|
|
1136 ngx_http_finalize_request(r, r->access_code);
|
|
1137 return NGX_OK;
|
|
1138 }
|
|
1139
|
|
1140 r->phase_handler++;
|
|
1141 return NGX_AGAIN;
|
|
1142 }
|
|
1143
|
|
1144
|
|
1145 ngx_int_t
|
430
|
1146 ngx_http_core_try_files_phase(ngx_http_request_t *r,
|
|
1147 ngx_http_phase_handler_t *ph)
|
|
1148 {
|
442
|
1149 size_t len, root, alias, reserve, allocated;
|
430
|
1150 u_char *p, *name;
|
464
|
1151 ngx_str_t path, args;
|
440
|
1152 ngx_uint_t test_dir;
|
430
|
1153 ngx_http_try_file_t *tf;
|
|
1154 ngx_open_file_info_t of;
|
|
1155 ngx_http_script_code_pt code;
|
|
1156 ngx_http_script_engine_t e;
|
|
1157 ngx_http_core_loc_conf_t *clcf;
|
|
1158 ngx_http_script_len_code_pt lcode;
|
|
1159
|
|
1160 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1161 "try files phase: %ui", r->phase_handler);
|
|
1162
|
|
1163 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1164
|
|
1165 if (clcf->try_files == NULL) {
|
|
1166 r->phase_handler++;
|
|
1167 return NGX_AGAIN;
|
|
1168 }
|
|
1169
|
|
1170 allocated = 0;
|
|
1171 root = 0;
|
|
1172 name = NULL;
|
442
|
1173 /* suppress MSVC warning */
|
430
|
1174 path.data = NULL;
|
|
1175
|
|
1176 tf = clcf->try_files;
|
|
1177
|
574
|
1178 alias = clcf->alias;
|
430
|
1179
|
|
1180 for ( ;; ) {
|
|
1181
|
|
1182 if (tf->lengths) {
|
|
1183 ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
|
|
1184
|
|
1185 e.ip = tf->lengths->elts;
|
|
1186 e.request = r;
|
|
1187
|
|
1188 /* 1 is for terminating '\0' as in static names */
|
|
1189 len = 1;
|
|
1190
|
|
1191 while (*(uintptr_t *) e.ip) {
|
|
1192 lcode = *(ngx_http_script_len_code_pt *) e.ip;
|
|
1193 len += lcode(&e);
|
|
1194 }
|
|
1195
|
|
1196 } else {
|
|
1197 len = tf->name.len;
|
|
1198 }
|
|
1199
|
|
1200 /* 16 bytes are preallocation */
|
454
|
1201 reserve = ngx_abs((ssize_t) (len - r->uri.len)) + alias + 16;
|
430
|
1202
|
|
1203 if (reserve > allocated) {
|
|
1204
|
|
1205 /* we just need to allocate path and to copy a root */
|
|
1206
|
|
1207 if (ngx_http_map_uri_to_path(r, &path, &root, reserve) == NULL) {
|
|
1208 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
1209 return NGX_OK;
|
|
1210 }
|
|
1211
|
|
1212 name = path.data + root;
|
|
1213 allocated = path.len - root - (r->uri.len - alias);
|
|
1214 }
|
|
1215
|
|
1216 if (tf->values == NULL) {
|
|
1217
|
|
1218 /* tf->name.len includes the terminating '\0' */
|
|
1219
|
|
1220 ngx_memcpy(name, tf->name.data, tf->name.len);
|
|
1221
|
|
1222 path.len = (name + tf->name.len - 1) - path.data;
|
|
1223
|
|
1224 } else {
|
|
1225 e.ip = tf->values->elts;
|
|
1226 e.pos = name;
|
434
|
1227 e.flushed = 1;
|
430
|
1228
|
|
1229 while (*(uintptr_t *) e.ip) {
|
|
1230 code = *(ngx_http_script_code_pt *) e.ip;
|
|
1231 code((ngx_http_script_engine_t *) &e);
|
|
1232 }
|
|
1233
|
|
1234 path.len = e.pos - path.data;
|
|
1235
|
460
|
1236 *e.pos = '\0';
|
430
|
1237
|
|
1238 if (alias && ngx_strncmp(name, clcf->name.data, alias) == 0) {
|
|
1239 ngx_memcpy(name, name + alias, len - alias);
|
|
1240 path.len -= alias;
|
|
1241 }
|
|
1242 }
|
|
1243
|
440
|
1244 test_dir = tf->test_dir;
|
|
1245
|
430
|
1246 tf++;
|
|
1247
|
574
|
1248 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1249 "try to use %s: \"%s\" \"%s\"",
|
|
1250 test_dir ? "dir" : "file", name, path.data);
|
430
|
1251
|
|
1252 if (tf->lengths == NULL && tf->name.len == 0) {
|
|
1253
|
478
|
1254 if (tf->code) {
|
|
1255 ngx_http_finalize_request(r, tf->code);
|
|
1256 return NGX_OK;
|
|
1257 }
|
|
1258
|
430
|
1259 path.len -= root;
|
|
1260 path.data += root;
|
|
1261
|
|
1262 if (path.data[0] == '@') {
|
|
1263 (void) ngx_http_named_location(r, &path);
|
|
1264
|
|
1265 } else {
|
464
|
1266 ngx_http_split_args(r, &path, &args);
|
|
1267
|
|
1268 (void) ngx_http_internal_redirect(r, &path, &args);
|
430
|
1269 }
|
|
1270
|
520
|
1271 ngx_http_finalize_request(r, NGX_DONE);
|
430
|
1272 return NGX_OK;
|
|
1273 }
|
|
1274
|
|
1275 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
|
|
1276
|
|
1277 of.directio = clcf->directio;
|
|
1278 of.valid = clcf->open_file_cache_valid;
|
|
1279 of.min_uses = clcf->open_file_cache_min_uses;
|
482
|
1280 of.test_only = 1;
|
430
|
1281 of.errors = clcf->open_file_cache_errors;
|
|
1282 of.events = clcf->open_file_cache_events;
|
|
1283
|
|
1284 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
|
|
1285 != NGX_OK)
|
|
1286 {
|
530
|
1287 if (of.err != NGX_ENOENT
|
|
1288 && of.err != NGX_ENOTDIR
|
|
1289 && of.err != NGX_ENAMETOOLONG)
|
|
1290 {
|
430
|
1291 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
|
482
|
1292 "%s \"%s\" failed", of.failed, path.data);
|
430
|
1293 }
|
|
1294
|
|
1295 continue;
|
|
1296 }
|
|
1297
|
440
|
1298 if (of.is_dir && !test_dir) {
|
438
|
1299 continue;
|
|
1300 }
|
|
1301
|
430
|
1302 path.len -= root;
|
|
1303 path.data += root;
|
|
1304
|
|
1305 if (!alias) {
|
|
1306 r->uri = path;
|
|
1307
|
574
|
1308 #if (NGX_PCRE)
|
|
1309 } else if (clcf->regex) {
|
|
1310 if (!test_dir) {
|
|
1311 r->uri = path;
|
|
1312 r->add_uri_to_alias = 1;
|
|
1313 }
|
|
1314 #endif
|
430
|
1315 } else {
|
|
1316 r->uri.len = alias + path.len;
|
|
1317 r->uri.data = ngx_pnalloc(r->pool, r->uri.len);
|
|
1318 if (r->uri.data == NULL) {
|
|
1319 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
1320 return NGX_OK;
|
|
1321 }
|
|
1322
|
|
1323 p = ngx_copy(r->uri.data, clcf->name.data, alias);
|
|
1324 ngx_memcpy(p, name, path.len);
|
|
1325 }
|
|
1326
|
508
|
1327 ngx_http_set_exten(r);
|
446
|
1328
|
430
|
1329 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1330 "try file uri: \"%V\"", &r->uri);
|
|
1331
|
|
1332 r->phase_handler++;
|
|
1333 return NGX_AGAIN;
|
|
1334 }
|
|
1335
|
|
1336 /* not reached */
|
|
1337 }
|
|
1338
|
|
1339
|
|
1340 ngx_int_t
|
230
|
1341 ngx_http_core_content_phase(ngx_http_request_t *r,
|
|
1342 ngx_http_phase_handler_t *ph)
|
|
1343 {
|
248
|
1344 size_t root;
|
230
|
1345 ngx_int_t rc;
|
|
1346 ngx_str_t path;
|
|
1347
|
|
1348 if (r->content_handler) {
|
|
1349 r->write_event_handler = ngx_http_request_empty_handler;
|
|
1350 ngx_http_finalize_request(r, r->content_handler(r));
|
|
1351 return NGX_OK;
|
|
1352 }
|
|
1353
|
|
1354 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1355 "content phase: %ui", r->phase_handler);
|
|
1356
|
|
1357 rc = ph->handler(r);
|
|
1358
|
|
1359 if (rc != NGX_DECLINED) {
|
|
1360 ngx_http_finalize_request(r, rc);
|
|
1361 return NGX_OK;
|
|
1362 }
|
|
1363
|
|
1364 /* rc == NGX_DECLINED */
|
|
1365
|
|
1366 ph++;
|
|
1367
|
|
1368 if (ph->checker) {
|
|
1369 r->phase_handler++;
|
|
1370 return NGX_AGAIN;
|
|
1371 }
|
|
1372
|
|
1373 /* no content handler was found */
|
|
1374
|
572
|
1375 if (r->uri.data[r->uri.len - 1] == '/') {
|
230
|
1376
|
248
|
1377 if (ngx_http_map_uri_to_path(r, &path, &root, 0) != NULL) {
|
230
|
1378 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
340
|
1379 "directory index of \"%s\" is forbidden", path.data);
|
230
|
1380 }
|
|
1381
|
|
1382 ngx_http_finalize_request(r, NGX_HTTP_FORBIDDEN);
|
|
1383 return NGX_OK;
|
|
1384 }
|
|
1385
|
|
1386 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no handler found");
|
|
1387
|
|
1388 ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
|
84
|
1389 return NGX_OK;
|
|
1390 }
|
|
1391
|
|
1392
|
|
1393 void
|
|
1394 ngx_http_update_location_config(ngx_http_request_t *r)
|
|
1395 {
|
|
1396 ngx_http_core_loc_conf_t *clcf;
|
|
1397
|
|
1398 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1399
|
180
|
1400 if (r->method & clcf->limit_except) {
|
|
1401 r->loc_conf = clcf->limit_except_loc_conf;
|
|
1402 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1403 }
|
|
1404
|
192
|
1405 if (r == r->main) {
|
484
|
1406 r->connection->log->file = clcf->error_log->file;
|
294
|
1407
|
192
|
1408 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
|
484
|
1409 r->connection->log->log_level = clcf->error_log->log_level;
|
192
|
1410 }
|
84
|
1411 }
|
|
1412
|
|
1413 if ((ngx_io.flags & NGX_IO_SENDFILE) && clcf->sendfile) {
|
|
1414 r->connection->sendfile = 1;
|
|
1415
|
|
1416 } else {
|
|
1417 r->connection->sendfile = 0;
|
|
1418 }
|
|
1419
|
182
|
1420 if (clcf->client_body_in_file_only) {
|
|
1421 r->request_body_in_file_only = 1;
|
|
1422 r->request_body_in_persistent_file = 1;
|
278
|
1423 r->request_body_in_clean_file =
|
|
1424 clcf->client_body_in_file_only == NGX_HTTP_REQUEST_BODY_FILE_CLEAN;
|
186
|
1425 r->request_body_file_log_level = NGX_LOG_NOTICE;
|
|
1426
|
|
1427 } else {
|
|
1428 r->request_body_file_log_level = NGX_LOG_WARN;
|
182
|
1429 }
|
|
1430
|
492
|
1431 r->request_body_in_single_buf = clcf->client_body_in_single_buffer;
|
|
1432
|
496
|
1433 if (r->keepalive) {
|
|
1434 if (clcf->keepalive_timeout == 0) {
|
|
1435 r->keepalive = 0;
|
|
1436
|
|
1437 } else if (r->connection->requests >= clcf->keepalive_requests) {
|
|
1438 r->keepalive = 0;
|
|
1439 }
|
84
|
1440 }
|
|
1441
|
|
1442 if (!clcf->tcp_nopush) {
|
|
1443 /* disable TCP_NOPUSH/TCP_CORK use */
|
|
1444 r->connection->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;
|
|
1445 }
|
|
1446
|
162
|
1447 if (r->limit_rate == 0) {
|
|
1448 r->limit_rate = clcf->limit_rate;
|
|
1449 }
|
76
|
1450
|
0
|
1451 if (clcf->handler) {
|
|
1452 r->content_handler = clcf->handler;
|
|
1453 }
|
|
1454 }
|
|
1455
|
|
1456
|
398
|
1457 /*
|
|
1458 * NGX_OK - exact or regex match
|
|
1459 * NGX_DONE - auto redirect
|
|
1460 * NGX_AGAIN - inclusive match
|
|
1461 * NGX_ERROR - regex error
|
|
1462 * NGX_DECLINED - no match
|
|
1463 */
|
|
1464
|
36
|
1465 static ngx_int_t
|
378
|
1466 ngx_http_core_find_location(ngx_http_request_t *r)
|
0
|
1467 {
|
378
|
1468 ngx_int_t rc;
|
|
1469 ngx_http_core_loc_conf_t *pclcf;
|
398
|
1470 #if (NGX_PCRE)
|
546
|
1471 ngx_int_t n;
|
398
|
1472 ngx_uint_t noregex;
|
|
1473 ngx_http_core_loc_conf_t *clcf, **clcfp;
|
|
1474
|
|
1475 noregex = 0;
|
|
1476 #endif
|
378
|
1477
|
|
1478 pclcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1479
|
|
1480 rc = ngx_http_core_find_static_location(r, pclcf->static_locations);
|
|
1481
|
|
1482 if (rc == NGX_AGAIN) {
|
398
|
1483
|
|
1484 #if (NGX_PCRE)
|
|
1485 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1486
|
|
1487 noregex = clcf->noregex;
|
|
1488 #endif
|
|
1489
|
378
|
1490 /* look up nested locations */
|
398
|
1491
|
378
|
1492 rc = ngx_http_core_find_location(r);
|
|
1493 }
|
|
1494
|
|
1495 if (rc == NGX_OK || rc == NGX_DONE) {
|
|
1496 return rc;
|
|
1497 }
|
|
1498
|
|
1499 /* rc == NGX_DECLINED or rc == NGX_AGAIN in nested location */
|
|
1500
|
|
1501 #if (NGX_PCRE)
|
398
|
1502
|
|
1503 if (noregex == 0 && pclcf->regex_locations) {
|
378
|
1504
|
|
1505 for (clcfp = pclcf->regex_locations; *clcfp; clcfp++) {
|
|
1506
|
|
1507 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1508 "test location: ~ \"%V\"", &(*clcfp)->name);
|
|
1509
|
546
|
1510 n = ngx_http_regex_exec(r, (*clcfp)->regex, &r->uri);
|
|
1511
|
|
1512 if (n == NGX_OK) {
|
|
1513 r->loc_conf = (*clcfp)->loc_conf;
|
|
1514
|
|
1515 /* look up nested locations */
|
|
1516
|
|
1517 rc = ngx_http_core_find_location(r);
|
|
1518
|
|
1519 return (rc == NGX_ERROR) ? rc : NGX_OK;
|
456
|
1520 }
|
|
1521
|
546
|
1522 if (n == NGX_DECLINED) {
|
378
|
1523 continue;
|
|
1524 }
|
|
1525
|
546
|
1526 return NGX_ERROR;
|
378
|
1527 }
|
|
1528 }
|
326
|
1529 #endif
|
0
|
1530
|
378
|
1531 return rc;
|
|
1532 }
|
|
1533
|
|
1534
|
|
1535 /*
|
|
1536 * NGX_OK - exact match
|
|
1537 * NGX_DONE - auto redirect
|
|
1538 * NGX_AGAIN - inclusive match
|
|
1539 * NGX_DECLINED - no match
|
|
1540 */
|
|
1541
|
|
1542 static ngx_int_t
|
|
1543 ngx_http_core_find_static_location(ngx_http_request_t *r,
|
|
1544 ngx_http_location_tree_node_t *node)
|
|
1545 {
|
|
1546 u_char *uri;
|
|
1547 size_t len, n;
|
|
1548 ngx_int_t rc, rv;
|
|
1549
|
|
1550 len = r->uri.len;
|
|
1551 uri = r->uri.data;
|
|
1552
|
|
1553 rv = NGX_DECLINED;
|
|
1554
|
|
1555 for ( ;; ) {
|
|
1556
|
|
1557 if (node == NULL) {
|
|
1558 return rv;
|
34
|
1559 }
|
|
1560
|
0
|
1561 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
378
|
1562 "test location: \"%*s\"", node->len, node->name);
|
|
1563
|
|
1564 n = (len <= (size_t) node->len) ? len : node->len;
|
|
1565
|
390
|
1566 rc = ngx_filename_cmp(uri, node->name, n);
|
378
|
1567
|
|
1568 if (rc != 0) {
|
|
1569 node = (rc < 0) ? node->left : node->right;
|
|
1570
|
0
|
1571 continue;
|
|
1572 }
|
|
1573
|
378
|
1574 if (len > (size_t) node->len) {
|
|
1575
|
|
1576 if (node->inclusive) {
|
|
1577
|
|
1578 r->loc_conf = node->inclusive->loc_conf;
|
|
1579 rv = NGX_AGAIN;
|
|
1580
|
|
1581 node = node->tree;
|
|
1582 uri += n;
|
|
1583 len -= n;
|
34
|
1584
|
|
1585 continue;
|
0
|
1586 }
|
|
1587
|
378
|
1588 /* exact only */
|
|
1589
|
|
1590 node = node->right;
|
|
1591
|
0
|
1592 continue;
|
|
1593 }
|
|
1594
|
378
|
1595 if (len == (size_t) node->len) {
|
|
1596
|
580
|
1597 if (node->exact) {
|
|
1598 r->loc_conf = node->exact->loc_conf;
|
|
1599 return NGX_OK;
|
|
1600
|
|
1601 } else {
|
|
1602 r->loc_conf = node->inclusive->loc_conf;
|
|
1603 return NGX_AGAIN;
|
|
1604 }
|
0
|
1605 }
|
|
1606
|
378
|
1607 /* len < node->len */
|
|
1608
|
|
1609 if (len + 1 == (size_t) node->len && node->auto_redirect) {
|
|
1610
|
|
1611 r->loc_conf = (node->exact) ? node->exact->loc_conf:
|
|
1612 node->inclusive->loc_conf;
|
|
1613 rv = NGX_DONE;
|
|
1614 }
|
|
1615
|
|
1616 node = node->left;
|
0
|
1617 }
|
|
1618 }
|
|
1619
|
|
1620
|
392
|
1621 void *
|
|
1622 ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash)
|
|
1623 {
|
494
|
1624 u_char c, *lowcase;
|
|
1625 size_t len;
|
|
1626 ngx_uint_t i, hash;
|
392
|
1627
|
554
|
1628 if (types_hash->size == 0) {
|
|
1629 return (void *) 4;
|
|
1630 }
|
|
1631
|
392
|
1632 if (r->headers_out.content_type.len == 0) {
|
|
1633 return NULL;
|
|
1634 }
|
|
1635
|
494
|
1636 len = r->headers_out.content_type_len;
|
|
1637
|
392
|
1638 if (r->headers_out.content_type_lowcase == NULL) {
|
|
1639
|
494
|
1640 lowcase = ngx_pnalloc(r->pool, len);
|
|
1641 if (lowcase == NULL) {
|
392
|
1642 return NULL;
|
|
1643 }
|
|
1644
|
494
|
1645 r->headers_out.content_type_lowcase = lowcase;
|
392
|
1646
|
|
1647 hash = 0;
|
|
1648
|
494
|
1649 for (i = 0; i < len; i++) {
|
392
|
1650 c = ngx_tolower(r->headers_out.content_type.data[i]);
|
|
1651 hash = ngx_hash(hash, c);
|
494
|
1652 lowcase[i] = c;
|
392
|
1653 }
|
|
1654
|
|
1655 r->headers_out.content_type_hash = hash;
|
|
1656 }
|
|
1657
|
494
|
1658 return ngx_hash_find(types_hash, r->headers_out.content_type_hash,
|
|
1659 r->headers_out.content_type_lowcase, len);
|
392
|
1660 }
|
|
1661
|
|
1662
|
36
|
1663 ngx_int_t
|
|
1664 ngx_http_set_content_type(ngx_http_request_t *r)
|
0
|
1665 {
|
392
|
1666 u_char c, *exten;
|
138
|
1667 ngx_str_t *type;
|
198
|
1668 ngx_uint_t i, hash;
|
0
|
1669 ngx_http_core_loc_conf_t *clcf;
|
|
1670
|
222
|
1671 if (r->headers_out.content_type.len) {
|
|
1672 return NGX_OK;
|
|
1673 }
|
|
1674
|
0
|
1675 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1676
|
|
1677 if (r->exten.len) {
|
34
|
1678
|
198
|
1679 hash = 0;
|
|
1680
|
|
1681 for (i = 0; i < r->exten.len; i++) {
|
|
1682 c = r->exten.data[i];
|
|
1683
|
|
1684 if (c >= 'A' && c <= 'Z') {
|
|
1685
|
392
|
1686 exten = ngx_pnalloc(r->pool, r->exten.len);
|
|
1687 if (exten == NULL) {
|
454
|
1688 return NGX_ERROR;
|
34
|
1689 }
|
|
1690
|
392
|
1691 hash = ngx_hash_strlow(exten, r->exten.data, r->exten.len);
|
34
|
1692
|
|
1693 r->exten.data = exten;
|
198
|
1694
|
|
1695 break;
|
34
|
1696 }
|
|
1697
|
198
|
1698 hash = ngx_hash(hash, c);
|
34
|
1699 }
|
|
1700
|
198
|
1701 type = ngx_hash_find(&clcf->types_hash, hash,
|
138
|
1702 r->exten.data, r->exten.len);
|
|
1703
|
|
1704 if (type) {
|
206
|
1705 r->headers_out.content_type_len = type->len;
|
138
|
1706 r->headers_out.content_type = *type;
|
206
|
1707
|
138
|
1708 return NGX_OK;
|
0
|
1709 }
|
|
1710 }
|
|
1711
|
206
|
1712 r->headers_out.content_type_len = clcf->default_type.len;
|
138
|
1713 r->headers_out.content_type = clcf->default_type;
|
0
|
1714
|
|
1715 return NGX_OK;
|
|
1716 }
|
|
1717
|
|
1718
|
508
|
1719 void
|
36
|
1720 ngx_http_set_exten(ngx_http_request_t *r)
|
0
|
1721 {
|
|
1722 ngx_int_t i;
|
|
1723
|
570
|
1724 ngx_str_null(&r->exten);
|
0
|
1725
|
|
1726 for (i = r->uri.len - 1; i > 1; i--) {
|
|
1727 if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {
|
198
|
1728
|
0
|
1729 r->exten.len = r->uri.len - i - 1;
|
198
|
1730 r->exten.data = &r->uri.data[i + 1];
|
0
|
1731
|
508
|
1732 return;
|
0
|
1733
|
|
1734 } else if (r->uri.data[i] == '/') {
|
508
|
1735 return;
|
0
|
1736 }
|
|
1737 }
|
|
1738
|
508
|
1739 return;
|
0
|
1740 }
|
|
1741
|
|
1742
|
36
|
1743 ngx_int_t
|
580
|
1744 ngx_http_send_response(ngx_http_request_t *r, ngx_uint_t status,
|
|
1745 ngx_str_t *ct, ngx_http_complex_value_t *cv)
|
|
1746 {
|
|
1747 ngx_int_t rc;
|
|
1748 ngx_str_t val;
|
|
1749 ngx_buf_t *b;
|
|
1750 ngx_chain_t out;
|
|
1751
|
|
1752 r->headers_out.status = status;
|
|
1753
|
|
1754 if (status == NGX_HTTP_NO_CONTENT) {
|
582
|
1755 r->header_only = 1;
|
580
|
1756 return ngx_http_send_header(r);
|
|
1757 }
|
|
1758
|
|
1759 if (ngx_http_complex_value(r, cv, &val) != NGX_OK) {
|
|
1760 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
1761 }
|
|
1762
|
|
1763 if (status >= NGX_HTTP_MOVED_PERMANENTLY && status <= NGX_HTTP_SEE_OTHER) {
|
|
1764
|
|
1765 r->headers_out.location = ngx_list_push(&r->headers_out.headers);
|
|
1766 if (r->headers_out.location == NULL) {
|
|
1767 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
1768 }
|
|
1769
|
|
1770 r->headers_out.location->hash = 1;
|
|
1771 ngx_str_set(&r->headers_out.location->key, "Location");
|
|
1772 r->headers_out.location->value = val;
|
|
1773
|
|
1774 return status;
|
|
1775 }
|
|
1776
|
|
1777 r->headers_out.content_length_n = val.len;
|
|
1778
|
|
1779 if (ct) {
|
|
1780 r->headers_out.content_type_len = ct->len;
|
|
1781 r->headers_out.content_type = *ct;
|
|
1782
|
|
1783 } else {
|
|
1784 if (ngx_http_set_content_type(r) != NGX_OK) {
|
|
1785 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
1786 }
|
|
1787 }
|
|
1788
|
|
1789 if (r->method == NGX_HTTP_HEAD || (r != r->main && val.len == 0)) {
|
|
1790 return ngx_http_send_header(r);
|
|
1791 }
|
|
1792
|
|
1793 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
|
|
1794 if (b == NULL) {
|
|
1795 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
1796 }
|
|
1797
|
|
1798 b->pos = val.data;
|
|
1799 b->last = val.data + val.len;
|
|
1800 b->memory = val.len ? 1 : 0;
|
|
1801 b->last_buf = (r == r->main) ? 1 : 0;
|
|
1802 b->last_in_chain = 1;
|
|
1803
|
|
1804 out.buf = b;
|
|
1805 out.next = NULL;
|
|
1806
|
|
1807 rc = ngx_http_send_header(r);
|
|
1808
|
|
1809 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
|
|
1810 return rc;
|
|
1811 }
|
|
1812
|
|
1813 return ngx_http_output_filter(r, &out);
|
|
1814 }
|
|
1815
|
|
1816
|
|
1817 ngx_int_t
|
106
|
1818 ngx_http_send_header(ngx_http_request_t *r)
|
|
1819 {
|
|
1820 if (r->err_status) {
|
|
1821 r->headers_out.status = r->err_status;
|
|
1822 r->headers_out.status_line.len = 0;
|
|
1823 }
|
|
1824
|
|
1825 return ngx_http_top_header_filter(r);
|
|
1826 }
|
|
1827
|
|
1828
|
|
1829 ngx_int_t
|
|
1830 ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
|
1831 {
|
488
|
1832 ngx_int_t rc;
|
|
1833 ngx_connection_t *c;
|
|
1834
|
|
1835 c = r->connection;
|
|
1836
|
|
1837 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
132
|
1838 "http output filter \"%V?%V\"", &r->uri, &r->args);
|
106
|
1839
|
|
1840 rc = ngx_http_top_body_filter(r, in);
|
|
1841
|
|
1842 if (rc == NGX_ERROR) {
|
|
1843 /* NGX_ERROR may be returned by any filter */
|
488
|
1844 c->error = 1;
|
106
|
1845 }
|
|
1846
|
|
1847 return rc;
|
|
1848 }
|
|
1849
|
|
1850
|
|
1851 u_char *
|
|
1852 ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,
|
248
|
1853 size_t *root_length, size_t reserved)
|
106
|
1854 {
|
172
|
1855 u_char *last;
|
|
1856 size_t alias;
|
|
1857 ngx_http_core_loc_conf_t *clcf;
|
106
|
1858
|
|
1859 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1860
|
574
|
1861 alias = clcf->alias;
|
106
|
1862
|
152
|
1863 if (alias && !r->valid_location) {
|
|
1864 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
|
1865 "\"alias\" could not be used in location \"%V\" "
|
|
1866 "where URI was rewritten", &clcf->name);
|
|
1867 return NULL;
|
|
1868 }
|
|
1869
|
144
|
1870 if (clcf->root_lengths == NULL) {
|
|
1871
|
248
|
1872 *root_length = clcf->root.len;
|
144
|
1873
|
460
|
1874 path->len = clcf->root.len + reserved + r->uri.len - alias + 1;
|
144
|
1875
|
382
|
1876 path->data = ngx_pnalloc(r->pool, path->len);
|
144
|
1877 if (path->data == NULL) {
|
|
1878 return NULL;
|
|
1879 }
|
|
1880
|
|
1881 last = ngx_copy(path->data, clcf->root.data, clcf->root.len);
|
172
|
1882
|
|
1883 } else {
|
468
|
1884
|
|
1885 #if (NGX_PCRE)
|
|
1886 ngx_uint_t captures;
|
|
1887
|
546
|
1888 captures = alias && clcf->regex;
|
574
|
1889
|
|
1890 reserved += captures ? r->add_uri_to_alias ? r->uri.len + 1 : 1
|
|
1891 : r->uri.len - alias + 1;
|
468
|
1892 #else
|
|
1893 reserved += r->uri.len - alias + 1;
|
|
1894 #endif
|
462
|
1895
|
|
1896 if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved,
|
220
|
1897 clcf->root_values->elts)
|
216
|
1898 == NULL)
|
|
1899 {
|
|
1900 return NULL;
|
|
1901 }
|
|
1902
|
454
|
1903 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, path, 0) != NGX_OK) {
|
172
|
1904 return NULL;
|
|
1905 }
|
|
1906
|
248
|
1907 *root_length = path->len - reserved;
|
|
1908 last = path->data + *root_length;
|
456
|
1909
|
468
|
1910 #if (NGX_PCRE)
|
|
1911 if (captures) {
|
574
|
1912 if (!r->add_uri_to_alias) {
|
|
1913 *last = '\0';
|
|
1914 return last;
|
|
1915 }
|
|
1916
|
|
1917 alias = 0;
|
456
|
1918 }
|
468
|
1919 #endif
|
144
|
1920 }
|
|
1921
|
172
|
1922 last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1);
|
106
|
1923
|
|
1924 return last;
|
|
1925 }
|
|
1926
|
|
1927
|
|
1928 ngx_int_t
|
88
|
1929 ngx_http_auth_basic_user(ngx_http_request_t *r)
|
|
1930 {
|
|
1931 ngx_str_t auth, encoded;
|
|
1932 ngx_uint_t len;
|
|
1933
|
|
1934 if (r->headers_in.user.len == 0 && r->headers_in.user.data != NULL) {
|
|
1935 return NGX_DECLINED;
|
|
1936 }
|
|
1937
|
|
1938 if (r->headers_in.authorization == NULL) {
|
|
1939 r->headers_in.user.data = (u_char *) "";
|
|
1940 return NGX_DECLINED;
|
|
1941 }
|
|
1942
|
|
1943 encoded = r->headers_in.authorization->value;
|
|
1944
|
|
1945 if (encoded.len < sizeof("Basic ") - 1
|
286
|
1946 || ngx_strncasecmp(encoded.data, (u_char *) "Basic ",
|
|
1947 sizeof("Basic ") - 1)
|
|
1948 != 0)
|
88
|
1949 {
|
|
1950 r->headers_in.user.data = (u_char *) "";
|
|
1951 return NGX_DECLINED;
|
|
1952 }
|
|
1953
|
|
1954 encoded.len -= sizeof("Basic ") - 1;
|
|
1955 encoded.data += sizeof("Basic ") - 1;
|
|
1956
|
|
1957 while (encoded.len && encoded.data[0] == ' ') {
|
|
1958 encoded.len--;
|
|
1959 encoded.data++;
|
|
1960 }
|
|
1961
|
|
1962 if (encoded.len == 0) {
|
|
1963 r->headers_in.user.data = (u_char *) "";
|
|
1964 return NGX_DECLINED;
|
|
1965 }
|
126
|
1966
|
88
|
1967 auth.len = ngx_base64_decoded_length(encoded.len);
|
382
|
1968 auth.data = ngx_pnalloc(r->pool, auth.len + 1);
|
88
|
1969 if (auth.data == NULL) {
|
|
1970 return NGX_ERROR;
|
|
1971 }
|
|
1972
|
|
1973 if (ngx_decode_base64(&auth, &encoded) != NGX_OK) {
|
|
1974 r->headers_in.user.data = (u_char *) "";
|
|
1975 return NGX_DECLINED;
|
|
1976 }
|
126
|
1977
|
88
|
1978 auth.data[auth.len] = '\0';
|
126
|
1979
|
|
1980 for (len = 0; len < auth.len; len++) {
|
88
|
1981 if (auth.data[len] == ':') {
|
|
1982 break;
|
|
1983 }
|
|
1984 }
|
126
|
1985
|
122
|
1986 if (len == 0 || len == auth.len) {
|
88
|
1987 r->headers_in.user.data = (u_char *) "";
|
|
1988 return NGX_DECLINED;
|
|
1989 }
|
|
1990
|
|
1991 r->headers_in.user.len = len;
|
|
1992 r->headers_in.user.data = auth.data;
|
|
1993 r->headers_in.passwd.len = auth.len - len - 1;
|
|
1994 r->headers_in.passwd.data = &auth.data[len + 1];
|
|
1995
|
|
1996 return NGX_OK;
|
|
1997 }
|
|
1998
|
|
1999
|
358
|
2000 #if (NGX_HTTP_GZIP)
|
|
2001
|
|
2002 ngx_int_t
|
|
2003 ngx_http_gzip_ok(ngx_http_request_t *r)
|
|
2004 {
|
|
2005 time_t date, expires;
|
|
2006 ngx_uint_t p;
|
|
2007 ngx_array_t *cc;
|
|
2008 ngx_table_elt_t *e, *d;
|
|
2009 ngx_http_core_loc_conf_t *clcf;
|
|
2010
|
546
|
2011 r->gzip_tested = 1;
|
358
|
2012
|
|
2013 if (r != r->main
|
|
2014 || r->headers_in.accept_encoding == NULL
|
|
2015 || ngx_strcasestrn(r->headers_in.accept_encoding->value.data,
|
|
2016 "gzip", 4 - 1)
|
|
2017 == NULL
|
|
2018
|
|
2019 /*
|
|
2020 * if the URL (without the "http://" prefix) is longer than 253 bytes,
|
|
2021 * then MSIE 4.x can not handle the compressed stream - it waits
|
|
2022 * too long, hangs up or crashes
|
|
2023 */
|
|
2024
|
|
2025 || (r->headers_in.msie4 && r->unparsed_uri.len > 200))
|
|
2026 {
|
|
2027 return NGX_DECLINED;
|
|
2028 }
|
|
2029
|
|
2030 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
2031
|
400
|
2032 if (r->headers_in.msie6 && clcf->gzip_disable_msie6) {
|
|
2033 return NGX_DECLINED;
|
|
2034 }
|
|
2035
|
358
|
2036 if (r->http_version < clcf->gzip_http_version) {
|
|
2037 return NGX_DECLINED;
|
|
2038 }
|
|
2039
|
|
2040 if (r->headers_in.via == NULL) {
|
|
2041 goto ok;
|
|
2042 }
|
|
2043
|
|
2044 p = clcf->gzip_proxied;
|
|
2045
|
|
2046 if (p & NGX_HTTP_GZIP_PROXIED_OFF) {
|
|
2047 return NGX_DECLINED;
|
|
2048 }
|
|
2049
|
|
2050 if (p & NGX_HTTP_GZIP_PROXIED_ANY) {
|
|
2051 goto ok;
|
|
2052 }
|
|
2053
|
|
2054 if (r->headers_in.authorization && (p & NGX_HTTP_GZIP_PROXIED_AUTH)) {
|
|
2055 goto ok;
|
|
2056 }
|
|
2057
|
|
2058 e = r->headers_out.expires;
|
|
2059
|
|
2060 if (e) {
|
|
2061
|
|
2062 if (!(p & NGX_HTTP_GZIP_PROXIED_EXPIRED)) {
|
|
2063 return NGX_DECLINED;
|
|
2064 }
|
|
2065
|
|
2066 expires = ngx_http_parse_time(e->value.data, e->value.len);
|
|
2067 if (expires == NGX_ERROR) {
|
|
2068 return NGX_DECLINED;
|
|
2069 }
|
|
2070
|
|
2071 d = r->headers_out.date;
|
|
2072
|
|
2073 if (d) {
|
|
2074 date = ngx_http_parse_time(d->value.data, d->value.len);
|
|
2075 if (date == NGX_ERROR) {
|
|
2076 return NGX_DECLINED;
|
|
2077 }
|
|
2078
|
|
2079 } else {
|
|
2080 date = ngx_time();
|
|
2081 }
|
|
2082
|
|
2083 if (expires < date) {
|
|
2084 goto ok;
|
|
2085 }
|
|
2086
|
|
2087 return NGX_DECLINED;
|
|
2088 }
|
|
2089
|
|
2090 cc = &r->headers_out.cache_control;
|
|
2091
|
|
2092 if (cc->elts) {
|
|
2093
|
|
2094 if ((p & NGX_HTTP_GZIP_PROXIED_NO_CACHE)
|
|
2095 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_cache,
|
|
2096 NULL)
|
|
2097 >= 0)
|
|
2098 {
|
|
2099 goto ok;
|
|
2100 }
|
|
2101
|
|
2102 if ((p & NGX_HTTP_GZIP_PROXIED_NO_STORE)
|
|
2103 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_store,
|
|
2104 NULL)
|
|
2105 >= 0)
|
|
2106 {
|
|
2107 goto ok;
|
|
2108 }
|
|
2109
|
|
2110 if ((p & NGX_HTTP_GZIP_PROXIED_PRIVATE)
|
|
2111 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_private,
|
|
2112 NULL)
|
|
2113 >= 0)
|
|
2114 {
|
|
2115 goto ok;
|
|
2116 }
|
|
2117
|
|
2118 return NGX_DECLINED;
|
|
2119 }
|
|
2120
|
|
2121 if ((p & NGX_HTTP_GZIP_PROXIED_NO_LM) && r->headers_out.last_modified) {
|
|
2122 return NGX_DECLINED;
|
|
2123 }
|
|
2124
|
|
2125 if ((p & NGX_HTTP_GZIP_PROXIED_NO_ETAG) && r->headers_out.etag) {
|
|
2126 return NGX_DECLINED;
|
|
2127 }
|
|
2128
|
|
2129 ok:
|
|
2130
|
|
2131 #if (NGX_PCRE)
|
|
2132
|
|
2133 if (clcf->gzip_disable && r->headers_in.user_agent) {
|
|
2134
|
362
|
2135 if (ngx_regex_exec_array(clcf->gzip_disable,
|
358
|
2136 &r->headers_in.user_agent->value,
|
|
2137 r->connection->log)
|
|
2138 != NGX_DECLINED)
|
|
2139 {
|
|
2140 return NGX_DECLINED;
|
|
2141 }
|
|
2142 }
|
|
2143
|
|
2144 #endif
|
|
2145
|
546
|
2146 r->gzip_ok = 1;
|
358
|
2147
|
|
2148 return NGX_OK;
|
|
2149 }
|
|
2150
|
|
2151 #endif
|
|
2152
|
|
2153
|
88
|
2154 ngx_int_t
|
58
|
2155 ngx_http_subrequest(ngx_http_request_t *r,
|
244
|
2156 ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **psr,
|
248
|
2157 ngx_http_post_subrequest_t *ps, ngx_uint_t flags)
|
58
|
2158 {
|
590
|
2159 ngx_time_t *tp;
|
132
|
2160 ngx_connection_t *c;
|
58
|
2161 ngx_http_request_t *sr;
|
|
2162 ngx_http_core_srv_conf_t *cscf;
|
|
2163 ngx_http_postponed_request_t *pr, *p;
|
|
2164
|
206
|
2165 r->main->subrequests--;
|
|
2166
|
|
2167 if (r->main->subrequests == 0) {
|
|
2168 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
228
|
2169 "subrequests cycle while processing \"%V\"", uri);
|
256
|
2170 r->main->subrequests = 1;
|
206
|
2171 return NGX_ERROR;
|
|
2172 }
|
|
2173
|
58
|
2174 sr = ngx_pcalloc(r->pool, sizeof(ngx_http_request_t));
|
|
2175 if (sr == NULL) {
|
194
|
2176 return NGX_ERROR;
|
58
|
2177 }
|
|
2178
|
|
2179 sr->signature = NGX_HTTP_MODULE;
|
132
|
2180
|
|
2181 c = r->connection;
|
|
2182 sr->connection = c;
|
58
|
2183
|
|
2184 sr->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
|
|
2185 if (sr->ctx == NULL) {
|
194
|
2186 return NGX_ERROR;
|
58
|
2187 }
|
|
2188
|
|
2189 if (ngx_list_init(&sr->headers_out.headers, r->pool, 20,
|
130
|
2190 sizeof(ngx_table_elt_t))
|
454
|
2191 != NGX_OK)
|
58
|
2192 {
|
194
|
2193 return NGX_ERROR;
|
58
|
2194 }
|
|
2195
|
|
2196 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
|
2197 sr->main_conf = cscf->ctx->main_conf;
|
|
2198 sr->srv_conf = cscf->ctx->srv_conf;
|
|
2199 sr->loc_conf = cscf->ctx->loc_conf;
|
|
2200
|
|
2201 sr->pool = r->pool;
|
|
2202
|
|
2203 sr->headers_in = r->headers_in;
|
|
2204
|
126
|
2205 ngx_http_clear_content_length(sr);
|
|
2206 ngx_http_clear_accept_ranges(sr);
|
|
2207 ngx_http_clear_last_modified(sr);
|
58
|
2208
|
|
2209 sr->request_body = r->request_body;
|
|
2210
|
|
2211 sr->method = NGX_HTTP_GET;
|
|
2212 sr->http_version = r->http_version;
|
|
2213
|
|
2214 sr->request_line = r->request_line;
|
|
2215 sr->uri = *uri;
|
122
|
2216
|
58
|
2217 if (args) {
|
|
2218 sr->args = *args;
|
|
2219 }
|
122
|
2220
|
132
|
2221 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
|
2222 "http subrequest \"%V?%V\"", uri, &sr->args);
|
|
2223
|
248
|
2224 sr->subrequest_in_memory = (flags & NGX_HTTP_SUBREQUEST_IN_MEMORY) != 0;
|
426
|
2225 sr->waited = (flags & NGX_HTTP_SUBREQUEST_WAITED) != 0;
|
122
|
2226
|
58
|
2227 sr->unparsed_uri = r->unparsed_uri;
|
364
|
2228 sr->method_name = ngx_http_core_get_method;
|
58
|
2229 sr->http_protocol = r->http_protocol;
|
|
2230
|
508
|
2231 ngx_http_set_exten(sr);
|
58
|
2232
|
102
|
2233 sr->main = r->main;
|
58
|
2234 sr->parent = r;
|
248
|
2235 sr->post_subrequest = ps;
|
58
|
2236 sr->read_event_handler = ngx_http_request_empty_handler;
|
426
|
2237 sr->write_event_handler = ngx_http_handler;
|
58
|
2238
|
434
|
2239 if (c->data == r && r->postponed == NULL) {
|
132
|
2240 c->data = sr;
|
58
|
2241 }
|
|
2242
|
|
2243 sr->variables = r->variables;
|
|
2244
|
|
2245 sr->log_handler = r->log_handler;
|
|
2246
|
|
2247 pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t));
|
|
2248 if (pr == NULL) {
|
194
|
2249 return NGX_ERROR;
|
58
|
2250 }
|
|
2251
|
|
2252 pr->request = sr;
|
|
2253 pr->out = NULL;
|
|
2254 pr->next = NULL;
|
|
2255
|
|
2256 if (r->postponed) {
|
|
2257 for (p = r->postponed; p->next; p = p->next) { /* void */ }
|
|
2258 p->next = pr;
|
|
2259
|
|
2260 } else {
|
|
2261 r->postponed = pr;
|
|
2262 }
|
|
2263
|
|
2264 sr->internal = 1;
|
|
2265
|
92
|
2266 sr->discard_body = r->discard_body;
|
438
|
2267 sr->expect_tested = 1;
|
62
|
2268 sr->main_filter_need_in_memory = r->main_filter_need_in_memory;
|
|
2269
|
200
|
2270 sr->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1;
|
|
2271
|
590
|
2272 tp = ngx_timeofday();
|
|
2273 r->start_sec = tp->sec;
|
|
2274 r->start_msec = tp->msec;
|
|
2275
|
426
|
2276 r->main->subrequests++;
|
518
|
2277 r->main->count++;
|
426
|
2278
|
|
2279 *psr = sr;
|
|
2280
|
520
|
2281 return ngx_http_post_request(sr, NULL);
|
58
|
2282 }
|
|
2283
|
|
2284
|
|
2285 ngx_int_t
|
36
|
2286 ngx_http_internal_redirect(ngx_http_request_t *r,
|
|
2287 ngx_str_t *uri, ngx_str_t *args)
|
0
|
2288 {
|
36
|
2289 ngx_http_core_srv_conf_t *cscf;
|
|
2290
|
226
|
2291 r->uri_changes--;
|
|
2292
|
|
2293 if (r->uri_changes == 0) {
|
|
2294 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
228
|
2295 "rewrite or internal redirection cycle "
|
|
2296 "while internal redirect to \"%V\"", uri);
|
|
2297
|
526
|
2298 r->main->count++;
|
226
|
2299 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
2300 return NGX_DONE;
|
|
2301 }
|
|
2302
|
10
|
2303 r->uri = *uri;
|
0
|
2304
|
|
2305 if (args) {
|
10
|
2306 r->args = *args;
|
58
|
2307
|
|
2308 } else {
|
570
|
2309 ngx_str_null(&r->args);
|
0
|
2310 }
|
|
2311
|
132
|
2312 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2313 "internal redirect: \"%V?%V\"", uri, &r->args);
|
|
2314
|
508
|
2315 ngx_http_set_exten(r);
|
0
|
2316
|
224
|
2317 /* clear the modules contexts */
|
|
2318 ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
|
0
|
2319
|
36
|
2320 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
|
2321 r->loc_conf = cscf->ctx->loc_conf;
|
|
2322
|
84
|
2323 ngx_http_update_location_config(r);
|
|
2324
|
464
|
2325 #if (NGX_HTTP_CACHE)
|
|
2326 r->cache = NULL;
|
|
2327 #endif
|
|
2328
|
58
|
2329 r->internal = 1;
|
574
|
2330 r->add_uri_to_alias = 0;
|
518
|
2331 r->main->count++;
|
58
|
2332
|
0
|
2333 ngx_http_handler(r);
|
|
2334
|
|
2335 return NGX_DONE;
|
|
2336 }
|
|
2337
|
|
2338
|
324
|
2339 ngx_int_t
|
|
2340 ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name)
|
|
2341 {
|
|
2342 ngx_http_core_srv_conf_t *cscf;
|
|
2343 ngx_http_core_loc_conf_t **clcfp;
|
|
2344 ngx_http_core_main_conf_t *cmcf;
|
|
2345
|
518
|
2346 r->main->count++;
|
|
2347
|
324
|
2348 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
|
2349
|
430
|
2350 if (cscf->named_locations) {
|
|
2351
|
|
2352 for (clcfp = cscf->named_locations; *clcfp; clcfp++) {
|
|
2353
|
|
2354 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2355 "test location: \"%V\"", &(*clcfp)->name);
|
|
2356
|
|
2357 if (name->len != (*clcfp)->name.len
|
|
2358 || ngx_strncmp(name->data, (*clcfp)->name.data, name->len) != 0)
|
|
2359 {
|
|
2360 continue;
|
|
2361 }
|
|
2362
|
|
2363 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2364 "using location: %V \"%V?%V\"",
|
|
2365 name, &r->uri, &r->args);
|
|
2366
|
|
2367 r->internal = 1;
|
|
2368 r->content_handler = NULL;
|
|
2369 r->loc_conf = (*clcfp)->loc_conf;
|
|
2370
|
|
2371 ngx_http_update_location_config(r);
|
|
2372
|
|
2373 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
|
|
2374
|
|
2375 r->phase_handler = cmcf->phase_engine.location_rewrite_index;
|
|
2376
|
|
2377 ngx_http_core_run_phases(r);
|
|
2378
|
|
2379 return NGX_DONE;
|
324
|
2380 }
|
|
2381 }
|
|
2382
|
|
2383 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
342
|
2384 "could not find named location \"%V\"", name);
|
324
|
2385
|
|
2386 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
378
|
2387
|
324
|
2388 return NGX_DONE;
|
|
2389 }
|
|
2390
|
|
2391
|
118
|
2392 ngx_http_cleanup_t *
|
|
2393 ngx_http_cleanup_add(ngx_http_request_t *r, size_t size)
|
0
|
2394 {
|
118
|
2395 ngx_http_cleanup_t *cln;
|
|
2396
|
|
2397 r = r->main;
|
|
2398
|
|
2399 cln = ngx_palloc(r->pool, sizeof(ngx_http_cleanup_t));
|
|
2400 if (cln == NULL) {
|
|
2401 return NULL;
|
0
|
2402 }
|
|
2403
|
118
|
2404 if (size) {
|
|
2405 cln->data = ngx_palloc(r->pool, size);
|
|
2406 if (cln->data == NULL) {
|
|
2407 return NULL;
|
|
2408 }
|
|
2409
|
|
2410 } else {
|
|
2411 cln->data = NULL;
|
|
2412 }
|
|
2413
|
|
2414 cln->handler = NULL;
|
|
2415 cln->next = r->cleanup;
|
|
2416
|
|
2417 r->cleanup = cln;
|
|
2418
|
|
2419 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2420 "http cleanup add: %p", cln);
|
|
2421
|
|
2422 return cln;
|
0
|
2423 }
|
|
2424
|
|
2425
|
36
|
2426 static char *
|
|
2427 ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
0
|
2428 {
|
308
|
2429 char *rv;
|
|
2430 void *mconf;
|
310
|
2431 ngx_uint_t i;
|
308
|
2432 ngx_conf_t pcf;
|
|
2433 ngx_http_module_t *module;
|
602
|
2434 struct sockaddr_in *sin;
|
308
|
2435 ngx_http_conf_ctx_t *ctx, *http_ctx;
|
602
|
2436 ngx_http_listen_opt_t lsopt;
|
308
|
2437 ngx_http_core_srv_conf_t *cscf, **cscfp;
|
310
|
2438 ngx_http_core_main_conf_t *cmcf;
|
36
|
2439
|
50
|
2440 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
|
|
2441 if (ctx == NULL) {
|
36
|
2442 return NGX_CONF_ERROR;
|
|
2443 }
|
0
|
2444
|
|
2445 http_ctx = cf->ctx;
|
|
2446 ctx->main_conf = http_ctx->main_conf;
|
|
2447
|
|
2448 /* the server{}'s srv_conf */
|
|
2449
|
36
|
2450 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
2451 if (ctx->srv_conf == NULL) {
|
|
2452 return NGX_CONF_ERROR;
|
|
2453 }
|
0
|
2454
|
|
2455 /* the server{}'s loc_conf */
|
|
2456
|
36
|
2457 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
2458 if (ctx->loc_conf == NULL) {
|
|
2459 return NGX_CONF_ERROR;
|
|
2460 }
|
0
|
2461
|
310
|
2462 for (i = 0; ngx_modules[i]; i++) {
|
|
2463 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
|
0
|
2464 continue;
|
|
2465 }
|
|
2466
|
310
|
2467 module = ngx_modules[i]->ctx;
|
0
|
2468
|
|
2469 if (module->create_srv_conf) {
|
50
|
2470 mconf = module->create_srv_conf(cf);
|
|
2471 if (mconf == NULL) {
|
36
|
2472 return NGX_CONF_ERROR;
|
|
2473 }
|
|
2474
|
310
|
2475 ctx->srv_conf[ngx_modules[i]->ctx_index] = mconf;
|
0
|
2476 }
|
|
2477
|
|
2478 if (module->create_loc_conf) {
|
50
|
2479 mconf = module->create_loc_conf(cf);
|
|
2480 if (mconf == NULL) {
|
36
|
2481 return NGX_CONF_ERROR;
|
|
2482 }
|
|
2483
|
310
|
2484 ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
|
0
|
2485 }
|
|
2486 }
|
|
2487
|
36
|
2488
|
|
2489 /* the server configuration context */
|
0
|
2490
|
|
2491 cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
|
|
2492 cscf->ctx = ctx;
|
|
2493
|
36
|
2494
|
0
|
2495 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
|
36
|
2496
|
50
|
2497 cscfp = ngx_array_push(&cmcf->servers);
|
|
2498 if (cscfp == NULL) {
|
36
|
2499 return NGX_CONF_ERROR;
|
|
2500 }
|
|
2501
|
0
|
2502 *cscfp = cscf;
|
|
2503
|
36
|
2504
|
0
|
2505 /* parse inside server{} */
|
|
2506
|
70
|
2507 pcf = *cf;
|
0
|
2508 cf->ctx = ctx;
|
|
2509 cf->cmd_type = NGX_HTTP_SRV_CONF;
|
34
|
2510
|
0
|
2511 rv = ngx_conf_parse(cf, NULL);
|
34
|
2512
|
70
|
2513 *cf = pcf;
|
0
|
2514
|
602
|
2515 if (rv == NGX_CONF_OK && !cscf->listen) {
|
|
2516 ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t));
|
|
2517
|
|
2518 sin = &lsopt.u.sockaddr_in;
|
|
2519
|
|
2520 sin->sin_family = AF_INET;
|
|
2521 #if (NGX_WIN32)
|
|
2522 sin->sin_port = htons(80);
|
|
2523 #else
|
|
2524 sin->sin_port = htons((getuid() == 0) ? 80 : 8000);
|
|
2525 #endif
|
|
2526 sin->sin_addr.s_addr = INADDR_ANY;
|
|
2527
|
|
2528 lsopt.socklen = sizeof(struct sockaddr_in);
|
|
2529
|
|
2530 lsopt.backlog = NGX_LISTEN_BACKLOG;
|
|
2531 lsopt.rcvbuf = -1;
|
|
2532 lsopt.sndbuf = -1;
|
|
2533 #if (NGX_HAVE_SETFIB)
|
|
2534 lsopt.setfib = -1;
|
|
2535 #endif
|
|
2536 lsopt.wildcard = 1;
|
|
2537
|
|
2538 (void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.addr,
|
|
2539 NGX_SOCKADDR_STRLEN, 1);
|
|
2540
|
|
2541 if (ngx_http_add_listen(cf, cscf, &lsopt) != NGX_OK) {
|
|
2542 return NGX_CONF_ERROR;
|
|
2543 }
|
|
2544 }
|
|
2545
|
0
|
2546 return rv;
|
|
2547 }
|
|
2548
|
|
2549
|
36
|
2550 static char *
|
|
2551 ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
0
|
2552 {
|
|
2553 char *rv;
|
430
|
2554 u_char *mod;
|
|
2555 size_t len;
|
|
2556 ngx_str_t *value, *name;
|
310
|
2557 ngx_uint_t i;
|
34
|
2558 ngx_conf_t save;
|
0
|
2559 ngx_http_module_t *module;
|
|
2560 ngx_http_conf_ctx_t *ctx, *pctx;
|
378
|
2561 ngx_http_core_loc_conf_t *clcf, *pclcf;
|
0
|
2562
|
50
|
2563 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
|
|
2564 if (ctx == NULL) {
|
0
|
2565 return NGX_CONF_ERROR;
|
|
2566 }
|
|
2567
|
|
2568 pctx = cf->ctx;
|
|
2569 ctx->main_conf = pctx->main_conf;
|
|
2570 ctx->srv_conf = pctx->srv_conf;
|
|
2571
|
|
2572 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
2573 if (ctx->loc_conf == NULL) {
|
|
2574 return NGX_CONF_ERROR;
|
|
2575 }
|
|
2576
|
310
|
2577 for (i = 0; ngx_modules[i]; i++) {
|
|
2578 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
|
0
|
2579 continue;
|
|
2580 }
|
|
2581
|
310
|
2582 module = ngx_modules[i]->ctx;
|
0
|
2583
|
|
2584 if (module->create_loc_conf) {
|
310
|
2585 ctx->loc_conf[ngx_modules[i]->ctx_index] =
|
0
|
2586 module->create_loc_conf(cf);
|
310
|
2587 if (ctx->loc_conf[ngx_modules[i]->ctx_index] == NULL) {
|
0
|
2588 return NGX_CONF_ERROR;
|
|
2589 }
|
|
2590 }
|
|
2591 }
|
|
2592
|
|
2593 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
|
|
2594 clcf->loc_conf = ctx->loc_conf;
|
|
2595
|
|
2596 value = cf->args->elts;
|
|
2597
|
|
2598 if (cf->args->nelts == 3) {
|
430
|
2599
|
|
2600 len = value[1].len;
|
|
2601 mod = value[1].data;
|
|
2602 name = &value[2];
|
|
2603
|
|
2604 if (len == 1 && mod[0] == '=') {
|
|
2605
|
|
2606 clcf->name = *name;
|
0
|
2607 clcf->exact_match = 1;
|
|
2608
|
430
|
2609 } else if (len == 2 && mod[0] == '^' && mod[1] == '~') {
|
|
2610
|
|
2611 clcf->name = *name;
|
16
|
2612 clcf->noregex = 1;
|
|
2613
|
430
|
2614 } else if (len == 1 && mod[0] == '~') {
|
|
2615
|
|
2616 if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
|
0
|
2617 return NGX_CONF_ERROR;
|
|
2618 }
|
|
2619
|
430
|
2620 } else if (len == 2 && mod[0] == '~' && mod[1] == '*') {
|
|
2621
|
|
2622 if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
|
|
2623 return NGX_CONF_ERROR;
|
|
2624 }
|
0
|
2625
|
|
2626 } else {
|
|
2627 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
2628 "invalid location modifier \"%V\"", &value[1]);
|
0
|
2629 return NGX_CONF_ERROR;
|
|
2630 }
|
|
2631
|
|
2632 } else {
|
324
|
2633
|
430
|
2634 name = &value[1];
|
|
2635
|
|
2636 if (name->data[0] == '=') {
|
|
2637
|
|
2638 clcf->name.len = name->len - 1;
|
|
2639 clcf->name.data = name->data + 1;
|
|
2640 clcf->exact_match = 1;
|
|
2641
|
|
2642 } else if (name->data[0] == '^' && name->data[1] == '~') {
|
|
2643
|
|
2644 clcf->name.len = name->len - 2;
|
|
2645 clcf->name.data = name->data + 2;
|
|
2646 clcf->noregex = 1;
|
|
2647
|
|
2648 } else if (name->data[0] == '~') {
|
|
2649
|
|
2650 name->len--;
|
|
2651 name->data++;
|
|
2652
|
|
2653 if (name->data[0] == '*') {
|
|
2654
|
|
2655 name->len--;
|
|
2656 name->data++;
|
|
2657
|
|
2658 if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
|
|
2659 return NGX_CONF_ERROR;
|
|
2660 }
|
|
2661
|
|
2662 } else {
|
|
2663 if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
|
|
2664 return NGX_CONF_ERROR;
|
|
2665 }
|
|
2666 }
|
|
2667
|
|
2668 } else {
|
|
2669
|
|
2670 clcf->name = *name;
|
|
2671
|
|
2672 if (name->data[0] == '@') {
|
|
2673 clcf->named = 1;
|
|
2674 }
|
324
|
2675 }
|
0
|
2676 }
|
|
2677
|
|
2678 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
|
|
2679
|
378
|
2680 if (pclcf->name.len) {
|
|
2681
|
|
2682 /* nested location */
|
|
2683
|
34
|
2684 #if 0
|
0
|
2685 clcf->prev_location = pclcf;
|
34
|
2686 #endif
|
0
|
2687
|
|
2688 if (pclcf->exact_match) {
|
|
2689 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
2690 "location \"%V\" could not be inside "
|
|
2691 "the exact location \"%V\"",
|
|
2692 &clcf->name, &pclcf->name);
|
0
|
2693 return NGX_CONF_ERROR;
|
|
2694 }
|
|
2695
|
324
|
2696 if (pclcf->named) {
|
|
2697 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2698 "location \"%V\" could not be inside "
|
|
2699 "the named location \"%V\"",
|
|
2700 &clcf->name, &pclcf->name);
|
|
2701 return NGX_CONF_ERROR;
|
|
2702 }
|
|
2703
|
378
|
2704 if (clcf->named) {
|
|
2705 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2706 "named location \"%V\" must be "
|
|
2707 "on server level only",
|
|
2708 &clcf->name);
|
|
2709 return NGX_CONF_ERROR;
|
|
2710 }
|
|
2711
|
430
|
2712 len = pclcf->name.len;
|
|
2713
|
4
|
2714 #if (NGX_PCRE)
|
0
|
2715 if (clcf->regex == NULL
|
430
|
2716 && ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0)
|
0
|
2717 #else
|
430
|
2718 if (ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0)
|
0
|
2719 #endif
|
|
2720 {
|
|
2721 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
2722 "location \"%V\" is outside location \"%V\"",
|
|
2723 &clcf->name, &pclcf->name);
|
0
|
2724 return NGX_CONF_ERROR;
|
|
2725 }
|
|
2726 }
|
|
2727
|
378
|
2728 if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
|
|
2729 return NGX_CONF_ERROR;
|
|
2730 }
|
0
|
2731
|
34
|
2732 save = *cf;
|
0
|
2733 cf->ctx = ctx;
|
|
2734 cf->cmd_type = NGX_HTTP_LOC_CONF;
|
34
|
2735
|
0
|
2736 rv = ngx_conf_parse(cf, NULL);
|
34
|
2737
|
|
2738 *cf = save;
|
|
2739
|
0
|
2740 return rv;
|
|
2741 }
|
|
2742
|
|
2743
|
430
|
2744 static ngx_int_t
|
|
2745 ngx_http_core_regex_location(ngx_conf_t *cf, ngx_http_core_loc_conf_t *clcf,
|
|
2746 ngx_str_t *regex, ngx_uint_t caseless)
|
|
2747 {
|
|
2748 #if (NGX_PCRE)
|
546
|
2749 ngx_regex_compile_t rc;
|
|
2750 u_char errstr[NGX_MAX_CONF_ERRSTR];
|
|
2751
|
|
2752 ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
|
|
2753
|
|
2754 rc.pattern = *regex;
|
|
2755 rc.err.len = NGX_MAX_CONF_ERRSTR;
|
|
2756 rc.err.data = errstr;
|
430
|
2757
|
508
|
2758 #if (NGX_HAVE_CASELESS_FILESYSTEM)
|
546
|
2759 rc.options = NGX_REGEX_CASELESS;
|
558
|
2760 #else
|
|
2761 rc.options = caseless;
|
508
|
2762 #endif
|
|
2763
|
546
|
2764 clcf->regex = ngx_http_regex_compile(cf, &rc);
|
430
|
2765 if (clcf->regex == NULL) {
|
|
2766 return NGX_ERROR;
|
|
2767 }
|
|
2768
|
|
2769 clcf->name = *regex;
|
|
2770
|
|
2771 return NGX_OK;
|
|
2772
|
|
2773 #else
|
|
2774
|
|
2775 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2776 "the using of the regex \"%V\" requires PCRE library",
|
|
2777 regex);
|
|
2778 return NGX_ERROR;
|
|
2779
|
|
2780 #endif
|
|
2781 }
|
|
2782
|
|
2783
|
36
|
2784 static char *
|
|
2785 ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
2786 {
|
546
|
2787 ngx_http_core_loc_conf_t *clcf = conf;
|
186
|
2788
|
0
|
2789 char *rv;
|
34
|
2790 ngx_conf_t save;
|
0
|
2791
|
546
|
2792 if (clcf->types == NULL) {
|
|
2793 clcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t));
|
|
2794 if (clcf->types == NULL) {
|
186
|
2795 return NGX_CONF_ERROR;
|
|
2796 }
|
|
2797 }
|
|
2798
|
34
|
2799 save = *cf;
|
|
2800 cf->handler = ngx_http_core_type;
|
0
|
2801 cf->handler_conf = conf;
|
34
|
2802
|
0
|
2803 rv = ngx_conf_parse(cf, NULL);
|
34
|
2804
|
|
2805 *cf = save;
|
0
|
2806
|
|
2807 return rv;
|
|
2808 }
|
|
2809
|
|
2810
|
36
|
2811 static char *
|
|
2812 ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
|
0
|
2813 {
|
546
|
2814 ngx_http_core_loc_conf_t *clcf = conf;
|
0
|
2815
|
294
|
2816 ngx_str_t *value, *content_type, *old, file;
|
392
|
2817 ngx_uint_t i, n, hash;
|
138
|
2818 ngx_hash_key_t *type;
|
0
|
2819
|
294
|
2820 value = cf->args->elts;
|
|
2821
|
|
2822 if (ngx_strcmp(value[0].data, "include") == 0) {
|
|
2823 file = value[1];
|
|
2824
|
454
|
2825 if (ngx_conf_full_name(cf->cycle, &file, 1) != NGX_OK) {
|
294
|
2826 return NGX_CONF_ERROR;
|
|
2827 }
|
|
2828
|
|
2829 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
|
|
2830
|
|
2831 return ngx_conf_parse(cf, &file);
|
|
2832 }
|
|
2833
|
138
|
2834 content_type = ngx_palloc(cf->pool, sizeof(ngx_str_t));
|
|
2835 if (content_type == NULL) {
|
|
2836 return NGX_CONF_ERROR;
|
0
|
2837 }
|
|
2838
|
138
|
2839 *content_type = value[0];
|
0
|
2840
|
|
2841 for (i = 1; i < cf->args->nelts; i++) {
|
138
|
2842
|
392
|
2843 hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len);
|
138
|
2844
|
546
|
2845 type = clcf->types->elts;
|
|
2846 for (n = 0; n < clcf->types->nelts; n++) {
|
138
|
2847 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) {
|
|
2848 old = type[n].value;
|
|
2849 type[n].value = content_type;
|
|
2850
|
|
2851 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
2852 "duplicate extention \"%V\", "
|
|
2853 "content type: \"%V\", "
|
|
2854 "old content type: \"%V\"",
|
|
2855 &value[i], content_type, old);
|
|
2856 continue;
|
|
2857 }
|
|
2858 }
|
|
2859
|
|
2860
|
546
|
2861 type = ngx_array_push(clcf->types);
|
50
|
2862 if (type == NULL) {
|
0
|
2863 return NGX_CONF_ERROR;
|
|
2864 }
|
|
2865
|
138
|
2866 type->key = value[i];
|
392
|
2867 type->key_hash = hash;
|
138
|
2868 type->value = content_type;
|
0
|
2869 }
|
|
2870
|
|
2871 return NGX_CONF_OK;
|
|
2872 }
|
|
2873
|
|
2874
|
58
|
2875 static ngx_int_t
|
|
2876 ngx_http_core_preconfiguration(ngx_conf_t *cf)
|
|
2877 {
|
|
2878 return ngx_http_variables_add_core_vars(cf);
|
|
2879 }
|
|
2880
|
|
2881
|
36
|
2882 static void *
|
|
2883 ngx_http_core_create_main_conf(ngx_conf_t *cf)
|
0
|
2884 {
|
34
|
2885 ngx_http_core_main_conf_t *cmcf;
|
|
2886
|
50
|
2887 cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t));
|
|
2888 if (cmcf == NULL) {
|
496
|
2889 return NULL;
|
34
|
2890 }
|
0
|
2891
|
48
|
2892 if (ngx_array_init(&cmcf->servers, cf->pool, 4,
|
118
|
2893 sizeof(ngx_http_core_srv_conf_t *))
|
200
|
2894 != NGX_OK)
|
34
|
2895 {
|
496
|
2896 return NULL;
|
34
|
2897 }
|
0
|
2898
|
142
|
2899 cmcf->server_names_hash_max_size = NGX_CONF_UNSET_UINT;
|
|
2900 cmcf->server_names_hash_bucket_size = NGX_CONF_UNSET_UINT;
|
26
|
2901
|
160
|
2902 cmcf->variables_hash_max_size = NGX_CONF_UNSET_UINT;
|
|
2903 cmcf->variables_hash_bucket_size = NGX_CONF_UNSET_UINT;
|
|
2904
|
0
|
2905 return cmcf;
|
|
2906 }
|
|
2907
|
|
2908
|
36
|
2909 static char *
|
|
2910 ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf)
|
0
|
2911 {
|
|
2912 ngx_http_core_main_conf_t *cmcf = conf;
|
|
2913
|
142
|
2914 if (cmcf->server_names_hash_max_size == NGX_CONF_UNSET_UINT) {
|
|
2915 cmcf->server_names_hash_max_size = 512;
|
26
|
2916 }
|
|
2917
|
142
|
2918 if (cmcf->server_names_hash_bucket_size == NGX_CONF_UNSET_UINT) {
|
|
2919 cmcf->server_names_hash_bucket_size = ngx_cacheline_size;
|
26
|
2920 }
|
0
|
2921
|
142
|
2922 cmcf->server_names_hash_bucket_size =
|
|
2923 ngx_align(cmcf->server_names_hash_bucket_size, ngx_cacheline_size);
|
|
2924
|
160
|
2925
|
|
2926 if (cmcf->variables_hash_max_size == NGX_CONF_UNSET_UINT) {
|
|
2927 cmcf->variables_hash_max_size = 512;
|
|
2928 }
|
|
2929
|
|
2930 if (cmcf->variables_hash_bucket_size == NGX_CONF_UNSET_UINT) {
|
|
2931 cmcf->variables_hash_bucket_size = 64;
|
|
2932 }
|
|
2933
|
|
2934 cmcf->variables_hash_bucket_size =
|
|
2935 ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size);
|
|
2936
|
548
|
2937 if (cmcf->ncaptures) {
|
|
2938 cmcf->ncaptures = (cmcf->ncaptures + 1) * 3;
|
|
2939 }
|
|
2940
|
0
|
2941 return NGX_CONF_OK;
|
|
2942 }
|
|
2943
|
|
2944
|
36
|
2945 static void *
|
|
2946 ngx_http_core_create_srv_conf(ngx_conf_t *cf)
|
0
|
2947 {
|
|
2948 ngx_http_core_srv_conf_t *cscf;
|
|
2949
|
50
|
2950 cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t));
|
|
2951 if (cscf == NULL) {
|
496
|
2952 return NULL;
|
36
|
2953 }
|
|
2954
|
0
|
2955 /*
|
36
|
2956 * set by ngx_pcalloc():
|
28
|
2957 *
|
|
2958 * conf->client_large_buffers.num = 0;
|
|
2959 */
|
0
|
2960
|
230
|
2961 if (ngx_array_init(&cscf->server_names, cf->temp_pool, 4,
|
142
|
2962 sizeof(ngx_http_server_name_t))
|
454
|
2963 != NGX_OK)
|
36
|
2964 {
|
496
|
2965 return NULL;
|
36
|
2966 }
|
0
|
2967
|
|
2968 cscf->connection_pool_size = NGX_CONF_UNSET_SIZE;
|
|
2969 cscf->request_pool_size = NGX_CONF_UNSET_SIZE;
|
|
2970 cscf->client_header_timeout = NGX_CONF_UNSET_MSEC;
|
|
2971 cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE;
|
60
|
2972 cscf->ignore_invalid_headers = NGX_CONF_UNSET;
|
342
|
2973 cscf->merge_slashes = NGX_CONF_UNSET;
|
412
|
2974 cscf->underscores_in_headers = NGX_CONF_UNSET;
|
0
|
2975
|
|
2976 return cscf;
|
|
2977 }
|
|
2978
|
|
2979
|
36
|
2980 static char *
|
|
2981 ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
0
|
2982 {
|
|
2983 ngx_http_core_srv_conf_t *prev = parent;
|
|
2984 ngx_http_core_srv_conf_t *conf = child;
|
|
2985
|
142
|
2986 ngx_http_server_name_t *sn;
|
0
|
2987
|
|
2988 /* TODO: it does not merge, it inits only */
|
|
2989
|
540
|
2990 ngx_conf_merge_size_value(conf->connection_pool_size,
|
|
2991 prev->connection_pool_size, 256);
|
|
2992 ngx_conf_merge_size_value(conf->request_pool_size,
|
|
2993 prev->request_pool_size, 4096);
|
|
2994 ngx_conf_merge_msec_value(conf->client_header_timeout,
|
|
2995 prev->client_header_timeout, 60000);
|
|
2996 ngx_conf_merge_size_value(conf->client_header_buffer_size,
|
|
2997 prev->client_header_buffer_size, 1024);
|
|
2998 ngx_conf_merge_bufs_value(conf->large_client_header_buffers,
|
|
2999 prev->large_client_header_buffers,
|
556
|
3000 4, 8192);
|
540
|
3001
|
|
3002 if (conf->large_client_header_buffers.size < conf->connection_pool_size) {
|
|
3003 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3004 "the \"large_client_header_buffers\" size must be "
|
|
3005 "equal to or bigger than \"connection_pool_size\"");
|
|
3006 return NGX_CONF_ERROR;
|
|
3007 }
|
|
3008
|
|
3009 ngx_conf_merge_value(conf->ignore_invalid_headers,
|
|
3010 prev->ignore_invalid_headers, 1);
|
|
3011
|
|
3012 ngx_conf_merge_value(conf->merge_slashes, prev->merge_slashes, 1);
|
|
3013
|
|
3014 ngx_conf_merge_value(conf->underscores_in_headers,
|
|
3015 prev->underscores_in_headers, 0);
|
|
3016
|
154
|
3017 if (conf->server_name.data == NULL) {
|
592
|
3018 ngx_str_set(&conf->server_name, "");
|
154
|
3019
|
50
|
3020 sn = ngx_array_push(&conf->server_names);
|
|
3021 if (sn == NULL) {
|
36
|
3022 return NGX_CONF_ERROR;
|
|
3023 }
|
|
3024
|
342
|
3025 #if (NGX_PCRE)
|
|
3026 sn->regex = NULL;
|
|
3027 #endif
|
538
|
3028 sn->server = conf;
|
592
|
3029 ngx_str_set(&sn->name, "");
|
0
|
3030 }
|
|
3031
|
|
3032 return NGX_CONF_OK;
|
|
3033 }
|
|
3034
|
|
3035
|
36
|
3036 static void *
|
|
3037 ngx_http_core_create_loc_conf(ngx_conf_t *cf)
|
0
|
3038 {
|
546
|
3039 ngx_http_core_loc_conf_t *clcf;
|
|
3040
|
|
3041 clcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t));
|
|
3042 if (clcf == NULL) {
|
496
|
3043 return NULL;
|
36
|
3044 }
|
0
|
3045
|
28
|
3046 /*
|
|
3047 * set by ngx_pcalloc():
|
|
3048 *
|
546
|
3049 * clcf->root = { 0, NULL };
|
|
3050 * clcf->limit_except = 0;
|
|
3051 * clcf->post_action = { 0, NULL };
|
|
3052 * clcf->types = NULL;
|
|
3053 * clcf->default_type = { 0, NULL };
|
|
3054 * clcf->error_log = NULL;
|
|
3055 * clcf->error_pages = NULL;
|
|
3056 * clcf->try_files = NULL;
|
|
3057 * clcf->client_body_path = NULL;
|
|
3058 * clcf->regex = NULL;
|
|
3059 * clcf->exact_match = 0;
|
|
3060 * clcf->auto_redirect = 0;
|
|
3061 * clcf->alias = 0;
|
|
3062 * clcf->gzip_proxied = 0;
|
28
|
3063 */
|
0
|
3064
|
546
|
3065 clcf->client_max_body_size = NGX_CONF_UNSET;
|
|
3066 clcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE;
|
|
3067 clcf->client_body_timeout = NGX_CONF_UNSET_MSEC;
|
|
3068 clcf->satisfy = NGX_CONF_UNSET_UINT;
|
|
3069 clcf->if_modified_since = NGX_CONF_UNSET_UINT;
|
|
3070 clcf->client_body_in_file_only = NGX_CONF_UNSET_UINT;
|
|
3071 clcf->client_body_in_single_buffer = NGX_CONF_UNSET;
|
|
3072 clcf->internal = NGX_CONF_UNSET;
|
|
3073 clcf->sendfile = NGX_CONF_UNSET;
|
|
3074 clcf->sendfile_max_chunk = NGX_CONF_UNSET_SIZE;
|
518
|
3075 #if (NGX_HAVE_FILE_AIO)
|
546
|
3076 clcf->aio = NGX_CONF_UNSET;
|
518
|
3077 #endif
|
546
|
3078 clcf->read_ahead = NGX_CONF_UNSET_SIZE;
|
|
3079 clcf->directio = NGX_CONF_UNSET;
|
|
3080 clcf->directio_alignment = NGX_CONF_UNSET;
|
|
3081 clcf->tcp_nopush = NGX_CONF_UNSET;
|
|
3082 clcf->tcp_nodelay = NGX_CONF_UNSET;
|
|
3083 clcf->send_timeout = NGX_CONF_UNSET_MSEC;
|
|
3084 clcf->send_lowat = NGX_CONF_UNSET_SIZE;
|
|
3085 clcf->postpone_output = NGX_CONF_UNSET_SIZE;
|
|
3086 clcf->limit_rate = NGX_CONF_UNSET_SIZE;
|
|
3087 clcf->limit_rate_after = NGX_CONF_UNSET_SIZE;
|
|
3088 clcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
|
|
3089 clcf->keepalive_header = NGX_CONF_UNSET;
|
|
3090 clcf->keepalive_requests = NGX_CONF_UNSET_UINT;
|
|
3091 clcf->lingering_time = NGX_CONF_UNSET_MSEC;
|
|
3092 clcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
|
|
3093 clcf->resolver_timeout = NGX_CONF_UNSET_MSEC;
|
|
3094 clcf->reset_timedout_connection = NGX_CONF_UNSET;
|
|
3095 clcf->server_name_in_redirect = NGX_CONF_UNSET;
|
|
3096 clcf->port_in_redirect = NGX_CONF_UNSET;
|
|
3097 clcf->msie_padding = NGX_CONF_UNSET;
|
|
3098 clcf->msie_refresh = NGX_CONF_UNSET;
|
|
3099 clcf->log_not_found = NGX_CONF_UNSET;
|
|
3100 clcf->log_subrequest = NGX_CONF_UNSET;
|
|
3101 clcf->recursive_error_pages = NGX_CONF_UNSET;
|
|
3102 clcf->server_tokens = NGX_CONF_UNSET;
|
566
|
3103 clcf->chunked_transfer_encoding = NGX_CONF_UNSET;
|
546
|
3104 clcf->types_hash_max_size = NGX_CONF_UNSET_UINT;
|
|
3105 clcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT;
|
|
3106
|
|
3107 clcf->open_file_cache = NGX_CONF_UNSET_PTR;
|
|
3108 clcf->open_file_cache_valid = NGX_CONF_UNSET;
|
|
3109 clcf->open_file_cache_min_uses = NGX_CONF_UNSET_UINT;
|
|
3110 clcf->open_file_cache_errors = NGX_CONF_UNSET;
|
|
3111 clcf->open_file_cache_events = NGX_CONF_UNSET;
|
0
|
3112
|
358
|
3113 #if (NGX_HTTP_GZIP)
|
546
|
3114 clcf->gzip_vary = NGX_CONF_UNSET;
|
|
3115 clcf->gzip_http_version = NGX_CONF_UNSET_UINT;
|
362
|
3116 #if (NGX_PCRE)
|
546
|
3117 clcf->gzip_disable = NGX_CONF_UNSET_PTR;
|
596
|
3118 #endif
|
546
|
3119 clcf->gzip_disable_msie6 = 3;
|
602
|
3120 #if (NGX_HTTP_DEGRADATION)
|
|
3121 clcf->gzip_disable_degradation = 3;
|
|
3122 #endif
|
358
|
3123 #endif
|
|
3124
|
546
|
3125 return clcf;
|
0
|
3126 }
|
|
3127
|
|
3128
|
138
|
3129 static ngx_str_t ngx_http_core_text_html_type = ngx_string("text/html");
|
|
3130 static ngx_str_t ngx_http_core_image_gif_type = ngx_string("image/gif");
|
|
3131 static ngx_str_t ngx_http_core_image_jpeg_type = ngx_string("image/jpeg");
|
|
3132
|
|
3133 static ngx_hash_key_t ngx_http_core_default_types[] = {
|
|
3134 { ngx_string("html"), 0, &ngx_http_core_text_html_type },
|
|
3135 { ngx_string("gif"), 0, &ngx_http_core_image_gif_type },
|
|
3136 { ngx_string("jpg"), 0, &ngx_http_core_image_jpeg_type },
|
|
3137 { ngx_null_string, 0, NULL }
|
0
|
3138 };
|
|
3139
|
|
3140
|
36
|
3141 static char *
|
138
|
3142 ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
0
|
3143 {
|
|
3144 ngx_http_core_loc_conf_t *prev = parent;
|
|
3145 ngx_http_core_loc_conf_t *conf = child;
|
|
3146
|
36
|
3147 ngx_uint_t i;
|
138
|
3148 ngx_hash_key_t *type;
|
|
3149 ngx_hash_init_t types_hash;
|
0
|
3150
|
152
|
3151 if (conf->root.data == NULL) {
|
|
3152
|
174
|
3153 conf->alias = prev->alias;
|
152
|
3154 conf->root = prev->root;
|
|
3155 conf->root_lengths = prev->root_lengths;
|
|
3156 conf->root_values = prev->root_values;
|
|
3157
|
|
3158 if (prev->root.data == NULL) {
|
570
|
3159 ngx_str_set(&conf->root, "html");
|
152
|
3160
|
454
|
3161 if (ngx_conf_full_name(cf->cycle, &conf->root, 0) != NGX_OK) {
|
152
|
3162 return NGX_CONF_ERROR;
|
|
3163 }
|
|
3164 }
|
0
|
3165 }
|
|
3166
|
126
|
3167 if (conf->post_action.data == NULL) {
|
|
3168 conf->post_action = prev->post_action;
|
|
3169 }
|
|
3170
|
212
|
3171 ngx_conf_merge_uint_value(conf->types_hash_max_size,
|
|
3172 prev->types_hash_max_size, 1024);
|
|
3173
|
|
3174 ngx_conf_merge_uint_value(conf->types_hash_bucket_size,
|
|
3175 prev->types_hash_bucket_size,
|
|
3176 ngx_cacheline_size);
|
138
|
3177
|
|
3178 conf->types_hash_bucket_size = ngx_align(conf->types_hash_bucket_size,
|
|
3179 ngx_cacheline_size);
|
|
3180
|
|
3181 /*
|
|
3182 * the special handling the "types" directive in the "http" section
|
|
3183 * to inherit the http's conf->types_hash to all servers
|
|
3184 */
|
|
3185
|
|
3186 if (prev->types && prev->types_hash.buckets == NULL) {
|
|
3187
|
|
3188 types_hash.hash = &prev->types_hash;
|
|
3189 types_hash.key = ngx_hash_key_lc;
|
|
3190 types_hash.max_size = conf->types_hash_max_size;
|
|
3191 types_hash.bucket_size = conf->types_hash_bucket_size;
|
144
|
3192 types_hash.name = "types_hash";
|
138
|
3193 types_hash.pool = cf->pool;
|
|
3194 types_hash.temp_pool = NULL;
|
|
3195
|
|
3196 if (ngx_hash_init(&types_hash, prev->types->elts, prev->types->nelts)
|
|
3197 != NGX_OK)
|
|
3198 {
|
|
3199 return NGX_CONF_ERROR;
|
|
3200 }
|
|
3201 }
|
|
3202
|
0
|
3203 if (conf->types == NULL) {
|
138
|
3204 conf->types = prev->types;
|
|
3205 conf->types_hash = prev->types_hash;
|
|
3206 }
|
|
3207
|
|
3208 if (conf->types == NULL) {
|
|
3209 conf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_hash_key_t));
|
|
3210 if (conf->types == NULL) {
|
|
3211 return NGX_CONF_ERROR;
|
|
3212 }
|
|
3213
|
|
3214 for (i = 0; ngx_http_core_default_types[i].key.len; i++) {
|
|
3215 type = ngx_array_push(conf->types);
|
|
3216 if (type == NULL) {
|
36
|
3217 return NGX_CONF_ERROR;
|
|
3218 }
|
0
|
3219
|
138
|
3220 type->key = ngx_http_core_default_types[i].key;
|
|
3221 type->key_hash =
|
|
3222 ngx_hash_key_lc(ngx_http_core_default_types[i].key.data,
|
|
3223 ngx_http_core_default_types[i].key.len);
|
|
3224 type->value = ngx_http_core_default_types[i].value;
|
|
3225 }
|
|
3226 }
|
|
3227
|
|
3228 if (conf->types_hash.buckets == NULL) {
|
|
3229
|
|
3230 types_hash.hash = &conf->types_hash;
|
|
3231 types_hash.key = ngx_hash_key_lc;
|
|
3232 types_hash.max_size = conf->types_hash_max_size;
|
|
3233 types_hash.bucket_size = conf->types_hash_bucket_size;
|
144
|
3234 types_hash.name = "mime_types_hash";
|
138
|
3235 types_hash.pool = cf->pool;
|
|
3236 types_hash.temp_pool = NULL;
|
|
3237
|
|
3238 if (ngx_hash_init(&types_hash, conf->types->elts, conf->types->nelts)
|
|
3239 != NGX_OK)
|
|
3240 {
|
|
3241 return NGX_CONF_ERROR;
|
0
|
3242 }
|
|
3243 }
|
|
3244
|
484
|
3245 if (conf->error_log == NULL) {
|
|
3246 if (prev->error_log) {
|
|
3247 conf->error_log = prev->error_log;
|
0
|
3248 } else {
|
484
|
3249 conf->error_log = &cf->cycle->new_log;
|
0
|
3250 }
|
|
3251 }
|
|
3252
|
|
3253 if (conf->error_pages == NULL && prev->error_pages) {
|
|
3254 conf->error_pages = prev->error_pages;
|
|
3255 }
|
|
3256
|
|
3257 ngx_conf_merge_str_value(conf->default_type,
|
36
|
3258 prev->default_type, "text/plain");
|
0
|
3259
|
212
|
3260 ngx_conf_merge_off_value(conf->client_max_body_size,
|
0
|
3261 prev->client_max_body_size, 1 * 1024 * 1024);
|
|
3262 ngx_conf_merge_size_value(conf->client_body_buffer_size,
|
|
3263 prev->client_body_buffer_size,
|
|
3264 (size_t) 2 * ngx_pagesize);
|
|
3265 ngx_conf_merge_msec_value(conf->client_body_timeout,
|
|
3266 prev->client_body_timeout, 60000);
|
58
|
3267
|
362
|
3268 ngx_conf_merge_uint_value(conf->satisfy, prev->satisfy,
|
|
3269 NGX_HTTP_SATISFY_ALL);
|
424
|
3270 ngx_conf_merge_uint_value(conf->if_modified_since, prev->if_modified_since,
|
444
|
3271 NGX_HTTP_IMS_EXACT);
|
492
|
3272 ngx_conf_merge_uint_value(conf->client_body_in_file_only,
|
|
3273 prev->client_body_in_file_only, 0);
|
|
3274 ngx_conf_merge_value(conf->client_body_in_single_buffer,
|
|
3275 prev->client_body_in_single_buffer, 0);
|
58
|
3276 ngx_conf_merge_value(conf->internal, prev->internal, 0);
|
0
|
3277 ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
|
300
|
3278 ngx_conf_merge_size_value(conf->sendfile_max_chunk,
|
|
3279 prev->sendfile_max_chunk, 0);
|
518
|
3280 #if (NGX_HAVE_FILE_AIO)
|
|
3281 ngx_conf_merge_value(conf->aio, prev->aio, 0);
|
|
3282 #endif
|
532
|
3283 ngx_conf_merge_size_value(conf->read_ahead, prev->read_ahead, 0);
|
390
|
3284 ngx_conf_merge_off_value(conf->directio, prev->directio,
|
|
3285 NGX_MAX_OFF_T_VALUE);
|
518
|
3286 ngx_conf_merge_off_value(conf->directio_alignment, prev->directio_alignment,
|
|
3287 512);
|
0
|
3288 ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0);
|
228
|
3289 ngx_conf_merge_value(conf->tcp_nodelay, prev->tcp_nodelay, 1);
|
58
|
3290
|
0
|
3291 ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000);
|
|
3292 ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0);
|
|
3293 ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output,
|
|
3294 1460);
|
|
3295 ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0);
|
496
|
3296 ngx_conf_merge_size_value(conf->limit_rate_after, prev->limit_rate_after,
|
|
3297 0);
|
0
|
3298 ngx_conf_merge_msec_value(conf->keepalive_timeout,
|
|
3299 prev->keepalive_timeout, 75000);
|
|
3300 ngx_conf_merge_sec_value(conf->keepalive_header,
|
|
3301 prev->keepalive_header, 0);
|
496
|
3302 ngx_conf_merge_uint_value(conf->keepalive_requests,
|
|
3303 prev->keepalive_requests, 100);
|
0
|
3304 ngx_conf_merge_msec_value(conf->lingering_time,
|
|
3305 prev->lingering_time, 30000);
|
|
3306 ngx_conf_merge_msec_value(conf->lingering_timeout,
|
|
3307 prev->lingering_timeout, 5000);
|
348
|
3308 ngx_conf_merge_msec_value(conf->resolver_timeout,
|
|
3309 prev->resolver_timeout, 30000);
|
|
3310
|
|
3311 if (conf->resolver == NULL) {
|
366
|
3312
|
|
3313 if (prev->resolver == NULL) {
|
|
3314
|
|
3315 /*
|
|
3316 * create dummy resolver in http {} context
|
|
3317 * to inherit it in all servers
|
|
3318 */
|
|
3319
|
|
3320 prev->resolver = ngx_resolver_create(cf, NULL);
|
|
3321 if (prev->resolver == NULL) {
|
364
|
3322 return NGX_CONF_ERROR;
|
354
|
3323 }
|
|
3324 }
|
376
|
3325
|
366
|
3326 conf->resolver = prev->resolver;
|
348
|
3327 }
|
0
|
3328
|
464
|
3329 if (ngx_conf_merge_path_value(cf, &conf->client_body_temp_path,
|
28
|
3330 prev->client_body_temp_path,
|
464
|
3331 &ngx_http_client_temp_path)
|
|
3332 != NGX_OK)
|
|
3333 {
|
|
3334 return NGX_CONF_ERROR;
|
|
3335 }
|
28
|
3336
|
0
|
3337 ngx_conf_merge_value(conf->reset_timedout_connection,
|
36
|
3338 prev->reset_timedout_connection, 0);
|
362
|
3339 ngx_conf_merge_value(conf->server_name_in_redirect,
|
592
|
3340 prev->server_name_in_redirect, 0);
|
70
|
3341 ngx_conf_merge_value(conf->port_in_redirect, prev->port_in_redirect, 1);
|
0
|
3342 ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1);
|
228
|
3343 ngx_conf_merge_value(conf->msie_refresh, prev->msie_refresh, 0);
|
76
|
3344 ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1);
|
412
|
3345 ngx_conf_merge_value(conf->log_subrequest, prev->log_subrequest, 0);
|
228
|
3346 ngx_conf_merge_value(conf->recursive_error_pages,
|
|
3347 prev->recursive_error_pages, 0);
|
342
|
3348 ngx_conf_merge_value(conf->server_tokens, prev->server_tokens, 1);
|
566
|
3349 ngx_conf_merge_value(conf->chunked_transfer_encoding,
|
|
3350 prev->chunked_transfer_encoding, 1);
|
0
|
3351
|
332
|
3352 ngx_conf_merge_ptr_value(conf->open_file_cache,
|
358
|
3353 prev->open_file_cache, NULL);
|
|
3354
|
|
3355 ngx_conf_merge_sec_value(conf->open_file_cache_valid,
|
|
3356 prev->open_file_cache_valid, 60);
|
|
3357
|
|
3358 ngx_conf_merge_uint_value(conf->open_file_cache_min_uses,
|
|
3359 prev->open_file_cache_min_uses, 1);
|
332
|
3360
|
|
3361 ngx_conf_merge_sec_value(conf->open_file_cache_errors,
|
358
|
3362 prev->open_file_cache_errors, 0);
|
332
|
3363
|
|
3364 ngx_conf_merge_sec_value(conf->open_file_cache_events,
|
358
|
3365 prev->open_file_cache_events, 0);
|
|
3366 #if (NGX_HTTP_GZIP)
|
|
3367
|
|
3368 ngx_conf_merge_value(conf->gzip_vary, prev->gzip_vary, 0);
|
|
3369 ngx_conf_merge_uint_value(conf->gzip_http_version, prev->gzip_http_version,
|
|
3370 NGX_HTTP_VERSION_11);
|
|
3371 ngx_conf_merge_bitmask_value(conf->gzip_proxied, prev->gzip_proxied,
|
|
3372 (NGX_CONF_BITMASK_SET|NGX_HTTP_GZIP_PROXIED_OFF));
|
|
3373
|
362
|
3374 #if (NGX_PCRE)
|
358
|
3375 ngx_conf_merge_ptr_value(conf->gzip_disable, prev->gzip_disable, NULL);
|
362
|
3376 #endif
|
358
|
3377
|
400
|
3378 if (conf->gzip_disable_msie6 == 3) {
|
|
3379 conf->gzip_disable_msie6 =
|
|
3380 (prev->gzip_disable_msie6 == 3) ? 0 : prev->gzip_disable_msie6;
|
|
3381 }
|
|
3382
|
602
|
3383 #if (NGX_HTTP_DEGRADATION)
|
|
3384
|
|
3385 if (conf->gzip_disable_degradation == 3) {
|
|
3386 conf->gzip_disable_degradation =
|
|
3387 (prev->gzip_disable_degradation == 3) ?
|
|
3388 0 : prev->gzip_disable_degradation;
|
|
3389 }
|
|
3390
|
|
3391 #endif
|
358
|
3392 #endif
|
0
|
3393
|
|
3394 return NGX_CONF_OK;
|
|
3395 }
|
|
3396
|
|
3397
|
36
|
3398 static char *
|
|
3399 ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
3400 {
|
538
|
3401 ngx_http_core_srv_conf_t *cscf = conf;
|
|
3402
|
|
3403 ngx_str_t *value, size;
|
|
3404 ngx_url_t u;
|
|
3405 ngx_uint_t n;
|
|
3406 ngx_http_listen_opt_t lsopt;
|
|
3407
|
|
3408 cscf->listen = 1;
|
0
|
3409
|
72
|
3410 value = cf->args->elts;
|
126
|
3411
|
252
|
3412 ngx_memzero(&u, sizeof(ngx_url_t));
|
|
3413
|
|
3414 u.url = value[1];
|
|
3415 u.listen = 1;
|
266
|
3416 u.default_port = 80;
|
252
|
3417
|
340
|
3418 if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
|
252
|
3419 if (u.err) {
|
|
3420 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3421 "%s in \"%V\" of the \"listen\" directive",
|
|
3422 u.err, &u.url);
|
|
3423 }
|
|
3424
|
126
|
3425 return NGX_CONF_ERROR;
|
72
|
3426 }
|
|
3427
|
538
|
3428 ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t));
|
|
3429
|
558
|
3430 ngx_memcpy(&lsopt.u.sockaddr, u.sockaddr, u.socklen);
|
538
|
3431
|
|
3432 lsopt.socklen = u.socklen;
|
|
3433 lsopt.backlog = NGX_LISTEN_BACKLOG;
|
|
3434 lsopt.rcvbuf = -1;
|
|
3435 lsopt.sndbuf = -1;
|
584
|
3436 #if (NGX_HAVE_SETFIB)
|
|
3437 lsopt.setfib = -1;
|
|
3438 #endif
|
538
|
3439 lsopt.wildcard = u.wildcard;
|
|
3440
|
558
|
3441 (void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.addr,
|
448
|
3442 NGX_SOCKADDR_STRLEN, 1);
|
180
|
3443
|
538
|
3444 for (n = 2; n < cf->args->nelts; n++) {
|
|
3445
|
|
3446 if (ngx_strcmp(value[n].data, "default_server") == 0
|
|
3447 || ngx_strcmp(value[n].data, "default") == 0)
|
|
3448 {
|
|
3449 lsopt.default_server = 1;
|
|
3450 continue;
|
72
|
3451 }
|
|
3452
|
|
3453 if (ngx_strcmp(value[n].data, "bind") == 0) {
|
538
|
3454 lsopt.set = 1;
|
|
3455 lsopt.bind = 1;
|
72
|
3456 continue;
|
|
3457 }
|
|
3458
|
584
|
3459 #if (NGX_HAVE_SETFIB)
|
|
3460 if (ngx_strncmp(value[n].data, "setfib=", 7) == 0) {
|
|
3461 lsopt.setfib = ngx_atoi(value[n].data + 7, value[n].len - 7);
|
|
3462
|
586
|
3463 if (lsopt.setfib == NGX_ERROR) {
|
584
|
3464 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3465 "invalid setfib \"%V\"", &value[n]);
|
|
3466 return NGX_CONF_ERROR;
|
|
3467 }
|
|
3468
|
|
3469 continue;
|
|
3470 }
|
|
3471 #endif
|
112
|
3472 if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) {
|
538
|
3473 lsopt.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8);
|
|
3474 lsopt.set = 1;
|
|
3475 lsopt.bind = 1;
|
|
3476
|
|
3477 if (lsopt.backlog == NGX_ERROR || lsopt.backlog == 0) {
|
72
|
3478 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3479 "invalid backlog \"%V\"", &value[n]);
|
|
3480 return NGX_CONF_ERROR;
|
|
3481 }
|
|
3482
|
|
3483 continue;
|
|
3484 }
|
|
3485
|
112
|
3486 if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) {
|
|
3487 size.len = value[n].len - 7;
|
|
3488 size.data = value[n].data + 7;
|
|
3489
|
538
|
3490 lsopt.rcvbuf = ngx_parse_size(&size);
|
|
3491 lsopt.set = 1;
|
|
3492 lsopt.bind = 1;
|
|
3493
|
|
3494 if (lsopt.rcvbuf == NGX_ERROR) {
|
112
|
3495 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3496 "invalid rcvbuf \"%V\"", &value[n]);
|
|
3497 return NGX_CONF_ERROR;
|
|
3498 }
|
|
3499
|
|
3500 continue;
|
|
3501 }
|
|
3502
|
|
3503 if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) {
|
|
3504 size.len = value[n].len - 7;
|
|
3505 size.data = value[n].data + 7;
|
|
3506
|
538
|
3507 lsopt.sndbuf = ngx_parse_size(&size);
|
|
3508 lsopt.set = 1;
|
|
3509 lsopt.bind = 1;
|
|
3510
|
|
3511 if (lsopt.sndbuf == NGX_ERROR) {
|
112
|
3512 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3513 "invalid sndbuf \"%V\"", &value[n]);
|
|
3514 return NGX_CONF_ERROR;
|
|
3515 }
|
|
3516
|
|
3517 continue;
|
|
3518 }
|
|
3519
|
|
3520 if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) {
|
72
|
3521 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
|
538
|
3522 lsopt.accept_filter = (char *) &value[n].data[14];
|
|
3523 lsopt.set = 1;
|
|
3524 lsopt.bind = 1;
|
72
|
3525 #else
|
|
3526 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3527 "accept filters \"%V\" are not supported "
|
|
3528 "on this platform, ignored",
|
|
3529 &value[n]);
|
|
3530 #endif
|
|
3531 continue;
|
|
3532 }
|
|
3533
|
|
3534 if (ngx_strcmp(value[n].data, "deferred") == 0) {
|
|
3535 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
|
538
|
3536 lsopt.deferred_accept = 1;
|
|
3537 lsopt.set = 1;
|
|
3538 lsopt.bind = 1;
|
72
|
3539 #else
|
|
3540 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3541 "the deferred accept is not supported "
|
|
3542 "on this platform, ignored");
|
|
3543 #endif
|
|
3544 continue;
|
|
3545 }
|
0
|
3546
|
460
|
3547 if (ngx_strncmp(value[n].data, "ipv6only=o", 10) == 0) {
|
|
3548 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
|
|
3549 struct sockaddr *sa;
|
|
3550
|
558
|
3551 sa = &lsopt.u.sockaddr;
|
460
|
3552
|
|
3553 if (sa->sa_family == AF_INET6) {
|
|
3554
|
|
3555 if (ngx_strcmp(&value[n].data[10], "n") == 0) {
|
538
|
3556 lsopt.ipv6only = 1;
|
460
|
3557
|
|
3558 } else if (ngx_strcmp(&value[n].data[10], "ff") == 0) {
|
538
|
3559 lsopt.ipv6only = 2;
|
460
|
3560
|
|
3561 } else {
|
|
3562 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3563 "invalid ipv6only flags \"%s\"",
|
|
3564 &value[n].data[9]);
|
|
3565 return NGX_CONF_ERROR;
|
|
3566 }
|
|
3567
|
538
|
3568 lsopt.set = 1;
|
|
3569 lsopt.bind = 1;
|
460
|
3570
|
|
3571 } else {
|
|
3572 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3573 "ipv6only is not supported "
|
538
|
3574 "on addr \"%s\", ignored", lsopt.addr);
|
460
|
3575 }
|
|
3576
|
|
3577 continue;
|
|
3578 #else
|
|
3579 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3580 "bind ipv6only is not supported "
|
|
3581 "on this platform");
|
|
3582 return NGX_CONF_ERROR;
|
|
3583 #endif
|
|
3584 }
|
|
3585
|
404
|
3586 if (ngx_strcmp(value[n].data, "ssl") == 0) {
|
|
3587 #if (NGX_HTTP_SSL)
|
538
|
3588 lsopt.ssl = 1;
|
404
|
3589 continue;
|
|
3590 #else
|
|
3591 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3592 "the \"ssl\" parameter requires "
|
|
3593 "ngx_http_ssl_module");
|
|
3594 return NGX_CONF_ERROR;
|
|
3595 #endif
|
|
3596 }
|
|
3597
|
0
|
3598 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
72
|
3599 "the invalid \"%V\" parameter", &value[n]);
|
0
|
3600 return NGX_CONF_ERROR;
|
|
3601 }
|
|
3602
|
538
|
3603 if (ngx_http_add_listen(cf, cscf, &lsopt) == NGX_OK) {
|
|
3604 return NGX_CONF_OK;
|
|
3605 }
|
|
3606
|
|
3607 return NGX_CONF_ERROR;
|
0
|
3608 }
|
|
3609
|
|
3610
|
36
|
3611 static char *
|
|
3612 ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
3613 {
|
142
|
3614 ngx_http_core_srv_conf_t *cscf = conf;
|
|
3615
|
|
3616 u_char ch;
|
|
3617 ngx_str_t *value, name;
|
|
3618 ngx_uint_t i;
|
|
3619 ngx_http_server_name_t *sn;
|
0
|
3620
|
|
3621 value = cf->args->elts;
|
|
3622
|
142
|
3623 ch = value[1].data[0];
|
|
3624
|
400
|
3625 if (cscf->server_name.data == NULL) {
|
592
|
3626 name = value[1];
|
|
3627
|
|
3628 if (ch == '.') {
|
|
3629 name.len--;
|
|
3630 name.data++;
|
|
3631 }
|
|
3632
|
|
3633 cscf->server_name.len = name.len;
|
|
3634 cscf->server_name.data = ngx_pstrdup(cf->pool, &name);
|
|
3635 if (cscf->server_name.data == NULL) {
|
142
|
3636 return NGX_CONF_ERROR;
|
|
3637 }
|
|
3638 }
|
|
3639
|
|
3640 for (i = 1; i < cf->args->nelts; i++) {
|
|
3641
|
|
3642 ch = value[i].data[0];
|
|
3643
|
400
|
3644 if ((ch == '*' && (value[i].len < 3 || value[i].data[1] != '.'))
|
142
|
3645 || (ch == '.' && value[i].len < 2))
|
|
3646 {
|
|
3647 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3648 "server name \"%V\" is invalid", &value[i]);
|
|
3649 return NGX_CONF_ERROR;
|
|
3650 }
|
|
3651
|
294
|
3652 if (ngx_strchr(value[i].data, '/')) {
|
|
3653 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
3654 "server name \"%V\" has strange symbols",
|
|
3655 &value[i]);
|
|
3656 }
|
|
3657
|
362
|
3658 if (value[i].len == 1 && ch == '*') {
|
|
3659 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3660 "\"server_name *\" is unsupported, use "
|
|
3661 "\"server_name_in_redirect off\" instead");
|
|
3662 return NGX_CONF_ERROR;
|
|
3663 }
|
|
3664
|
142
|
3665 sn = ngx_array_push(&cscf->server_names);
|
50
|
3666 if (sn == NULL) {
|
4
|
3667 return NGX_CONF_ERROR;
|
|
3668 }
|
0
|
3669
|
326
|
3670 #if (NGX_PCRE)
|
|
3671 sn->regex = NULL;
|
|
3672 #endif
|
538
|
3673 sn->server = cscf;
|
358
|
3674 sn->name = value[i];
|
326
|
3675
|
|
3676 if (value[i].data[0] != '~') {
|
554
|
3677 ngx_strlow(sn->name.data, sn->name.data, sn->name.len);
|
326
|
3678 continue;
|
|
3679 }
|
|
3680
|
|
3681 #if (NGX_PCRE)
|
356
|
3682 {
|
554
|
3683 u_char *p;
|
|
3684 ngx_regex_compile_t rc;
|
|
3685 u_char errstr[NGX_MAX_CONF_ERRSTR];
|
356
|
3686
|
526
|
3687 if (value[i].len == 1) {
|
|
3688 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3689 "empty regex in server name \"%V\"", &value[i]);
|
|
3690 return NGX_CONF_ERROR;
|
|
3691 }
|
|
3692
|
326
|
3693 value[i].len--;
|
|
3694 value[i].data++;
|
|
3695
|
546
|
3696 ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
|
|
3697
|
|
3698 rc.pattern = value[i];
|
|
3699 rc.err.len = NGX_MAX_CONF_ERRSTR;
|
|
3700 rc.err.data = errstr;
|
|
3701
|
554
|
3702 for (p = value[i].data; p < value[i].data + value[i].len; p++) {
|
|
3703 if (*p >= 'A' && *p <= 'Z') {
|
|
3704 rc.options = NGX_REGEX_CASELESS;
|
|
3705 break;
|
|
3706 }
|
|
3707 }
|
|
3708
|
546
|
3709 sn->regex = ngx_http_regex_compile(cf, &rc);
|
326
|
3710 if (sn->regex == NULL) {
|
|
3711 return NGX_CONF_ERROR;
|
|
3712 }
|
|
3713
|
358
|
3714 sn->name = value[i];
|
546
|
3715 cscf->captures = (rc.captures > 0);
|
356
|
3716 }
|
326
|
3717 #else
|
|
3718 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3719 "the using of the regex \"%V\" "
|
|
3720 "requires PCRE library", &value[i]);
|
|
3721
|
|
3722 return NGX_CONF_ERROR;
|
|
3723 #endif
|
0
|
3724 }
|
|
3725
|
|
3726 return NGX_CONF_OK;
|
|
3727 }
|
|
3728
|
|
3729
|
36
|
3730 static char *
|
|
3731 ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
3732 {
|
546
|
3733 ngx_http_core_loc_conf_t *clcf = conf;
|
0
|
3734
|
144
|
3735 ngx_str_t *value;
|
574
|
3736 ngx_int_t alias;
|
|
3737 ngx_uint_t n;
|
144
|
3738 ngx_http_script_compile_t sc;
|
0
|
3739
|
|
3740 alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0;
|
|
3741
|
546
|
3742 if (clcf->root.data) {
|
0
|
3743
|
574
|
3744 if ((clcf->alias != 0) == alias) {
|
0
|
3745 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
3746 "\"%V\" directive is duplicate",
|
|
3747 &cmd->name);
|
0
|
3748 } else {
|
|
3749 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
3750 "\"%V\" directive is duplicate, "
|
0
|
3751 "\"%s\" directive is specified before",
|
546
|
3752 &cmd->name, clcf->alias ? "alias" : "root");
|
0
|
3753 }
|
|
3754
|
|
3755 return NGX_CONF_ERROR;
|
|
3756 }
|
|
3757
|
546
|
3758 if (clcf->named && alias) {
|
324
|
3759 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3760 "the \"alias\" directive may not be used "
|
|
3761 "inside named location");
|
|
3762
|
|
3763 return NGX_CONF_ERROR;
|
|
3764 }
|
|
3765
|
0
|
3766 value = cf->args->elts;
|
|
3767
|
294
|
3768 if (ngx_strstr(value[1].data, "$document_root")
|
|
3769 || ngx_strstr(value[1].data, "${document_root}"))
|
|
3770 {
|
|
3771 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3772 "the $document_root variable may not be used "
|
|
3773 "in the \"%V\" directive",
|
|
3774 &cmd->name);
|
|
3775
|
|
3776 return NGX_CONF_ERROR;
|
|
3777 }
|
|
3778
|
412
|
3779 if (ngx_strstr(value[1].data, "$realpath_root")
|
|
3780 || ngx_strstr(value[1].data, "${realpath_root}"))
|
|
3781 {
|
|
3782 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3783 "the $realpath_root variable may not be used "
|
|
3784 "in the \"%V\" directive",
|
|
3785 &cmd->name);
|
|
3786
|
|
3787 return NGX_CONF_ERROR;
|
|
3788 }
|
|
3789
|
574
|
3790 clcf->alias = alias ? clcf->name.len : 0;
|
546
|
3791 clcf->root = value[1];
|
|
3792
|
|
3793 if (!alias && clcf->root.data[clcf->root.len - 1] == '/') {
|
|
3794 clcf->root.len--;
|
0
|
3795 }
|
|
3796
|
546
|
3797 if (clcf->root.data[0] != '$') {
|
|
3798 if (ngx_conf_full_name(cf->cycle, &clcf->root, 0) != NGX_OK) {
|
216
|
3799 return NGX_CONF_ERROR;
|
|
3800 }
|
152
|
3801 }
|
|
3802
|
546
|
3803 n = ngx_http_script_variables_count(&clcf->root);
|
144
|
3804
|
456
|
3805 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
596
|
3806 sc.variables = n;
|
|
3807
|
|
3808 #if (NGX_PCRE)
|
|
3809 if (alias && clcf->regex) {
|
|
3810 n = 1;
|
|
3811 }
|
|
3812 #endif
|
456
|
3813
|
|
3814 if (n) {
|
|
3815 sc.cf = cf;
|
546
|
3816 sc.source = &clcf->root;
|
|
3817 sc.lengths = &clcf->root_lengths;
|
|
3818 sc.values = &clcf->root_values;
|
456
|
3819 sc.complete_lengths = 1;
|
|
3820 sc.complete_values = 1;
|
|
3821
|
|
3822 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
3823 return NGX_CONF_ERROR;
|
|
3824 }
|
144
|
3825 }
|
|
3826
|
0
|
3827 return NGX_CONF_OK;
|
|
3828 }
|
|
3829
|
|
3830
|
180
|
3831 static ngx_http_method_name_t ngx_methods_names[] = {
|
286
|
3832 { (u_char *) "GET", (uint32_t) ~NGX_HTTP_GET },
|
|
3833 { (u_char *) "HEAD", (uint32_t) ~NGX_HTTP_HEAD },
|
|
3834 { (u_char *) "POST", (uint32_t) ~NGX_HTTP_POST },
|
|
3835 { (u_char *) "PUT", (uint32_t) ~NGX_HTTP_PUT },
|
|
3836 { (u_char *) "DELETE", (uint32_t) ~NGX_HTTP_DELETE },
|
|
3837 { (u_char *) "MKCOL", (uint32_t) ~NGX_HTTP_MKCOL },
|
|
3838 { (u_char *) "COPY", (uint32_t) ~NGX_HTTP_COPY },
|
|
3839 { (u_char *) "MOVE", (uint32_t) ~NGX_HTTP_MOVE },
|
|
3840 { (u_char *) "OPTIONS", (uint32_t) ~NGX_HTTP_OPTIONS },
|
|
3841 { (u_char *) "PROPFIND" , (uint32_t) ~NGX_HTTP_PROPFIND },
|
|
3842 { (u_char *) "PROPPATCH", (uint32_t) ~NGX_HTTP_PROPPATCH },
|
|
3843 { (u_char *) "LOCK", (uint32_t) ~NGX_HTTP_LOCK },
|
|
3844 { (u_char *) "UNLOCK", (uint32_t) ~NGX_HTTP_UNLOCK },
|
578
|
3845 { (u_char *) "PATCH", (uint32_t) ~NGX_HTTP_PATCH },
|
180
|
3846 { NULL, 0 }
|
|
3847 };
|
|
3848
|
|
3849
|
|
3850 static char *
|
|
3851 ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
3852 {
|
378
|
3853 ngx_http_core_loc_conf_t *pclcf = conf;
|
180
|
3854
|
|
3855 char *rv;
|
|
3856 void *mconf;
|
|
3857 ngx_str_t *value;
|
|
3858 ngx_uint_t i;
|
|
3859 ngx_conf_t save;
|
|
3860 ngx_http_module_t *module;
|
|
3861 ngx_http_conf_ctx_t *ctx, *pctx;
|
|
3862 ngx_http_method_name_t *name;
|
378
|
3863 ngx_http_core_loc_conf_t *clcf;
|
|
3864
|
|
3865 if (pclcf->limit_except) {
|
180
|
3866 return "duplicate";
|
|
3867 }
|
|
3868
|
378
|
3869 pclcf->limit_except = 0xffffffff;
|
180
|
3870
|
|
3871 value = cf->args->elts;
|
|
3872
|
|
3873 for (i = 1; i < cf->args->nelts; i++) {
|
|
3874 for (name = ngx_methods_names; name->name; name++) {
|
|
3875
|
|
3876 if (ngx_strcasecmp(value[i].data, name->name) == 0) {
|
378
|
3877 pclcf->limit_except &= name->method;
|
180
|
3878 goto next;
|
|
3879 }
|
|
3880 }
|
|
3881
|
|
3882 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3883 "invalid method \"%V\"", &value[i]);
|
|
3884 return NGX_CONF_ERROR;
|
|
3885
|
|
3886 next:
|
|
3887 continue;
|
|
3888 }
|
|
3889
|
378
|
3890 if (!(pclcf->limit_except & NGX_HTTP_GET)) {
|
|
3891 pclcf->limit_except &= (uint32_t) ~NGX_HTTP_HEAD;
|
180
|
3892 }
|
|
3893
|
|
3894 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
|
|
3895 if (ctx == NULL) {
|
|
3896 return NGX_CONF_ERROR;
|
|
3897 }
|
|
3898
|
|
3899 pctx = cf->ctx;
|
|
3900 ctx->main_conf = pctx->main_conf;
|
|
3901 ctx->srv_conf = pctx->srv_conf;
|
|
3902
|
|
3903 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
3904 if (ctx->loc_conf == NULL) {
|
|
3905 return NGX_CONF_ERROR;
|
|
3906 }
|
|
3907
|
|
3908 for (i = 0; ngx_modules[i]; i++) {
|
|
3909 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
|
|
3910 continue;
|
|
3911 }
|
|
3912
|
|
3913 module = ngx_modules[i]->ctx;
|
|
3914
|
|
3915 if (module->create_loc_conf) {
|
|
3916
|
|
3917 mconf = module->create_loc_conf(cf);
|
|
3918 if (mconf == NULL) {
|
|
3919 return NGX_CONF_ERROR;
|
|
3920 }
|
|
3921
|
|
3922 ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
|
|
3923 }
|
|
3924 }
|
|
3925
|
|
3926
|
378
|
3927 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
|
|
3928 pclcf->limit_except_loc_conf = ctx->loc_conf;
|
|
3929 clcf->loc_conf = ctx->loc_conf;
|
|
3930 clcf->name = pclcf->name;
|
|
3931 clcf->noname = 1;
|
592
|
3932 clcf->lmt_excpt = 1;
|
378
|
3933
|
|
3934 if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
|
180
|
3935 return NGX_CONF_ERROR;
|
|
3936 }
|
|
3937
|
|
3938 save = *cf;
|
|
3939 cf->ctx = ctx;
|
|
3940 cf->cmd_type = NGX_HTTP_LMT_CONF;
|
|
3941
|
|
3942 rv = ngx_conf_parse(cf, NULL);
|
|
3943
|
|
3944 *cf = save;
|
|
3945
|
|
3946 return rv;
|
|
3947 }
|
|
3948
|
|
3949
|
36
|
3950 static char *
|
390
|
3951 ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
3952 {
|
|
3953 ngx_http_core_loc_conf_t *clcf = conf;
|
|
3954
|
|
3955 ngx_str_t *value;
|
|
3956
|
|
3957 if (clcf->directio != NGX_CONF_UNSET) {
|
|
3958 return "is duplicate";
|
|
3959 }
|
|
3960
|
|
3961 value = cf->args->elts;
|
|
3962
|
|
3963 if (ngx_strcmp(value[1].data, "off") == 0) {
|
416
|
3964 clcf->directio = NGX_OPEN_FILE_DIRECTIO_OFF;
|
390
|
3965 return NGX_CONF_OK;
|
|
3966 }
|
|
3967
|
|
3968 clcf->directio = ngx_parse_offset(&value[1]);
|
|
3969 if (clcf->directio == (off_t) NGX_ERROR) {
|
|
3970 return "invalid value";
|
|
3971 }
|
|
3972
|
|
3973 return NGX_CONF_OK;
|
|
3974 }
|
|
3975
|
|
3976
|
|
3977 static char *
|
36
|
3978 ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
3979 {
|
546
|
3980 ngx_http_core_loc_conf_t *clcf = conf;
|
0
|
3981
|
464
|
3982 u_char *p;
|
|
3983 ngx_int_t overwrite;
|
|
3984 ngx_str_t *value, uri, args;
|
|
3985 ngx_uint_t i, n;
|
|
3986 ngx_http_err_page_t *err;
|
|
3987 ngx_http_complex_value_t cv;
|
|
3988 ngx_http_compile_complex_value_t ccv;
|
0
|
3989
|
546
|
3990 if (clcf->error_pages == NULL) {
|
|
3991 clcf->error_pages = ngx_array_create(cf->pool, 4,
|
|
3992 sizeof(ngx_http_err_page_t));
|
|
3993 if (clcf->error_pages == NULL) {
|
0
|
3994 return NGX_CONF_ERROR;
|
|
3995 }
|
|
3996 }
|
|
3997
|
|
3998 value = cf->args->elts;
|
|
3999
|
|
4000 i = cf->args->nelts - 2;
|
|
4001
|
|
4002 if (value[i].data[0] == '=') {
|
|
4003 if (i == 1) {
|
|
4004 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
4005 "invalid value \"%V\"", &value[i]);
|
0
|
4006 return NGX_CONF_ERROR;
|
|
4007 }
|
|
4008
|
104
|
4009 if (value[i].len > 1) {
|
|
4010 overwrite = ngx_atoi(&value[i].data[1], value[i].len - 1);
|
|
4011
|
|
4012 if (overwrite == NGX_ERROR) {
|
|
4013 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4014 "invalid value \"%V\"", &value[i]);
|
|
4015 return NGX_CONF_ERROR;
|
|
4016 }
|
|
4017
|
|
4018 } else {
|
|
4019 overwrite = 0;
|
0
|
4020 }
|
|
4021
|
|
4022 n = 2;
|
|
4023
|
|
4024 } else {
|
104
|
4025 overwrite = -1;
|
0
|
4026 n = 1;
|
|
4027 }
|
|
4028
|
222
|
4029 uri = value[cf->args->nelts - 1];
|
464
|
4030
|
|
4031 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
|
|
4032
|
|
4033 ccv.cf = cf;
|
|
4034 ccv.value = &uri;
|
|
4035 ccv.complex_value = &cv;
|
|
4036
|
|
4037 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
|
|
4038 return NGX_CONF_ERROR;
|
|
4039 }
|
|
4040
|
570
|
4041 ngx_str_null(&args);
|
464
|
4042
|
478
|
4043 if (cv.lengths == NULL && uri.data[0] == '/') {
|
464
|
4044 p = (u_char *) ngx_strchr(uri.data, '?');
|
|
4045
|
|
4046 if (p) {
|
|
4047 cv.value.len = p - uri.data;
|
|
4048 cv.value.data = uri.data;
|
|
4049 p++;
|
|
4050 args.len = (uri.data + uri.len) - p;
|
|
4051 args.data = p;
|
222
|
4052 }
|
|
4053 }
|
|
4054
|
0
|
4055 for (i = 1; i < cf->args->nelts - n; i++) {
|
546
|
4056 err = ngx_array_push(clcf->error_pages);
|
50
|
4057 if (err == NULL) {
|
0
|
4058 return NGX_CONF_ERROR;
|
|
4059 }
|
|
4060
|
|
4061 err->status = ngx_atoi(value[i].data, value[i].len);
|
36
|
4062
|
236
|
4063 if (err->status == NGX_ERROR || err->status == 499) {
|
0
|
4064 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
4065 "invalid value \"%V\"", &value[i]);
|
0
|
4066 return NGX_CONF_ERROR;
|
|
4067 }
|
|
4068
|
558
|
4069 if (err->status < 300 || err->status > 599) {
|
0
|
4070 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
558
|
4071 "value \"%V\" must be between 300 and 599",
|
10
|
4072 &value[i]);
|
0
|
4073 return NGX_CONF_ERROR;
|
|
4074 }
|
|
4075
|
602
|
4076 err->overwrite = overwrite;
|
|
4077
|
|
4078 if (overwrite == -1) {
|
366
|
4079 switch (err->status) {
|
|
4080 case NGX_HTTP_TO_HTTPS:
|
|
4081 case NGX_HTTPS_CERT_ERROR:
|
|
4082 case NGX_HTTPS_NO_CERT:
|
|
4083 err->overwrite = NGX_HTTP_BAD_REQUEST;
|
|
4084 default:
|
|
4085 break;
|
|
4086 }
|
|
4087 }
|
104
|
4088
|
464
|
4089 err->value = cv;
|
|
4090 err->args = args;
|
0
|
4091 }
|
|
4092
|
|
4093 return NGX_CONF_OK;
|
|
4094 }
|
|
4095
|
|
4096
|
36
|
4097 static char *
|
430
|
4098 ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
4099 {
|
|
4100 ngx_http_core_loc_conf_t *clcf = conf;
|
|
4101
|
|
4102 ngx_str_t *value;
|
478
|
4103 ngx_int_t code;
|
430
|
4104 ngx_uint_t i, n;
|
|
4105 ngx_http_try_file_t *tf;
|
|
4106 ngx_http_script_compile_t sc;
|
|
4107 ngx_http_core_main_conf_t *cmcf;
|
|
4108
|
|
4109 if (clcf->try_files) {
|
|
4110 return "is duplicate";
|
|
4111 }
|
|
4112
|
|
4113 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
|
|
4114
|
|
4115 cmcf->try_files = 1;
|
|
4116
|
|
4117 tf = ngx_pcalloc(cf->pool, cf->args->nelts * sizeof(ngx_http_try_file_t));
|
|
4118 if (tf == NULL) {
|
|
4119 return NGX_CONF_ERROR;
|
|
4120 }
|
|
4121
|
|
4122 clcf->try_files = tf;
|
|
4123
|
|
4124 value = cf->args->elts;
|
|
4125
|
|
4126 for (i = 0; i < cf->args->nelts - 1; i++) {
|
|
4127
|
|
4128 tf[i].name = value[i + 1];
|
|
4129
|
440
|
4130 if (tf[i].name.data[tf[i].name.len - 1] == '/') {
|
|
4131 tf[i].test_dir = 1;
|
|
4132 tf[i].name.len--;
|
464
|
4133 tf[i].name.data[tf[i].name.len] = '\0';
|
440
|
4134 }
|
|
4135
|
430
|
4136 n = ngx_http_script_variables_count(&tf[i].name);
|
|
4137
|
|
4138 if (n) {
|
|
4139 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
4140
|
|
4141 sc.cf = cf;
|
|
4142 sc.source = &tf[i].name;
|
|
4143 sc.lengths = &tf[i].lengths;
|
|
4144 sc.values = &tf[i].values;
|
|
4145 sc.variables = n;
|
|
4146 sc.complete_lengths = 1;
|
|
4147 sc.complete_values = 1;
|
|
4148
|
|
4149 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
4150 return NGX_CONF_ERROR;
|
|
4151 }
|
|
4152
|
|
4153 } else {
|
|
4154 /* add trailing '\0' to length */
|
|
4155 tf[i].name.len++;
|
|
4156 }
|
|
4157 }
|
|
4158
|
478
|
4159 if (tf[i - 1].name.data[0] == '=') {
|
|
4160
|
|
4161 code = ngx_atoi(tf[i - 1].name.data + 1, tf[i - 1].name.len - 2);
|
|
4162
|
|
4163 if (code == NGX_ERROR) {
|
|
4164 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4165 "invalid code \"%*s\"",
|
|
4166 tf[i - 1].name.len - 1, tf[i - 1].name.data);
|
|
4167 return NGX_CONF_ERROR;
|
|
4168 }
|
|
4169
|
|
4170 tf[i].code = code;
|
|
4171 }
|
|
4172
|
430
|
4173 return NGX_CONF_OK;
|
|
4174 }
|
|
4175
|
|
4176
|
|
4177 static char *
|
332
|
4178 ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
4179 {
|
546
|
4180 ngx_http_core_loc_conf_t *clcf = conf;
|
332
|
4181
|
|
4182 time_t inactive;
|
|
4183 ngx_str_t *value, s;
|
|
4184 ngx_int_t max;
|
|
4185 ngx_uint_t i;
|
|
4186
|
546
|
4187 if (clcf->open_file_cache != NGX_CONF_UNSET_PTR) {
|
332
|
4188 return "is duplicate";
|
|
4189 }
|
|
4190
|
|
4191 value = cf->args->elts;
|
|
4192
|
|
4193 max = 0;
|
|
4194 inactive = 60;
|
|
4195
|
|
4196 for (i = 1; i < cf->args->nelts; i++) {
|
|
4197
|
|
4198 if (ngx_strncmp(value[i].data, "max=", 4) == 0) {
|
|
4199
|
|
4200 max = ngx_atoi(value[i].data + 4, value[i].len - 4);
|
|
4201 if (max == NGX_ERROR) {
|
388
|
4202 goto failed;
|
332
|
4203 }
|
|
4204
|
|
4205 continue;
|
|
4206 }
|
|
4207
|
|
4208 if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) {
|
|
4209
|
|
4210 s.len = value[i].len - 9;
|
|
4211 s.data = value[i].data + 9;
|
|
4212
|
|
4213 inactive = ngx_parse_time(&s, 1);
|
|
4214 if (inactive < 0) {
|
388
|
4215 goto failed;
|
332
|
4216 }
|
|
4217
|
|
4218 continue;
|
|
4219 }
|
|
4220
|
|
4221 if (ngx_strcmp(value[i].data, "off") == 0) {
|
|
4222
|
546
|
4223 clcf->open_file_cache = NULL;
|
332
|
4224
|
|
4225 continue;
|
|
4226 }
|
|
4227
|
388
|
4228 failed:
|
|
4229
|
332
|
4230 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4231 "invalid \"open_file_cache\" parameter \"%V\"",
|
|
4232 &value[i]);
|
|
4233 return NGX_CONF_ERROR;
|
|
4234 }
|
|
4235
|
546
|
4236 if (clcf->open_file_cache == NULL) {
|
332
|
4237 return NGX_CONF_OK;
|
|
4238 }
|
|
4239
|
|
4240 if (max == 0) {
|
|
4241 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4242 "\"open_file_cache\" must have \"max\" parameter");
|
|
4243 return NGX_CONF_ERROR;
|
|
4244 }
|
|
4245
|
546
|
4246 clcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive);
|
|
4247 if (clcf->open_file_cache) {
|
332
|
4248 return NGX_CONF_OK;
|
|
4249 }
|
|
4250
|
|
4251 return NGX_CONF_ERROR;
|
|
4252 }
|
|
4253
|
|
4254
|
|
4255 static char *
|
58
|
4256 ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
4257 {
|
546
|
4258 ngx_http_core_loc_conf_t *clcf = conf;
|
58
|
4259
|
482
|
4260 ngx_str_t *value;
|
|
4261
|
546
|
4262 if (clcf->error_log) {
|
484
|
4263 return "is duplicate";
|
|
4264 }
|
|
4265
|
482
|
4266 value = cf->args->elts;
|
|
4267
|
546
|
4268 clcf->error_log = ngx_log_create(cf->cycle, &value[1]);
|
|
4269 if (clcf->error_log == NULL) {
|
58
|
4270 return NGX_CONF_ERROR;
|
|
4271 }
|
|
4272
|
484
|
4273 if (cf->args->nelts == 2) {
|
546
|
4274 clcf->error_log->log_level = NGX_LOG_ERR;
|
484
|
4275 return NGX_CONF_OK;
|
|
4276 }
|
|
4277
|
546
|
4278 return ngx_log_set_levels(cf, clcf->error_log);
|
58
|
4279 }
|
|
4280
|
|
4281
|
|
4282 static char *
|
36
|
4283 ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
4284 {
|
546
|
4285 ngx_http_core_loc_conf_t *clcf = conf;
|
0
|
4286
|
|
4287 ngx_str_t *value;
|
|
4288
|
546
|
4289 if (clcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) {
|
0
|
4290 return "is duplicate";
|
|
4291 }
|
|
4292
|
|
4293 value = cf->args->elts;
|
|
4294
|
546
|
4295 clcf->keepalive_timeout = ngx_parse_time(&value[1], 0);
|
|
4296
|
|
4297 if (clcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) {
|
0
|
4298 return "invalid value";
|
|
4299 }
|
|
4300
|
546
|
4301 if (clcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) {
|
0
|
4302 return "value must be less than 597 hours";
|
|
4303 }
|
|
4304
|
|
4305 if (cf->args->nelts == 2) {
|
|
4306 return NGX_CONF_OK;
|
|
4307 }
|
|
4308
|
546
|
4309 clcf->keepalive_header = ngx_parse_time(&value[2], 1);
|
|
4310
|
|
4311 if (clcf->keepalive_header == NGX_ERROR) {
|
0
|
4312 return "invalid value";
|
|
4313 }
|
|
4314
|
546
|
4315 if (clcf->keepalive_header == NGX_PARSE_LARGE_TIME) {
|
0
|
4316 return "value must be less than 68 years";
|
|
4317 }
|
|
4318
|
|
4319 return NGX_CONF_OK;
|
|
4320 }
|
|
4321
|
|
4322
|
36
|
4323 static char *
|
58
|
4324 ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
4325 {
|
546
|
4326 ngx_http_core_loc_conf_t *clcf = conf;
|
|
4327
|
|
4328 if (clcf->internal != NGX_CONF_UNSET) {
|
58
|
4329 return "is duplicate";
|
0
|
4330 }
|
|
4331
|
546
|
4332 clcf->internal = 1;
|
58
|
4333
|
|
4334 return NGX_CONF_OK;
|
0
|
4335 }
|
|
4336
|
|
4337
|
36
|
4338 static char *
|
348
|
4339 ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
4340 {
|
|
4341 ngx_http_core_loc_conf_t *clcf = conf;
|
|
4342
|
|
4343 ngx_url_t u;
|
|
4344 ngx_str_t *value;
|
|
4345
|
366
|
4346 if (clcf->resolver) {
|
|
4347 return "is duplicate";
|
|
4348 }
|
|
4349
|
348
|
4350 value = cf->args->elts;
|
|
4351
|
354
|
4352 ngx_memzero(&u, sizeof(ngx_url_t));
|
|
4353
|
348
|
4354 u.host = value[1];
|
|
4355 u.port = 53;
|
|
4356
|
|
4357 if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
|
|
4358 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V: %s", &u.host, u.err);
|
|
4359 return NGX_CONF_ERROR;
|
|
4360 }
|
|
4361
|
366
|
4362 clcf->resolver = ngx_resolver_create(cf, &u.addrs[0]);
|
348
|
4363 if (clcf->resolver == NULL) {
|
|
4364 return NGX_OK;
|
|
4365 }
|
|
4366
|
|
4367 return NGX_CONF_OK;
|
|
4368 }
|
|
4369
|
|
4370
|
358
|
4371 #if (NGX_HTTP_GZIP)
|
|
4372
|
|
4373 static char *
|
|
4374 ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
4375 {
|
400
|
4376 ngx_http_core_loc_conf_t *clcf = conf;
|
|
4377
|
358
|
4378 #if (NGX_PCRE)
|
|
4379
|
546
|
4380 ngx_str_t *value;
|
|
4381 ngx_uint_t i;
|
|
4382 ngx_regex_elt_t *re;
|
|
4383 ngx_regex_compile_t rc;
|
|
4384 u_char errstr[NGX_MAX_CONF_ERRSTR];
|
358
|
4385
|
|
4386 if (clcf->gzip_disable == NGX_CONF_UNSET_PTR) {
|
|
4387 clcf->gzip_disable = ngx_array_create(cf->pool, 2,
|
|
4388 sizeof(ngx_regex_elt_t));
|
|
4389 if (clcf->gzip_disable == NULL) {
|
|
4390 return NGX_CONF_ERROR;
|
|
4391 }
|
|
4392 }
|
|
4393
|
|
4394 value = cf->args->elts;
|
|
4395
|
546
|
4396 ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
|
|
4397
|
|
4398 rc.pool = cf->pool;
|
|
4399 rc.err.len = NGX_MAX_CONF_ERRSTR;
|
|
4400 rc.err.data = errstr;
|
358
|
4401
|
|
4402 for (i = 1; i < cf->args->nelts; i++) {
|
|
4403
|
596
|
4404 if (ngx_strcmp(value[i].data, "msie6") == 0) {
|
400
|
4405 clcf->gzip_disable_msie6 = 1;
|
|
4406 continue;
|
|
4407 }
|
|
4408
|
602
|
4409 #if (NGX_HTTP_DEGRADATION)
|
|
4410
|
|
4411 if (ngx_strcmp(value[i].data, "degradation") == 0) {
|
|
4412 clcf->gzip_disable_degradation = 1;
|
|
4413 continue;
|
|
4414 }
|
|
4415
|
|
4416 #endif
|
|
4417
|
358
|
4418 re = ngx_array_push(clcf->gzip_disable);
|
|
4419 if (re == NULL) {
|
|
4420 return NGX_CONF_ERROR;
|
|
4421 }
|
|
4422
|
596
|
4423 rc.pattern = value[i];
|
546
|
4424 rc.options = NGX_REGEX_CASELESS;
|
|
4425
|
|
4426 if (ngx_regex_compile(&rc) != NGX_OK) {
|
|
4427 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err);
|
358
|
4428 return NGX_CONF_ERROR;
|
|
4429 }
|
|
4430
|
546
|
4431 re->regex = rc.regex;
|
358
|
4432 re->name = value[i].data;
|
|
4433 }
|
|
4434
|
|
4435 return NGX_CONF_OK;
|
|
4436
|
|
4437 #else
|
602
|
4438 ngx_str_t *value;
|
|
4439 ngx_uint_t i;
|
400
|
4440
|
|
4441 value = cf->args->elts;
|
|
4442
|
602
|
4443 for (i = 1; i < cf->args->nelts; i++) {
|
|
4444 if (ngx_strcmp(value[i].data, "msie6") == 0) {
|
|
4445 clcf->gzip_disable_msie6 = 1;
|
|
4446 continue;
|
|
4447 }
|
|
4448
|
|
4449 #if (NGX_HTTP_DEGRADATION)
|
|
4450
|
|
4451 if (ngx_strcmp(value[i].data, "degradation") == 0) {
|
|
4452 clcf->gzip_disable_degradation = 1;
|
|
4453 continue;
|
|
4454 }
|
|
4455
|
|
4456 #endif
|
|
4457
|
|
4458 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4459 "without PCRE library \"gzip_disable\" supports "
|
|
4460 "builtin \"msie6\" and \"degradation\" mask only");
|
|
4461
|
|
4462 return NGX_CONF_ERROR;
|
400
|
4463 }
|
|
4464
|
602
|
4465 return NGX_CONF_OK;
|
|
4466
|
358
|
4467 #endif
|
|
4468 }
|
|
4469
|
|
4470 #endif
|
|
4471
|
|
4472
|
348
|
4473 static char *
|
36
|
4474 ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data)
|
0
|
4475 {
|
22
|
4476 #if (NGX_FREEBSD)
|
2
|
4477 ssize_t *np = data;
|
0
|
4478
|
222
|
4479 if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) {
|
0
|
4480 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4481 "\"send_lowat\" must be less than %d "
|
|
4482 "(sysctl net.inet.tcp.sendspace)",
|
|
4483 ngx_freebsd_net_inet_tcp_sendspace);
|
|
4484
|
|
4485 return NGX_CONF_ERROR;
|
|
4486 }
|
|
4487
|
18
|
4488 #elif !(NGX_HAVE_SO_SNDLOWAT)
|
22
|
4489 ssize_t *np = data;
|
0
|
4490
|
|
4491 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
4492 "\"send_lowat\" is not supported, ignored");
|
|
4493
|
2
|
4494 *np = 0;
|
|
4495
|
0
|
4496 #endif
|
|
4497
|
|
4498 return NGX_CONF_OK;
|
|
4499 }
|
300
|
4500
|
|
4501
|
|
4502 static char *
|
|
4503 ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data)
|
|
4504 {
|
|
4505 size_t *sp = data;
|
|
4506
|
|
4507 if (*sp < NGX_MIN_POOL_SIZE) {
|
|
4508 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
558
|
4509 "the pool size must be no less than %uz",
|
|
4510 NGX_MIN_POOL_SIZE);
|
|
4511 return NGX_CONF_ERROR;
|
|
4512 }
|
|
4513
|
|
4514 if (*sp % NGX_POOL_ALIGNMENT) {
|
|
4515 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4516 "the pool size must be a multiple of %uz",
|
|
4517 NGX_POOL_ALIGNMENT);
|
300
|
4518 return NGX_CONF_ERROR;
|
|
4519 }
|
|
4520
|
|
4521 return NGX_CONF_OK;
|
|
4522 }
|