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