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