3 * Copyright (C) Igor Sysoev
7 #include <ngx_config.h>
15 } ngx_http_method_name_t;
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
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);
27 static ngx_int_t ngx_http_core_preconfiguration(ngx_conf_t *cf);
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,
32 void *parent, void *child);
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,
35 void *parent, void *child);
37 static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd,
39 static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd,
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);
44 static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd,
46 static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy,
49 static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
51 static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
53 static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
54 static char *ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd,
56 static char *ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd,
58 static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd,
60 static char *ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd,
62 static char *ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd,
64 static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
66 static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
68 static char *ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd,
70 static char *ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
73 static char *ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd,
77 static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data);
78 static char *ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data);
80 static ngx_conf_post_t ngx_http_core_lowat_post =
81 { ngx_http_core_lowat_check };
83 static ngx_conf_post_handler_pt ngx_http_core_pool_size_p =
84 ngx_http_core_pool_size;
86 static ngx_conf_deprecated_t ngx_conf_deprecated_optimize_server_names = {
87 ngx_conf_deprecated, "optimize_server_names", "server_name_in_redirect"
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"
94 static ngx_conf_deprecated_t ngx_conf_deprecated_satisfy_any = {
95 ngx_conf_deprecated, "satisfy_any", "satisfy"
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 }
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 }
114 static ngx_conf_enum_t ngx_http_core_if_modified_since[] = {
115 { ngx_string("exact"), 0 },
116 { ngx_string("before"), 1 },
117 { ngx_null_string, 0 }
123 static ngx_conf_enum_t ngx_http_gzip_http_version[] = {
124 { ngx_string("1.0"), NGX_HTTP_VERSION_10 },
125 { ngx_string("1.1"), NGX_HTTP_VERSION_11 },
126 { ngx_null_string, 0 }
130 static ngx_conf_bitmask_t ngx_http_gzip_proxied_mask[] = {
131 { ngx_string("off"), NGX_HTTP_GZIP_PROXIED_OFF },
132 { ngx_string("expired"), NGX_HTTP_GZIP_PROXIED_EXPIRED },
133 { ngx_string("no-cache"), NGX_HTTP_GZIP_PROXIED_NO_CACHE },
134 { ngx_string("no-store"), NGX_HTTP_GZIP_PROXIED_NO_STORE },
135 { ngx_string("private"), NGX_HTTP_GZIP_PROXIED_PRIVATE },
136 { ngx_string("no_last_modified"), NGX_HTTP_GZIP_PROXIED_NO_LM },
137 { ngx_string("no_etag"), NGX_HTTP_GZIP_PROXIED_NO_ETAG },
138 { ngx_string("auth"), NGX_HTTP_GZIP_PROXIED_AUTH },
139 { ngx_string("any"), NGX_HTTP_GZIP_PROXIED_ANY },
140 { ngx_null_string, 0 }
144 static ngx_str_t ngx_http_gzip_no_cache = ngx_string("no-cache");
145 static ngx_str_t ngx_http_gzip_no_store = ngx_string("no-store");
146 static ngx_str_t ngx_http_gzip_private = ngx_string("private");
151 static ngx_command_t ngx_http_core_commands[] = {
153 { ngx_string("variables_hash_max_size"),
154 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
155 ngx_conf_set_num_slot,
156 NGX_HTTP_MAIN_CONF_OFFSET,
157 offsetof(ngx_http_core_main_conf_t, variables_hash_max_size),
160 { ngx_string("variables_hash_bucket_size"),
161 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
162 ngx_conf_set_num_slot,
163 NGX_HTTP_MAIN_CONF_OFFSET,
164 offsetof(ngx_http_core_main_conf_t, variables_hash_bucket_size),
167 { ngx_string("server_names_hash_max_size"),
168 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
169 ngx_conf_set_num_slot,
170 NGX_HTTP_MAIN_CONF_OFFSET,
171 offsetof(ngx_http_core_main_conf_t, server_names_hash_max_size),
174 { ngx_string("server_names_hash_bucket_size"),
175 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
176 ngx_conf_set_num_slot,
177 NGX_HTTP_MAIN_CONF_OFFSET,
178 offsetof(ngx_http_core_main_conf_t, server_names_hash_bucket_size),
181 { ngx_string("server"),
182 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_MULTI|NGX_CONF_NOARGS,
183 ngx_http_core_server,
188 { ngx_string("connection_pool_size"),
189 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
190 ngx_conf_set_size_slot,
191 NGX_HTTP_SRV_CONF_OFFSET,
192 offsetof(ngx_http_core_srv_conf_t, connection_pool_size),
193 &ngx_http_core_pool_size_p },
195 { ngx_string("request_pool_size"),
196 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
197 ngx_conf_set_size_slot,
198 NGX_HTTP_SRV_CONF_OFFSET,
199 offsetof(ngx_http_core_srv_conf_t, request_pool_size),
200 &ngx_http_core_pool_size_p },
202 { ngx_string("client_header_timeout"),
203 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
204 ngx_conf_set_msec_slot,
205 NGX_HTTP_SRV_CONF_OFFSET,
206 offsetof(ngx_http_core_srv_conf_t, client_header_timeout),
209 { ngx_string("client_header_buffer_size"),
210 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
211 ngx_conf_set_size_slot,
212 NGX_HTTP_SRV_CONF_OFFSET,
213 offsetof(ngx_http_core_srv_conf_t, client_header_buffer_size),
216 { ngx_string("large_client_header_buffers"),
217 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE2,
218 ngx_conf_set_bufs_slot,
219 NGX_HTTP_SRV_CONF_OFFSET,
220 offsetof(ngx_http_core_srv_conf_t, large_client_header_buffers),
223 { ngx_string("optimize_server_names"),
224 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
225 ngx_conf_set_flag_slot,
226 NGX_HTTP_LOC_CONF_OFFSET,
227 offsetof(ngx_http_core_loc_conf_t, server_name_in_redirect),
228 &ngx_conf_deprecated_optimize_server_names },
230 { ngx_string("ignore_invalid_headers"),
231 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
232 ngx_conf_set_flag_slot,
233 NGX_HTTP_SRV_CONF_OFFSET,
234 offsetof(ngx_http_core_srv_conf_t, ignore_invalid_headers),
237 { ngx_string("merge_slashes"),
238 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
239 ngx_conf_set_flag_slot,
240 NGX_HTTP_SRV_CONF_OFFSET,
241 offsetof(ngx_http_core_srv_conf_t, merge_slashes),
244 { ngx_string("underscores_in_headers"),
245 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
246 ngx_conf_set_flag_slot,
247 NGX_HTTP_SRV_CONF_OFFSET,
248 offsetof(ngx_http_core_srv_conf_t, underscores_in_headers),
251 { ngx_string("location"),
252 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12,
253 ngx_http_core_location,
254 NGX_HTTP_SRV_CONF_OFFSET,
258 { ngx_string("listen"),
259 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
260 ngx_http_core_listen,
261 NGX_HTTP_SRV_CONF_OFFSET,
265 { ngx_string("server_name"),
266 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
267 ngx_http_core_server_name,
268 NGX_HTTP_SRV_CONF_OFFSET,
272 { ngx_string("types_hash_max_size"),
273 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
274 ngx_conf_set_num_slot,
275 NGX_HTTP_LOC_CONF_OFFSET,
276 offsetof(ngx_http_core_loc_conf_t, types_hash_max_size),
279 { ngx_string("types_hash_bucket_size"),
280 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
281 ngx_conf_set_num_slot,
282 NGX_HTTP_LOC_CONF_OFFSET,
283 offsetof(ngx_http_core_loc_conf_t, types_hash_bucket_size),
286 { ngx_string("types"),
287 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF
288 |NGX_CONF_BLOCK|NGX_CONF_NOARGS,
290 NGX_HTTP_LOC_CONF_OFFSET,
294 { ngx_string("default_type"),
295 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
296 ngx_conf_set_str_slot,
297 NGX_HTTP_LOC_CONF_OFFSET,
298 offsetof(ngx_http_core_loc_conf_t, default_type),
301 { ngx_string("root"),
302 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
305 NGX_HTTP_LOC_CONF_OFFSET,
309 { ngx_string("alias"),
310 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
312 NGX_HTTP_LOC_CONF_OFFSET,
316 { ngx_string("limit_except"),
317 NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_1MORE,
318 ngx_http_core_limit_except,
319 NGX_HTTP_LOC_CONF_OFFSET,
323 { ngx_string("client_max_body_size"),
324 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
325 ngx_conf_set_off_slot,
326 NGX_HTTP_LOC_CONF_OFFSET,
327 offsetof(ngx_http_core_loc_conf_t, client_max_body_size),
330 { ngx_string("client_body_buffer_size"),
331 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
332 ngx_conf_set_size_slot,
333 NGX_HTTP_LOC_CONF_OFFSET,
334 offsetof(ngx_http_core_loc_conf_t, client_body_buffer_size),
337 { ngx_string("client_body_timeout"),
338 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
339 ngx_conf_set_msec_slot,
340 NGX_HTTP_LOC_CONF_OFFSET,
341 offsetof(ngx_http_core_loc_conf_t, client_body_timeout),
344 { ngx_string("client_body_temp_path"),
345 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
346 ngx_conf_set_path_slot,
347 NGX_HTTP_LOC_CONF_OFFSET,
348 offsetof(ngx_http_core_loc_conf_t, client_body_temp_path),
349 (void *) ngx_garbage_collector_temp_handler },
351 { ngx_string("client_body_in_file_only"),
352 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
353 ngx_conf_set_enum_slot,
354 NGX_HTTP_LOC_CONF_OFFSET,
355 offsetof(ngx_http_core_loc_conf_t, client_body_in_file_only),
356 &ngx_http_core_request_body_in_file },
358 { ngx_string("sendfile"),
359 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
361 ngx_conf_set_flag_slot,
362 NGX_HTTP_LOC_CONF_OFFSET,
363 offsetof(ngx_http_core_loc_conf_t, sendfile),
366 { ngx_string("sendfile_max_chunk"),
367 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
368 ngx_conf_set_size_slot,
369 NGX_HTTP_LOC_CONF_OFFSET,
370 offsetof(ngx_http_core_loc_conf_t, sendfile_max_chunk),
373 { ngx_string("directio"),
374 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
375 ngx_http_core_directio,
376 NGX_HTTP_LOC_CONF_OFFSET,
380 { ngx_string("tcp_nopush"),
381 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
382 ngx_conf_set_flag_slot,
383 NGX_HTTP_LOC_CONF_OFFSET,
384 offsetof(ngx_http_core_loc_conf_t, tcp_nopush),
387 { ngx_string("tcp_nodelay"),
388 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
389 ngx_conf_set_flag_slot,
390 NGX_HTTP_LOC_CONF_OFFSET,
391 offsetof(ngx_http_core_loc_conf_t, tcp_nodelay),
394 { ngx_string("send_timeout"),
395 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
396 ngx_conf_set_msec_slot,
397 NGX_HTTP_LOC_CONF_OFFSET,
398 offsetof(ngx_http_core_loc_conf_t, send_timeout),
401 { ngx_string("send_lowat"),
402 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
403 ngx_conf_set_size_slot,
404 NGX_HTTP_LOC_CONF_OFFSET,
405 offsetof(ngx_http_core_loc_conf_t, send_lowat),
406 &ngx_http_core_lowat_post },
408 { ngx_string("postpone_output"),
409 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
410 ngx_conf_set_size_slot,
411 NGX_HTTP_LOC_CONF_OFFSET,
412 offsetof(ngx_http_core_loc_conf_t, postpone_output),
415 { ngx_string("limit_rate"),
416 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
418 ngx_conf_set_size_slot,
419 NGX_HTTP_LOC_CONF_OFFSET,
420 offsetof(ngx_http_core_loc_conf_t, limit_rate),
423 { ngx_string("keepalive_timeout"),
424 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
425 ngx_http_core_keepalive,
426 NGX_HTTP_LOC_CONF_OFFSET,
430 { ngx_string("satisfy"),
431 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
432 ngx_conf_set_enum_slot,
433 NGX_HTTP_LOC_CONF_OFFSET,
434 offsetof(ngx_http_core_loc_conf_t, satisfy),
435 &ngx_http_core_satisfy },
437 { ngx_string("satisfy_any"),
438 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
439 ngx_conf_set_flag_slot,
440 NGX_HTTP_LOC_CONF_OFFSET,
441 offsetof(ngx_http_core_loc_conf_t, satisfy),
442 &ngx_conf_deprecated_satisfy_any },
444 { ngx_string("internal"),
445 NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
446 ngx_http_core_internal,
447 NGX_HTTP_LOC_CONF_OFFSET,
451 { ngx_string("lingering_time"),
452 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
453 ngx_conf_set_msec_slot,
454 NGX_HTTP_LOC_CONF_OFFSET,
455 offsetof(ngx_http_core_loc_conf_t, lingering_time),
458 { ngx_string("lingering_timeout"),
459 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
460 ngx_conf_set_msec_slot,
461 NGX_HTTP_LOC_CONF_OFFSET,
462 offsetof(ngx_http_core_loc_conf_t, lingering_timeout),
465 { ngx_string("reset_timedout_connection"),
466 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
467 ngx_conf_set_flag_slot,
468 NGX_HTTP_LOC_CONF_OFFSET,
469 offsetof(ngx_http_core_loc_conf_t, reset_timedout_connection),
472 { ngx_string("server_name_in_redirect"),
473 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
474 ngx_conf_set_flag_slot,
475 NGX_HTTP_LOC_CONF_OFFSET,
476 offsetof(ngx_http_core_loc_conf_t, server_name_in_redirect),
479 { ngx_string("port_in_redirect"),
480 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
481 ngx_conf_set_flag_slot,
482 NGX_HTTP_LOC_CONF_OFFSET,
483 offsetof(ngx_http_core_loc_conf_t, port_in_redirect),
486 { ngx_string("msie_padding"),
487 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
488 ngx_conf_set_flag_slot,
489 NGX_HTTP_LOC_CONF_OFFSET,
490 offsetof(ngx_http_core_loc_conf_t, msie_padding),
493 { ngx_string("msie_refresh"),
494 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
495 ngx_conf_set_flag_slot,
496 NGX_HTTP_LOC_CONF_OFFSET,
497 offsetof(ngx_http_core_loc_conf_t, msie_refresh),
500 { ngx_string("log_not_found"),
501 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
502 ngx_conf_set_flag_slot,
503 NGX_HTTP_LOC_CONF_OFFSET,
504 offsetof(ngx_http_core_loc_conf_t, log_not_found),
507 { ngx_string("log_subrequest"),
508 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
509 ngx_conf_set_flag_slot,
510 NGX_HTTP_LOC_CONF_OFFSET,
511 offsetof(ngx_http_core_loc_conf_t, log_subrequest),
514 { ngx_string("recursive_error_pages"),
515 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
516 ngx_conf_set_flag_slot,
517 NGX_HTTP_LOC_CONF_OFFSET,
518 offsetof(ngx_http_core_loc_conf_t, recursive_error_pages),
521 { ngx_string("server_tokens"),
522 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
523 ngx_conf_set_flag_slot,
524 NGX_HTTP_LOC_CONF_OFFSET,
525 offsetof(ngx_http_core_loc_conf_t, server_tokens),
528 { ngx_string("if_modified_since"),
529 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
530 ngx_conf_set_enum_slot,
531 NGX_HTTP_LOC_CONF_OFFSET,
532 offsetof(ngx_http_core_loc_conf_t, if_modified_since),
533 &ngx_http_core_if_modified_since },
535 { ngx_string("error_page"),
536 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
538 ngx_http_core_error_page,
539 NGX_HTTP_LOC_CONF_OFFSET,
543 { ngx_string("try_files"),
544 NGX_HTTP_LOC_CONF|NGX_CONF_2MORE,
545 ngx_http_core_try_files,
546 NGX_HTTP_LOC_CONF_OFFSET,
550 { ngx_string("post_action"),
551 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
553 ngx_conf_set_str_slot,
554 NGX_HTTP_LOC_CONF_OFFSET,
555 offsetof(ngx_http_core_loc_conf_t, post_action),
558 { ngx_string("error_log"),
559 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
560 ngx_http_core_error_log,
561 NGX_HTTP_LOC_CONF_OFFSET,
565 { ngx_string("open_file_cache"),
566 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
567 ngx_http_core_open_file_cache,
568 NGX_HTTP_LOC_CONF_OFFSET,
569 offsetof(ngx_http_core_loc_conf_t, open_file_cache),
572 { ngx_string("open_file_cache_valid"),
573 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
574 ngx_conf_set_sec_slot,
575 NGX_HTTP_LOC_CONF_OFFSET,
576 offsetof(ngx_http_core_loc_conf_t, open_file_cache_valid),
579 { ngx_string("open_file_cache_retest"),
580 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
581 ngx_conf_set_sec_slot,
582 NGX_HTTP_LOC_CONF_OFFSET,
583 offsetof(ngx_http_core_loc_conf_t, open_file_cache_valid),
584 &ngx_conf_deprecated_open_file_cache_retest },
586 { ngx_string("open_file_cache_min_uses"),
587 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
588 ngx_conf_set_num_slot,
589 NGX_HTTP_LOC_CONF_OFFSET,
590 offsetof(ngx_http_core_loc_conf_t, open_file_cache_min_uses),
593 { ngx_string("open_file_cache_errors"),
594 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
595 ngx_conf_set_flag_slot,
596 NGX_HTTP_LOC_CONF_OFFSET,
597 offsetof(ngx_http_core_loc_conf_t, open_file_cache_errors),
600 { ngx_string("open_file_cache_events"),
601 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
602 ngx_conf_set_flag_slot,
603 NGX_HTTP_LOC_CONF_OFFSET,
604 offsetof(ngx_http_core_loc_conf_t, open_file_cache_events),
607 { ngx_string("resolver"),
608 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
609 ngx_http_core_resolver,
610 NGX_HTTP_LOC_CONF_OFFSET,
614 { ngx_string("resolver_timeout"),
615 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
616 ngx_conf_set_msec_slot,
617 NGX_HTTP_LOC_CONF_OFFSET,
618 offsetof(ngx_http_core_loc_conf_t, resolver_timeout),
623 { ngx_string("gzip_vary"),
624 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
625 ngx_conf_set_flag_slot,
626 NGX_HTTP_LOC_CONF_OFFSET,
627 offsetof(ngx_http_core_loc_conf_t, gzip_vary),
630 { ngx_string("gzip_http_version"),
631 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
632 ngx_conf_set_enum_slot,
633 NGX_HTTP_LOC_CONF_OFFSET,
634 offsetof(ngx_http_core_loc_conf_t, gzip_http_version),
635 &ngx_http_gzip_http_version },
637 { ngx_string("gzip_proxied"),
638 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
639 ngx_conf_set_bitmask_slot,
640 NGX_HTTP_LOC_CONF_OFFSET,
641 offsetof(ngx_http_core_loc_conf_t, gzip_proxied),
642 &ngx_http_gzip_proxied_mask },
644 { ngx_string("gzip_disable"),
645 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
646 ngx_http_gzip_disable,
647 NGX_HTTP_LOC_CONF_OFFSET,
657 static ngx_http_module_t ngx_http_core_module_ctx = {
658 ngx_http_core_preconfiguration, /* preconfiguration */
659 NULL, /* postconfiguration */
661 ngx_http_core_create_main_conf, /* create main configuration */
662 ngx_http_core_init_main_conf, /* init main configuration */
664 ngx_http_core_create_srv_conf, /* create server configuration */
665 ngx_http_core_merge_srv_conf, /* merge server configuration */
667 ngx_http_core_create_loc_conf, /* create location configuration */
668 ngx_http_core_merge_loc_conf /* merge location configuration */
672 ngx_module_t ngx_http_core_module = {
674 &ngx_http_core_module_ctx, /* module context */
675 ngx_http_core_commands, /* module directives */
676 NGX_HTTP_MODULE, /* module type */
677 NULL, /* init master */
678 NULL, /* init module */
679 NULL, /* init process */
680 NULL, /* init thread */
681 NULL, /* exit thread */
682 NULL, /* exit process */
683 NULL, /* exit master */
684 NGX_MODULE_V1_PADDING
688 static ngx_str_t ngx_http_core_get_method = { 3, (u_char *) "GET " };
692 ngx_http_handler(ngx_http_request_t *r)
694 ngx_http_core_main_conf_t *cmcf;
696 r->connection->log->action = NULL;
698 r->connection->unexpected_eof = 0;
701 switch (r->headers_in.connection_type) {
703 if (r->http_version > NGX_HTTP_VERSION_10) {
710 case NGX_HTTP_CONNECTION_CLOSE:
714 case NGX_HTTP_CONNECTION_KEEP_ALIVE:
719 if (r->keepalive && r->headers_in.msie && r->method == NGX_HTTP_POST) {
722 * MSIE may wait for some time if an response for
723 * a POST request was sent over a keepalive connection
729 if (r->headers_in.content_length_n > 0) {
730 r->lingering_close = 1;
733 r->lingering_close = 0;
736 r->phase_handler = 0;
739 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
740 r->phase_handler = cmcf->phase_engine.server_rewrite_index;
743 if (r->unparsed_uri.len) {
744 r->valid_unparsed_uri = 1;
747 r->valid_location = 1;
750 r->write_event_handler = ngx_http_core_run_phases;
751 ngx_http_core_run_phases(r);
756 ngx_http_core_run_phases(ngx_http_request_t *r)
759 ngx_http_phase_handler_t *ph;
760 ngx_http_core_main_conf_t *cmcf;
762 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
764 ph = cmcf->phase_engine.handlers;
766 while (ph[r->phase_handler].checker) {
768 rc = ph[r->phase_handler].checker(r, &ph[r->phase_handler]);
778 ngx_http_core_generic_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
783 * generic phase checker,
784 * used by the post read, server rewrite, rewrite, and pre-access phases
787 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
788 "generic phase: %ui", r->phase_handler);
793 r->phase_handler = ph->next;
797 if (rc == NGX_DECLINED) {
802 if (rc == NGX_AGAIN || rc == NGX_DONE) {
806 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
808 ngx_http_finalize_request(r, rc);
815 ngx_http_core_find_config_phase(ngx_http_request_t *r,
816 ngx_http_phase_handler_t *ph)
821 ngx_http_core_loc_conf_t *clcf;
823 r->content_handler = NULL;
826 rc = ngx_http_core_find_location(r);
828 if (rc == NGX_ERROR) {
829 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
833 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
835 if (!r->internal && clcf->internal) {
836 ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
840 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
841 "using configuration \"%s%V\"",
842 (clcf->noname ? "*" : (clcf->exact_match ? "=" : "")),
845 ngx_http_update_location_config(r);
847 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
849 r->headers_in.content_length_n, clcf->client_max_body_size);
851 if (r->headers_in.content_length_n != -1
853 && clcf->client_max_body_size
854 && clcf->client_max_body_size < r->headers_in.content_length_n)
856 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
857 "client intended to send too large body: %O bytes",
858 r->headers_in.content_length_n);
860 ngx_http_finalize_request(r, NGX_HTTP_REQUEST_ENTITY_TOO_LARGE);
864 if (rc == NGX_DONE) {
865 r->headers_out.location = ngx_list_push(&r->headers_out.headers);
866 if (r->headers_out.location == NULL) {
867 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
872 * we do not need to set the r->headers_out.location->hash and
873 * r->headers_out.location->key fields
876 if (r->args.len == 0) {
877 r->headers_out.location->value = clcf->name;
880 len = clcf->name.len + 1 + r->args.len;
881 p = ngx_pnalloc(r->pool, len);
884 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
888 r->headers_out.location->value.len = len;
889 r->headers_out.location->value.data = p;
891 p = ngx_cpymem(p, clcf->name.data, clcf->name.len);
893 ngx_memcpy(p, r->args.data, r->args.len);
896 ngx_http_finalize_request(r, NGX_HTTP_MOVED_PERMANENTLY);
906 ngx_http_core_post_rewrite_phase(ngx_http_request_t *r,
907 ngx_http_phase_handler_t *ph)
909 ngx_http_core_srv_conf_t *cscf;
911 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
912 "post rewrite phase: %ui", r->phase_handler);
914 if (!r->uri_changed) {
919 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
920 "uri changes: %d", r->uri_changes);
923 * gcc before 3.3 compiles the broken code for
924 * if (r->uri_changes-- == 0)
925 * if the r->uri_changes is defined as
926 * unsigned uri_changes:4
931 if (r->uri_changes == 0) {
932 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
933 "rewrite or internal redirection cycle "
934 "while processing \"%V\"", &r->uri);
936 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
940 r->phase_handler = ph->next;
942 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
943 r->loc_conf = cscf->ctx->loc_conf;
950 ngx_http_core_access_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
953 ngx_http_core_loc_conf_t *clcf;
956 r->phase_handler = ph->next;
960 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
961 "access phase: %ui", r->phase_handler);
965 if (rc == NGX_DECLINED) {
970 if (rc == NGX_AGAIN || rc == NGX_DONE) {
974 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
976 if (clcf->satisfy == NGX_HTTP_SATISFY_ALL) {
987 if (r->headers_out.www_authenticate) {
988 r->headers_out.www_authenticate->hash = 0;
991 r->phase_handler = ph->next;
995 if (rc == NGX_HTTP_FORBIDDEN || rc == NGX_HTTP_UNAUTHORIZED) {
1003 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
1005 ngx_http_finalize_request(r, rc);
1011 ngx_http_core_post_access_phase(ngx_http_request_t *r,
1012 ngx_http_phase_handler_t *ph)
1014 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1015 "post access phase: %ui", r->phase_handler);
1017 if (r->access_code) {
1019 if (r->access_code == NGX_HTTP_FORBIDDEN) {
1020 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1021 "access forbidden by rule");
1024 ngx_http_finalize_request(r, r->access_code);
1034 ngx_http_core_try_files_phase(ngx_http_request_t *r,
1035 ngx_http_phase_handler_t *ph)
1037 size_t len, root, alias, reserve, allocated;
1040 ngx_uint_t test_dir;
1041 ngx_http_try_file_t *tf;
1042 ngx_open_file_info_t of;
1043 ngx_http_script_code_pt code;
1044 ngx_http_script_engine_t e;
1045 ngx_http_core_loc_conf_t *clcf;
1046 ngx_http_script_len_code_pt lcode;
1048 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1049 "try files phase: %ui", r->phase_handler);
1051 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1053 if (clcf->try_files == NULL) {
1061 /* suppress MSVC warning */
1064 tf = clcf->try_files;
1066 alias = clcf->alias ? clcf->name.len : 0;
1071 ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
1073 e.ip = tf->lengths->elts;
1076 /* 1 is for terminating '\0' as in static names */
1079 while (*(uintptr_t *) e.ip) {
1080 lcode = *(ngx_http_script_len_code_pt *) e.ip;
1088 reserve = len - r->uri.len;
1090 /* 16 bytes are preallocation */
1091 reserve = reserve < 16 ? 16 : reserve + 16;
1095 if (reserve > allocated) {
1097 /* we just need to allocate path and to copy a root */
1099 if (ngx_http_map_uri_to_path(r, &path, &root, reserve) == NULL) {
1100 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1104 name = path.data + root;
1105 allocated = path.len - root - (r->uri.len - alias);
1108 if (tf->values == NULL) {
1110 /* tf->name.len includes the terminating '\0' */
1112 ngx_memcpy(name, tf->name.data, tf->name.len);
1114 path.len = (name + tf->name.len - 1) - path.data;
1117 e.ip = tf->values->elts;
1121 while (*(uintptr_t *) e.ip) {
1122 code = *(ngx_http_script_code_pt *) e.ip;
1123 code((ngx_http_script_engine_t *) &e);
1126 path.len = e.pos - path.data;
1130 if (alias && ngx_strncmp(name, clcf->name.data, alias) == 0) {
1131 ngx_memcpy(name, name + alias, len - alias);
1136 test_dir = tf->test_dir;
1140 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1141 "try to use file: \"%s\"", name);
1143 if (tf->lengths == NULL && tf->name.len == 0) {
1148 if (path.data[0] == '@') {
1149 (void) ngx_http_named_location(r, &path);
1152 (void) ngx_http_internal_redirect(r, &path, NULL);
1158 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
1160 of.directio = clcf->directio;
1161 of.valid = clcf->open_file_cache_valid;
1162 of.min_uses = clcf->open_file_cache_min_uses;
1163 of.errors = clcf->open_file_cache_errors;
1164 of.events = clcf->open_file_cache_events;
1166 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
1169 if (of.err != NGX_ENOENT && of.err != NGX_ENOTDIR) {
1170 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
1171 ngx_open_file_n " \"%s\" failed", path.data);
1177 if (of.is_dir && !test_dir) {
1188 r->uri.len = alias + path.len;
1189 r->uri.data = ngx_pnalloc(r->pool, r->uri.len);
1190 if (r->uri.data == NULL) {
1191 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1195 p = ngx_copy(r->uri.data, clcf->name.data, alias);
1196 ngx_memcpy(p, name, path.len);
1199 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1200 "try file uri: \"%V\"", &r->uri);
1211 ngx_http_core_content_phase(ngx_http_request_t *r,
1212 ngx_http_phase_handler_t *ph)
1218 if (r->content_handler) {
1219 r->write_event_handler = ngx_http_request_empty_handler;
1220 ngx_http_finalize_request(r, r->content_handler(r));
1224 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1225 "content phase: %ui", r->phase_handler);
1227 rc = ph->handler(r);
1229 if (rc == NGX_DONE) {
1233 if (rc != NGX_DECLINED) {
1234 ngx_http_finalize_request(r, rc);
1238 /* rc == NGX_DECLINED */
1247 /* no content handler was found */
1249 if (r->uri.data[r->uri.len - 1] == '/' && !r->zero_in_uri) {
1251 if (ngx_http_map_uri_to_path(r, &path, &root, 0) != NULL) {
1252 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1253 "directory index of \"%s\" is forbidden", path.data);
1256 ngx_http_finalize_request(r, NGX_HTTP_FORBIDDEN);
1260 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no handler found");
1262 ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
1268 ngx_http_update_location_config(ngx_http_request_t *r)
1270 ngx_http_core_loc_conf_t *clcf;
1272 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1274 if (r->method & clcf->limit_except) {
1275 r->loc_conf = clcf->limit_except_loc_conf;
1276 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1280 r->connection->log->file = clcf->err_log->file;
1282 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
1283 r->connection->log->log_level = clcf->err_log->log_level;
1287 if ((ngx_io.flags & NGX_IO_SENDFILE) && clcf->sendfile) {
1288 r->connection->sendfile = 1;
1291 r->connection->sendfile = 0;
1294 if (clcf->client_body_in_file_only) {
1295 r->request_body_in_file_only = 1;
1296 r->request_body_in_persistent_file = 1;
1297 r->request_body_in_clean_file =
1298 clcf->client_body_in_file_only == NGX_HTTP_REQUEST_BODY_FILE_CLEAN;
1299 r->request_body_file_log_level = NGX_LOG_NOTICE;
1302 r->request_body_file_log_level = NGX_LOG_WARN;
1305 if (r->keepalive && clcf->keepalive_timeout == 0) {
1309 if (!clcf->tcp_nopush) {
1310 /* disable TCP_NOPUSH/TCP_CORK use */
1311 r->connection->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;
1314 if (r->limit_rate == 0) {
1315 r->limit_rate = clcf->limit_rate;
1318 if (clcf->handler) {
1319 r->content_handler = clcf->handler;
1325 * NGX_OK - exact or regex match
1326 * NGX_DONE - auto redirect
1327 * NGX_AGAIN - inclusive match
1328 * NGX_ERROR - regex error
1329 * NGX_DECLINED - no match
1333 ngx_http_core_find_location(ngx_http_request_t *r)
1336 ngx_http_core_loc_conf_t *pclcf;
1340 ngx_http_core_loc_conf_t *clcf, **clcfp;
1345 pclcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1347 rc = ngx_http_core_find_static_location(r, pclcf->static_locations);
1349 if (rc == NGX_AGAIN) {
1352 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1354 noregex = clcf->noregex;
1357 /* look up nested locations */
1359 rc = ngx_http_core_find_location(r);
1362 if (rc == NGX_OK || rc == NGX_DONE) {
1366 /* rc == NGX_DECLINED or rc == NGX_AGAIN in nested location */
1370 if (noregex == 0 && pclcf->regex_locations) {
1372 for (clcfp = pclcf->regex_locations; *clcfp; clcfp++) {
1374 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1375 "test location: ~ \"%V\"", &(*clcfp)->name);
1377 n = ngx_regex_exec((*clcfp)->regex, &r->uri, NULL, 0);
1379 if (n == NGX_REGEX_NO_MATCHED) {
1384 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
1386 " failed: %d on \"%V\" using \"%V\"",
1387 n, &r->uri, &(*clcfp)->name);
1393 r->loc_conf = (*clcfp)->loc_conf;
1395 /* look up nested locations */
1397 rc = ngx_http_core_find_location(r);
1399 return (rc == NGX_ERROR) ? rc : NGX_OK;
1409 * NGX_OK - exact match
1410 * NGX_DONE - auto redirect
1411 * NGX_AGAIN - inclusive match
1412 * NGX_DECLINED - no match
1416 ngx_http_core_find_static_location(ngx_http_request_t *r,
1417 ngx_http_location_tree_node_t *node)
1434 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1435 "test location: \"%*s\"", node->len, node->name);
1437 n = (len <= (size_t) node->len) ? len : node->len;
1439 rc = ngx_filename_cmp(uri, node->name, n);
1442 node = (rc < 0) ? node->left : node->right;
1447 if (len > (size_t) node->len) {
1449 if (node->inclusive) {
1451 r->loc_conf = node->inclusive->loc_conf;
1468 if (len == (size_t) node->len) {
1470 r->loc_conf = (node->exact) ? node->exact->loc_conf:
1471 node->inclusive->loc_conf;
1475 /* len < node->len */
1477 if (len + 1 == (size_t) node->len && node->auto_redirect) {
1479 r->loc_conf = (node->exact) ? node->exact->loc_conf:
1480 node->inclusive->loc_conf;
1490 ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash)
1495 if (r->headers_out.content_type.len == 0) {
1499 if (r->headers_out.content_type_lowcase == NULL) {
1501 p = ngx_pnalloc(r->pool, r->headers_out.content_type_len);
1507 r->headers_out.content_type_lowcase = p;
1511 for (i = 0; i < r->headers_out.content_type_len; i++) {
1512 c = ngx_tolower(r->headers_out.content_type.data[i]);
1513 hash = ngx_hash(hash, c);
1517 r->headers_out.content_type_hash = hash;
1520 return ngx_hash_find(types_hash,
1521 r->headers_out.content_type_hash,
1522 r->headers_out.content_type_lowcase,
1523 r->headers_out.content_type_len);
1528 ngx_http_set_content_type(ngx_http_request_t *r)
1533 ngx_http_core_loc_conf_t *clcf;
1535 if (r->headers_out.content_type.len) {
1539 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1545 for (i = 0; i < r->exten.len; i++) {
1546 c = r->exten.data[i];
1548 if (c >= 'A' && c <= 'Z') {
1550 exten = ngx_pnalloc(r->pool, r->exten.len);
1551 if (exten == NULL) {
1552 return NGX_HTTP_INTERNAL_SERVER_ERROR;
1555 hash = ngx_hash_strlow(exten, r->exten.data, r->exten.len);
1557 r->exten.data = exten;
1562 hash = ngx_hash(hash, c);
1565 type = ngx_hash_find(&clcf->types_hash, hash,
1566 r->exten.data, r->exten.len);
1569 r->headers_out.content_type_len = type->len;
1570 r->headers_out.content_type = *type;
1576 r->headers_out.content_type_len = clcf->default_type.len;
1577 r->headers_out.content_type = clcf->default_type;
1584 ngx_http_set_exten(ngx_http_request_t *r)
1589 r->exten.data = NULL;
1591 for (i = r->uri.len - 1; i > 1; i--) {
1592 if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {
1594 r->exten.len = r->uri.len - i - 1;
1595 r->exten.data = &r->uri.data[i + 1];
1599 } else if (r->uri.data[i] == '/') {
1609 ngx_http_send_header(ngx_http_request_t *r)
1611 if (r->err_status) {
1612 r->headers_out.status = r->err_status;
1613 r->headers_out.status_line.len = 0;
1616 return ngx_http_top_header_filter(r);
1621 ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
1625 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1626 "http output filter \"%V?%V\"", &r->uri, &r->args);
1628 rc = ngx_http_top_body_filter(r, in);
1630 if (rc == NGX_ERROR) {
1631 /* NGX_ERROR may be returned by any filter */
1632 r->connection->error = 1;
1640 ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,
1641 size_t *root_length, size_t reserved)
1645 ngx_http_core_loc_conf_t *clcf;
1647 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1649 alias = clcf->alias ? clcf->name.len : 0;
1651 if (alias && !r->valid_location) {
1652 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
1653 "\"alias\" could not be used in location \"%V\" "
1654 "where URI was rewritten", &clcf->name);
1658 reserved += r->uri.len - alias + 1;
1660 if (clcf->root_lengths == NULL) {
1662 *root_length = clcf->root.len;
1664 path->len = clcf->root.len + reserved;
1666 path->data = ngx_pnalloc(r->pool, path->len);
1667 if (path->data == NULL) {
1671 last = ngx_copy(path->data, clcf->root.data, clcf->root.len);
1674 if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved,
1675 clcf->root_values->elts)
1681 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, path, 0)== NGX_ERROR)
1686 *root_length = path->len - reserved;
1687 last = path->data + *root_length;
1690 last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1);
1697 ngx_http_auth_basic_user(ngx_http_request_t *r)
1699 ngx_str_t auth, encoded;
1702 if (r->headers_in.user.len == 0 && r->headers_in.user.data != NULL) {
1703 return NGX_DECLINED;
1706 if (r->headers_in.authorization == NULL) {
1707 r->headers_in.user.data = (u_char *) "";
1708 return NGX_DECLINED;
1711 encoded = r->headers_in.authorization->value;
1713 if (encoded.len < sizeof("Basic ") - 1
1714 || ngx_strncasecmp(encoded.data, (u_char *) "Basic ",
1715 sizeof("Basic ") - 1)
1718 r->headers_in.user.data = (u_char *) "";
1719 return NGX_DECLINED;
1722 encoded.len -= sizeof("Basic ") - 1;
1723 encoded.data += sizeof("Basic ") - 1;
1725 while (encoded.len && encoded.data[0] == ' ') {
1730 if (encoded.len == 0) {
1731 r->headers_in.user.data = (u_char *) "";
1732 return NGX_DECLINED;
1735 auth.len = ngx_base64_decoded_length(encoded.len);
1736 auth.data = ngx_pnalloc(r->pool, auth.len + 1);
1737 if (auth.data == NULL) {
1741 if (ngx_decode_base64(&auth, &encoded) != NGX_OK) {
1742 r->headers_in.user.data = (u_char *) "";
1743 return NGX_DECLINED;
1746 auth.data[auth.len] = '\0';
1748 for (len = 0; len < auth.len; len++) {
1749 if (auth.data[len] == ':') {
1754 if (len == 0 || len == auth.len) {
1755 r->headers_in.user.data = (u_char *) "";
1756 return NGX_DECLINED;
1759 r->headers_in.user.len = len;
1760 r->headers_in.user.data = auth.data;
1761 r->headers_in.passwd.len = auth.len - len - 1;
1762 r->headers_in.passwd.data = &auth.data[len + 1];
1769 ngx_http_server_addr(ngx_http_request_t *r, ngx_str_t *s)
1772 ngx_connection_t *c;
1773 struct sockaddr_in sin;
1779 if (r->in_addr == 0) {
1780 len = sizeof(struct sockaddr_in);
1781 if (getsockname(c->fd, (struct sockaddr *) &sin, &len) == -1) {
1782 ngx_connection_error(c, ngx_socket_errno, "getsockname() failed");
1786 r->in_addr = sin.sin_addr.s_addr;
1789 sin.sin_family = c->sockaddr->sa_family;
1790 sin.sin_addr.s_addr = r->in_addr;
1797 s->len = ngx_sock_ntop((struct sockaddr *) &sin, s->data,
1798 NGX_INET_ADDRSTRLEN);
1807 ngx_http_gzip_ok(ngx_http_request_t *r)
1809 time_t date, expires;
1812 ngx_table_elt_t *e, *d;
1813 ngx_http_core_loc_conf_t *clcf;
1820 return NGX_DECLINED;
1826 || r->headers_in.accept_encoding == NULL
1827 || ngx_strcasestrn(r->headers_in.accept_encoding->value.data,
1832 * if the URL (without the "http://" prefix) is longer than 253 bytes,
1833 * then MSIE 4.x can not handle the compressed stream - it waits
1834 * too long, hangs up or crashes
1837 || (r->headers_in.msie4 && r->unparsed_uri.len > 200))
1839 return NGX_DECLINED;
1842 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1844 if (r->headers_in.msie6 && clcf->gzip_disable_msie6) {
1845 return NGX_DECLINED;
1848 if (r->http_version < clcf->gzip_http_version) {
1849 return NGX_DECLINED;
1852 if (r->headers_in.via == NULL) {
1856 p = clcf->gzip_proxied;
1858 if (p & NGX_HTTP_GZIP_PROXIED_OFF) {
1859 return NGX_DECLINED;
1862 if (p & NGX_HTTP_GZIP_PROXIED_ANY) {
1866 if (r->headers_in.authorization && (p & NGX_HTTP_GZIP_PROXIED_AUTH)) {
1870 e = r->headers_out.expires;
1874 if (!(p & NGX_HTTP_GZIP_PROXIED_EXPIRED)) {
1875 return NGX_DECLINED;
1878 expires = ngx_http_parse_time(e->value.data, e->value.len);
1879 if (expires == NGX_ERROR) {
1880 return NGX_DECLINED;
1883 d = r->headers_out.date;
1886 date = ngx_http_parse_time(d->value.data, d->value.len);
1887 if (date == NGX_ERROR) {
1888 return NGX_DECLINED;
1895 if (expires < date) {
1899 return NGX_DECLINED;
1902 cc = &r->headers_out.cache_control;
1906 if ((p & NGX_HTTP_GZIP_PROXIED_NO_CACHE)
1907 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_cache,
1914 if ((p & NGX_HTTP_GZIP_PROXIED_NO_STORE)
1915 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_store,
1922 if ((p & NGX_HTTP_GZIP_PROXIED_PRIVATE)
1923 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_private,
1930 return NGX_DECLINED;
1933 if ((p & NGX_HTTP_GZIP_PROXIED_NO_LM) && r->headers_out.last_modified) {
1934 return NGX_DECLINED;
1937 if ((p & NGX_HTTP_GZIP_PROXIED_NO_ETAG) && r->headers_out.etag) {
1938 return NGX_DECLINED;
1945 if (clcf->gzip_disable && r->headers_in.user_agent) {
1947 if (ngx_regex_exec_array(clcf->gzip_disable,
1948 &r->headers_in.user_agent->value,
1952 return NGX_DECLINED;
1967 ngx_http_subrequest(ngx_http_request_t *r,
1968 ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **psr,
1969 ngx_http_post_subrequest_t *ps, ngx_uint_t flags)
1971 ngx_connection_t *c;
1972 ngx_http_request_t *sr;
1973 ngx_http_core_srv_conf_t *cscf;
1974 ngx_http_postponed_request_t *pr, *p;
1976 r->main->subrequests--;
1978 if (r->main->subrequests == 0) {
1979 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1980 "subrequests cycle while processing \"%V\"", uri);
1981 r->main->subrequests = 1;
1985 sr = ngx_pcalloc(r->pool, sizeof(ngx_http_request_t));
1990 sr->signature = NGX_HTTP_MODULE;
1995 sr->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
1996 if (sr->ctx == NULL) {
2000 if (ngx_list_init(&sr->headers_out.headers, r->pool, 20,
2001 sizeof(ngx_table_elt_t))
2007 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
2008 sr->main_conf = cscf->ctx->main_conf;
2009 sr->srv_conf = cscf->ctx->srv_conf;
2010 sr->loc_conf = cscf->ctx->loc_conf;
2014 sr->headers_in = r->headers_in;
2016 ngx_http_clear_content_length(sr);
2017 ngx_http_clear_accept_ranges(sr);
2018 ngx_http_clear_last_modified(sr);
2020 sr->request_body = r->request_body;
2022 sr->method = NGX_HTTP_GET;
2023 sr->http_version = r->http_version;
2025 sr->request_line = r->request_line;
2032 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
2033 "http subrequest \"%V?%V\"", uri, &sr->args);
2035 sr->zero_in_uri = (flags & NGX_HTTP_ZERO_IN_URI) != 0;
2036 sr->subrequest_in_memory = (flags & NGX_HTTP_SUBREQUEST_IN_MEMORY) != 0;
2037 sr->waited = (flags & NGX_HTTP_SUBREQUEST_WAITED) != 0;
2039 sr->unparsed_uri = r->unparsed_uri;
2040 sr->method_name = ngx_http_core_get_method;
2041 sr->http_protocol = r->http_protocol;
2043 if (ngx_http_set_exten(sr) != NGX_OK) {
2049 sr->post_subrequest = ps;
2050 sr->read_event_handler = ngx_http_request_empty_handler;
2051 sr->write_event_handler = ngx_http_handler;
2053 if (c->data == r && r->postponed == NULL) {
2057 sr->in_addr = r->in_addr;
2059 sr->port_text = r->port_text;
2061 sr->variables = r->variables;
2063 sr->log_handler = r->log_handler;
2065 pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t));
2075 for (p = r->postponed; p->next; p = p->next) { /* void */ }
2084 sr->discard_body = r->discard_body;
2085 sr->expect_tested = 1;
2086 sr->main_filter_need_in_memory = r->main_filter_need_in_memory;
2088 sr->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1;
2090 r->main->subrequests++;
2094 return ngx_http_post_request(sr);
2099 ngx_http_internal_redirect(ngx_http_request_t *r,
2100 ngx_str_t *uri, ngx_str_t *args)
2102 ngx_http_core_srv_conf_t *cscf;
2106 if (r->uri_changes == 0) {
2107 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2108 "rewrite or internal redirection cycle "
2109 "while internal redirect to \"%V\"", uri);
2111 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
2122 r->args.data = NULL;
2125 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2126 "internal redirect: \"%V?%V\"", uri, &r->args);
2128 if (ngx_http_set_exten(r) != NGX_OK) {
2129 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
2133 /* clear the modules contexts */
2134 ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
2136 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
2137 r->loc_conf = cscf->ctx->loc_conf;
2139 ngx_http_update_location_config(r);
2143 ngx_http_handler(r);
2150 ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name)
2152 ngx_http_core_srv_conf_t *cscf;
2153 ngx_http_core_loc_conf_t **clcfp;
2154 ngx_http_core_main_conf_t *cmcf;
2156 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
2158 if (cscf->named_locations) {
2160 for (clcfp = cscf->named_locations; *clcfp; clcfp++) {
2162 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2163 "test location: \"%V\"", &(*clcfp)->name);
2165 if (name->len != (*clcfp)->name.len
2166 || ngx_strncmp(name->data, (*clcfp)->name.data, name->len) != 0)
2171 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2172 "using location: %V \"%V?%V\"",
2173 name, &r->uri, &r->args);
2176 r->content_handler = NULL;
2177 r->loc_conf = (*clcfp)->loc_conf;
2179 ngx_http_update_location_config(r);
2181 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
2183 r->phase_handler = cmcf->phase_engine.location_rewrite_index;
2185 ngx_http_core_run_phases(r);
2191 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2192 "could not find named location \"%V\"", name);
2194 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
2200 ngx_http_cleanup_t *
2201 ngx_http_cleanup_add(ngx_http_request_t *r, size_t size)
2203 ngx_http_cleanup_t *cln;
2207 cln = ngx_palloc(r->pool, sizeof(ngx_http_cleanup_t));
2213 cln->data = ngx_palloc(r->pool, size);
2214 if (cln->data == NULL) {
2222 cln->handler = NULL;
2223 cln->next = r->cleanup;
2227 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2228 "http cleanup add: %p", cln);
2235 ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
2241 ngx_http_module_t *module;
2242 ngx_http_conf_ctx_t *ctx, *http_ctx;
2243 ngx_http_core_srv_conf_t *cscf, **cscfp;
2244 ngx_http_core_main_conf_t *cmcf;
2246 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
2248 return NGX_CONF_ERROR;
2252 ctx->main_conf = http_ctx->main_conf;
2254 /* the server{}'s srv_conf */
2256 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2257 if (ctx->srv_conf == NULL) {
2258 return NGX_CONF_ERROR;
2261 /* the server{}'s loc_conf */
2263 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2264 if (ctx->loc_conf == NULL) {
2265 return NGX_CONF_ERROR;
2268 for (i = 0; ngx_modules[i]; i++) {
2269 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
2273 module = ngx_modules[i]->ctx;
2275 if (module->create_srv_conf) {
2276 mconf = module->create_srv_conf(cf);
2277 if (mconf == NULL) {
2278 return NGX_CONF_ERROR;
2281 ctx->srv_conf[ngx_modules[i]->ctx_index] = mconf;
2284 if (module->create_loc_conf) {
2285 mconf = module->create_loc_conf(cf);
2286 if (mconf == NULL) {
2287 return NGX_CONF_ERROR;
2290 ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
2295 /* the server configuration context */
2297 cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
2301 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
2303 cscfp = ngx_array_push(&cmcf->servers);
2304 if (cscfp == NULL) {
2305 return NGX_CONF_ERROR;
2311 /* parse inside server{} */
2315 cf->cmd_type = NGX_HTTP_SRV_CONF;
2317 rv = ngx_conf_parse(cf, NULL);
2326 ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
2331 ngx_str_t *value, *name;
2334 ngx_http_module_t *module;
2335 ngx_http_conf_ctx_t *ctx, *pctx;
2336 ngx_http_core_loc_conf_t *clcf, *pclcf;
2338 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
2340 return NGX_CONF_ERROR;
2344 ctx->main_conf = pctx->main_conf;
2345 ctx->srv_conf = pctx->srv_conf;
2347 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2348 if (ctx->loc_conf == NULL) {
2349 return NGX_CONF_ERROR;
2352 for (i = 0; ngx_modules[i]; i++) {
2353 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
2357 module = ngx_modules[i]->ctx;
2359 if (module->create_loc_conf) {
2360 ctx->loc_conf[ngx_modules[i]->ctx_index] =
2361 module->create_loc_conf(cf);
2362 if (ctx->loc_conf[ngx_modules[i]->ctx_index] == NULL) {
2363 return NGX_CONF_ERROR;
2368 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
2369 clcf->loc_conf = ctx->loc_conf;
2371 value = cf->args->elts;
2373 if (cf->args->nelts == 3) {
2376 mod = value[1].data;
2379 if (len == 1 && mod[0] == '=') {
2382 clcf->exact_match = 1;
2384 } else if (len == 2 && mod[0] == '^' && mod[1] == '~') {
2389 } else if (len == 1 && mod[0] == '~') {
2391 if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
2392 return NGX_CONF_ERROR;
2395 } else if (len == 2 && mod[0] == '~' && mod[1] == '*') {
2397 if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
2398 return NGX_CONF_ERROR;
2402 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2403 "invalid location modifier \"%V\"", &value[1]);
2404 return NGX_CONF_ERROR;
2411 if (name->data[0] == '=') {
2413 clcf->name.len = name->len - 1;
2414 clcf->name.data = name->data + 1;
2415 clcf->exact_match = 1;
2417 } else if (name->data[0] == '^' && name->data[1] == '~') {
2419 clcf->name.len = name->len - 2;
2420 clcf->name.data = name->data + 2;
2423 } else if (name->data[0] == '~') {
2428 if (name->data[0] == '*') {
2433 if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
2434 return NGX_CONF_ERROR;
2438 if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
2439 return NGX_CONF_ERROR;
2447 if (name->data[0] == '@') {
2453 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
2455 if (pclcf->name.len) {
2457 /* nested location */
2460 clcf->prev_location = pclcf;
2463 if (pclcf->exact_match) {
2464 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2465 "location \"%V\" could not be inside "
2466 "the exact location \"%V\"",
2467 &clcf->name, &pclcf->name);
2468 return NGX_CONF_ERROR;
2472 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2473 "location \"%V\" could not be inside "
2474 "the named location \"%V\"",
2475 &clcf->name, &pclcf->name);
2476 return NGX_CONF_ERROR;
2480 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2481 "named location \"%V\" must be "
2482 "on server level only",
2484 return NGX_CONF_ERROR;
2487 len = pclcf->name.len;
2490 if (clcf->regex == NULL
2491 && ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0)
2493 if (ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0)
2496 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2497 "location \"%V\" is outside location \"%V\"",
2498 &clcf->name, &pclcf->name);
2499 return NGX_CONF_ERROR;
2503 if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
2504 return NGX_CONF_ERROR;
2509 cf->cmd_type = NGX_HTTP_LOC_CONF;
2511 rv = ngx_conf_parse(cf, NULL);
2520 ngx_http_core_regex_location(ngx_conf_t *cf, ngx_http_core_loc_conf_t *clcf,
2521 ngx_str_t *regex, ngx_uint_t caseless)
2525 u_char errstr[NGX_MAX_CONF_ERRSTR];
2527 err.len = NGX_MAX_CONF_ERRSTR;
2530 clcf->regex = ngx_regex_compile(regex, caseless ? NGX_REGEX_CASELESS: 0,
2533 if (clcf->regex == NULL) {
2534 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
2538 clcf->name = *regex;
2544 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2545 "the using of the regex \"%V\" requires PCRE library",
2554 ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2556 ngx_http_core_loc_conf_t *lcf = conf;
2561 if (lcf->types == NULL) {
2562 lcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t));
2563 if (lcf->types == NULL) {
2564 return NGX_CONF_ERROR;
2569 cf->handler = ngx_http_core_type;
2570 cf->handler_conf = conf;
2572 rv = ngx_conf_parse(cf, NULL);
2581 ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
2583 ngx_http_core_loc_conf_t *lcf = conf;
2585 ngx_str_t *value, *content_type, *old, file;
2586 ngx_uint_t i, n, hash;
2587 ngx_hash_key_t *type;
2589 value = cf->args->elts;
2591 if (ngx_strcmp(value[0].data, "include") == 0) {
2594 if (ngx_conf_full_name(cf->cycle, &file, 1) == NGX_ERROR){
2595 return NGX_CONF_ERROR;
2598 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
2600 return ngx_conf_parse(cf, &file);
2603 content_type = ngx_palloc(cf->pool, sizeof(ngx_str_t));
2604 if (content_type == NULL) {
2605 return NGX_CONF_ERROR;
2608 *content_type = value[0];
2610 for (i = 1; i < cf->args->nelts; i++) {
2612 hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len);
2614 type = lcf->types->elts;
2615 for (n = 0; n < lcf->types->nelts; n++) {
2616 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) {
2617 old = type[n].value;
2618 type[n].value = content_type;
2620 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
2621 "duplicate extention \"%V\", "
2622 "content type: \"%V\", "
2623 "old content type: \"%V\"",
2624 &value[i], content_type, old);
2630 type = ngx_array_push(lcf->types);
2632 return NGX_CONF_ERROR;
2635 type->key = value[i];
2636 type->key_hash = hash;
2637 type->value = content_type;
2645 ngx_http_core_preconfiguration(ngx_conf_t *cf)
2647 return ngx_http_variables_add_core_vars(cf);
2652 ngx_http_core_create_main_conf(ngx_conf_t *cf)
2654 ngx_http_core_main_conf_t *cmcf;
2656 cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t));
2658 return NGX_CONF_ERROR;
2661 if (ngx_array_init(&cmcf->servers, cf->pool, 4,
2662 sizeof(ngx_http_core_srv_conf_t *))
2665 return NGX_CONF_ERROR;
2668 cmcf->server_names_hash_max_size = NGX_CONF_UNSET_UINT;
2669 cmcf->server_names_hash_bucket_size = NGX_CONF_UNSET_UINT;
2671 cmcf->variables_hash_max_size = NGX_CONF_UNSET_UINT;
2672 cmcf->variables_hash_bucket_size = NGX_CONF_UNSET_UINT;
2679 ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf)
2681 ngx_http_core_main_conf_t *cmcf = conf;
2683 if (cmcf->server_names_hash_max_size == NGX_CONF_UNSET_UINT) {
2684 cmcf->server_names_hash_max_size = 512;
2687 if (cmcf->server_names_hash_bucket_size == NGX_CONF_UNSET_UINT) {
2688 cmcf->server_names_hash_bucket_size = ngx_cacheline_size;
2691 cmcf->server_names_hash_bucket_size =
2692 ngx_align(cmcf->server_names_hash_bucket_size, ngx_cacheline_size);
2695 if (cmcf->variables_hash_max_size == NGX_CONF_UNSET_UINT) {
2696 cmcf->variables_hash_max_size = 512;
2699 if (cmcf->variables_hash_bucket_size == NGX_CONF_UNSET_UINT) {
2700 cmcf->variables_hash_bucket_size = 64;
2703 cmcf->variables_hash_bucket_size =
2704 ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size);
2711 ngx_http_core_create_srv_conf(ngx_conf_t *cf)
2713 ngx_http_core_srv_conf_t *cscf;
2715 cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t));
2717 return NGX_CONF_ERROR;
2721 * set by ngx_pcalloc():
2723 * conf->client_large_buffers.num = 0;
2726 if (ngx_array_init(&cscf->listen, cf->pool, 4, sizeof(ngx_http_listen_t))
2729 return NGX_CONF_ERROR;
2732 if (ngx_array_init(&cscf->server_names, cf->temp_pool, 4,
2733 sizeof(ngx_http_server_name_t))
2736 return NGX_CONF_ERROR;
2739 cscf->connection_pool_size = NGX_CONF_UNSET_SIZE;
2740 cscf->request_pool_size = NGX_CONF_UNSET_SIZE;
2741 cscf->client_header_timeout = NGX_CONF_UNSET_MSEC;
2742 cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE;
2743 cscf->ignore_invalid_headers = NGX_CONF_UNSET;
2744 cscf->merge_slashes = NGX_CONF_UNSET;
2745 cscf->underscores_in_headers = NGX_CONF_UNSET;
2752 ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
2754 ngx_http_core_srv_conf_t *prev = parent;
2755 ngx_http_core_srv_conf_t *conf = child;
2757 ngx_http_listen_t *ls;
2758 ngx_http_server_name_t *sn;
2760 /* TODO: it does not merge, it inits only */
2762 if (conf->listen.nelts == 0) {
2763 ls = ngx_array_push(&conf->listen);
2765 return NGX_CONF_ERROR;
2768 ngx_memzero(ls, sizeof(ngx_http_listen_t));
2770 ls->addr = INADDR_ANY;
2774 /* STUB: getuid() should be cached */
2775 ls->port = (getuid() == 0) ? 80 : 8000;
2777 ls->family = AF_INET;
2779 ls->conf.backlog = NGX_LISTEN_BACKLOG;
2780 ls->conf.rcvbuf = -1;
2781 ls->conf.sndbuf = -1;
2784 if (conf->server_name.data == NULL) {
2785 conf->server_name = cf->cycle->hostname;
2787 sn = ngx_array_push(&conf->server_names);
2789 return NGX_CONF_ERROR;
2795 sn->core_srv_conf = conf;
2796 sn->name.len = conf->server_name.len;
2797 sn->name.data = conf->server_name.data;
2800 ngx_conf_merge_size_value(conf->connection_pool_size,
2801 prev->connection_pool_size, 256);
2802 ngx_conf_merge_size_value(conf->request_pool_size,
2803 prev->request_pool_size, 4096);
2804 ngx_conf_merge_msec_value(conf->client_header_timeout,
2805 prev->client_header_timeout, 60000);
2806 ngx_conf_merge_size_value(conf->client_header_buffer_size,
2807 prev->client_header_buffer_size, 1024);
2808 ngx_conf_merge_bufs_value(conf->large_client_header_buffers,
2809 prev->large_client_header_buffers,
2812 if (conf->large_client_header_buffers.size < conf->connection_pool_size) {
2813 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2814 "the \"large_client_header_buffers\" size must be "
2815 "equal to or bigger than \"connection_pool_size\"");
2816 return NGX_CONF_ERROR;
2819 ngx_conf_merge_value(conf->ignore_invalid_headers,
2820 prev->ignore_invalid_headers, 1);
2822 ngx_conf_merge_value(conf->merge_slashes, prev->merge_slashes, 1);
2824 ngx_conf_merge_value(conf->underscores_in_headers,
2825 prev->underscores_in_headers, 0);
2832 ngx_http_core_create_loc_conf(ngx_conf_t *cf)
2834 ngx_http_core_loc_conf_t *lcf;
2836 lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t));
2838 return NGX_CONF_ERROR;
2842 * set by ngx_pcalloc():
2844 * lcf->root = { 0, NULL };
2845 * lcf->limit_except = 0;
2846 * lcf->post_action = { 0, NULL };
2847 * lcf->types = NULL;
2848 * lcf->default_type = { 0, NULL };
2849 * lcf->err_log = NULL;
2850 * lcf->error_pages = NULL;
2851 * lcf->try_files = NULL;
2852 * lcf->client_body_path = NULL;
2853 * lcf->regex = NULL;
2854 * lcf->exact_match = 0;
2855 * lcf->auto_redirect = 0;
2857 * lcf->gzip_proxied = 0;
2860 lcf->client_max_body_size = NGX_CONF_UNSET;
2861 lcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE;
2862 lcf->client_body_timeout = NGX_CONF_UNSET_MSEC;
2863 lcf->satisfy = NGX_CONF_UNSET_UINT;
2864 lcf->if_modified_since = NGX_CONF_UNSET_UINT;
2865 lcf->internal = NGX_CONF_UNSET;
2866 lcf->client_body_in_file_only = NGX_CONF_UNSET;
2867 lcf->sendfile = NGX_CONF_UNSET;
2868 lcf->sendfile_max_chunk = NGX_CONF_UNSET_SIZE;
2869 lcf->directio = NGX_CONF_UNSET;
2870 lcf->tcp_nopush = NGX_CONF_UNSET;
2871 lcf->tcp_nodelay = NGX_CONF_UNSET;
2872 lcf->send_timeout = NGX_CONF_UNSET_MSEC;
2873 lcf->send_lowat = NGX_CONF_UNSET_SIZE;
2874 lcf->postpone_output = NGX_CONF_UNSET_SIZE;
2875 lcf->limit_rate = NGX_CONF_UNSET_SIZE;
2876 lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
2877 lcf->keepalive_header = NGX_CONF_UNSET;
2878 lcf->lingering_time = NGX_CONF_UNSET_MSEC;
2879 lcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
2880 lcf->resolver_timeout = NGX_CONF_UNSET_MSEC;
2881 lcf->reset_timedout_connection = NGX_CONF_UNSET;
2882 lcf->server_name_in_redirect = NGX_CONF_UNSET;
2883 lcf->port_in_redirect = NGX_CONF_UNSET;
2884 lcf->msie_padding = NGX_CONF_UNSET;
2885 lcf->msie_refresh = NGX_CONF_UNSET;
2886 lcf->log_not_found = NGX_CONF_UNSET;
2887 lcf->log_subrequest = NGX_CONF_UNSET;
2888 lcf->recursive_error_pages = NGX_CONF_UNSET;
2889 lcf->server_tokens = NGX_CONF_UNSET;
2890 lcf->types_hash_max_size = NGX_CONF_UNSET_UINT;
2891 lcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT;
2893 lcf->open_file_cache = NGX_CONF_UNSET_PTR;
2894 lcf->open_file_cache_valid = NGX_CONF_UNSET;
2895 lcf->open_file_cache_min_uses = NGX_CONF_UNSET_UINT;
2896 lcf->open_file_cache_errors = NGX_CONF_UNSET;
2897 lcf->open_file_cache_events = NGX_CONF_UNSET;
2900 lcf->gzip_vary = NGX_CONF_UNSET;
2901 lcf->gzip_http_version = NGX_CONF_UNSET_UINT;
2903 lcf->gzip_disable = NGX_CONF_UNSET_PTR;
2904 lcf->gzip_disable_msie6 = 3;
2912 static ngx_str_t ngx_http_core_text_html_type = ngx_string("text/html");
2913 static ngx_str_t ngx_http_core_image_gif_type = ngx_string("image/gif");
2914 static ngx_str_t ngx_http_core_image_jpeg_type = ngx_string("image/jpeg");
2916 static ngx_hash_key_t ngx_http_core_default_types[] = {
2917 { ngx_string("html"), 0, &ngx_http_core_text_html_type },
2918 { ngx_string("gif"), 0, &ngx_http_core_image_gif_type },
2919 { ngx_string("jpg"), 0, &ngx_http_core_image_jpeg_type },
2920 { ngx_null_string, 0, NULL }
2925 ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
2927 ngx_http_core_loc_conf_t *prev = parent;
2928 ngx_http_core_loc_conf_t *conf = child;
2931 ngx_hash_key_t *type;
2932 ngx_hash_init_t types_hash;
2934 if (conf->root.data == NULL) {
2936 conf->alias = prev->alias;
2937 conf->root = prev->root;
2938 conf->root_lengths = prev->root_lengths;
2939 conf->root_values = prev->root_values;
2941 if (prev->root.data == NULL) {
2942 conf->root.len = sizeof("html") - 1;
2943 conf->root.data = (u_char *) "html";
2945 if (ngx_conf_full_name(cf->cycle, &conf->root, 0) == NGX_ERROR) {
2946 return NGX_CONF_ERROR;
2951 if (conf->post_action.data == NULL) {
2952 conf->post_action = prev->post_action;
2955 ngx_conf_merge_uint_value(conf->types_hash_max_size,
2956 prev->types_hash_max_size, 1024);
2958 ngx_conf_merge_uint_value(conf->types_hash_bucket_size,
2959 prev->types_hash_bucket_size,
2960 ngx_cacheline_size);
2962 conf->types_hash_bucket_size = ngx_align(conf->types_hash_bucket_size,
2963 ngx_cacheline_size);
2966 * the special handling the "types" directive in the "http" section
2967 * to inherit the http's conf->types_hash to all servers
2970 if (prev->types && prev->types_hash.buckets == NULL) {
2972 types_hash.hash = &prev->types_hash;
2973 types_hash.key = ngx_hash_key_lc;
2974 types_hash.max_size = conf->types_hash_max_size;
2975 types_hash.bucket_size = conf->types_hash_bucket_size;
2976 types_hash.name = "types_hash";
2977 types_hash.pool = cf->pool;
2978 types_hash.temp_pool = NULL;
2980 if (ngx_hash_init(&types_hash, prev->types->elts, prev->types->nelts)
2983 return NGX_CONF_ERROR;
2987 if (conf->types == NULL) {
2988 conf->types = prev->types;
2989 conf->types_hash = prev->types_hash;
2992 if (conf->types == NULL) {
2993 conf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_hash_key_t));
2994 if (conf->types == NULL) {
2995 return NGX_CONF_ERROR;
2998 for (i = 0; ngx_http_core_default_types[i].key.len; i++) {
2999 type = ngx_array_push(conf->types);
3001 return NGX_CONF_ERROR;
3004 type->key = ngx_http_core_default_types[i].key;
3006 ngx_hash_key_lc(ngx_http_core_default_types[i].key.data,
3007 ngx_http_core_default_types[i].key.len);
3008 type->value = ngx_http_core_default_types[i].value;
3012 if (conf->types_hash.buckets == NULL) {
3014 types_hash.hash = &conf->types_hash;
3015 types_hash.key = ngx_hash_key_lc;
3016 types_hash.max_size = conf->types_hash_max_size;
3017 types_hash.bucket_size = conf->types_hash_bucket_size;
3018 types_hash.name = "mime_types_hash";
3019 types_hash.pool = cf->pool;
3020 types_hash.temp_pool = NULL;
3022 if (ngx_hash_init(&types_hash, conf->types->elts, conf->types->nelts)
3025 return NGX_CONF_ERROR;
3029 if (conf->err_log == NULL) {
3030 if (prev->err_log) {
3031 conf->err_log = prev->err_log;
3033 conf->err_log = cf->cycle->new_log;
3037 if (conf->error_pages == NULL && prev->error_pages) {
3038 conf->error_pages = prev->error_pages;
3041 ngx_conf_merge_str_value(conf->default_type,
3042 prev->default_type, "text/plain");
3044 ngx_conf_merge_off_value(conf->client_max_body_size,
3045 prev->client_max_body_size, 1 * 1024 * 1024);
3046 ngx_conf_merge_size_value(conf->client_body_buffer_size,
3047 prev->client_body_buffer_size,
3048 (size_t) 2 * ngx_pagesize);
3049 ngx_conf_merge_msec_value(conf->client_body_timeout,
3050 prev->client_body_timeout, 60000);
3052 ngx_conf_merge_uint_value(conf->satisfy, prev->satisfy,
3053 NGX_HTTP_SATISFY_ALL);
3054 ngx_conf_merge_uint_value(conf->if_modified_since, prev->if_modified_since,
3056 ngx_conf_merge_value(conf->internal, prev->internal, 0);
3057 ngx_conf_merge_value(conf->client_body_in_file_only,
3058 prev->client_body_in_file_only, 0);
3059 ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
3060 ngx_conf_merge_size_value(conf->sendfile_max_chunk,
3061 prev->sendfile_max_chunk, 0);
3062 ngx_conf_merge_off_value(conf->directio, prev->directio,
3063 NGX_MAX_OFF_T_VALUE);
3064 ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0);
3065 ngx_conf_merge_value(conf->tcp_nodelay, prev->tcp_nodelay, 1);
3067 ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000);
3068 ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0);
3069 ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output,
3071 ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0);
3072 ngx_conf_merge_msec_value(conf->keepalive_timeout,
3073 prev->keepalive_timeout, 75000);
3074 ngx_conf_merge_sec_value(conf->keepalive_header,
3075 prev->keepalive_header, 0);
3076 ngx_conf_merge_msec_value(conf->lingering_time,
3077 prev->lingering_time, 30000);
3078 ngx_conf_merge_msec_value(conf->lingering_timeout,
3079 prev->lingering_timeout, 5000);
3080 ngx_conf_merge_msec_value(conf->resolver_timeout,
3081 prev->resolver_timeout, 30000);
3083 if (conf->resolver == NULL) {
3085 if (prev->resolver == NULL) {
3088 * create dummy resolver in http {} context
3089 * to inherit it in all servers
3092 prev->resolver = ngx_resolver_create(cf, NULL);
3093 if (prev->resolver == NULL) {
3094 return NGX_CONF_ERROR;
3098 conf->resolver = prev->resolver;
3101 ngx_conf_merge_path_value(conf->client_body_temp_path,
3102 prev->client_body_temp_path,
3103 NGX_HTTP_CLIENT_TEMP_PATH, 0, 0, 0,
3104 ngx_garbage_collector_temp_handler, cf);
3106 ngx_conf_merge_value(conf->reset_timedout_connection,
3107 prev->reset_timedout_connection, 0);
3108 ngx_conf_merge_value(conf->server_name_in_redirect,
3109 prev->server_name_in_redirect, 1);
3110 ngx_conf_merge_value(conf->port_in_redirect, prev->port_in_redirect, 1);
3111 ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1);
3112 ngx_conf_merge_value(conf->msie_refresh, prev->msie_refresh, 0);
3113 ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1);
3114 ngx_conf_merge_value(conf->log_subrequest, prev->log_subrequest, 0);
3115 ngx_conf_merge_value(conf->recursive_error_pages,
3116 prev->recursive_error_pages, 0);
3117 ngx_conf_merge_value(conf->server_tokens, prev->server_tokens, 1);
3119 ngx_conf_merge_ptr_value(conf->open_file_cache,
3120 prev->open_file_cache, NULL);
3122 ngx_conf_merge_sec_value(conf->open_file_cache_valid,
3123 prev->open_file_cache_valid, 60);
3125 ngx_conf_merge_uint_value(conf->open_file_cache_min_uses,
3126 prev->open_file_cache_min_uses, 1);
3128 ngx_conf_merge_sec_value(conf->open_file_cache_errors,
3129 prev->open_file_cache_errors, 0);
3131 ngx_conf_merge_sec_value(conf->open_file_cache_events,
3132 prev->open_file_cache_events, 0);
3135 ngx_conf_merge_value(conf->gzip_vary, prev->gzip_vary, 0);
3136 ngx_conf_merge_uint_value(conf->gzip_http_version, prev->gzip_http_version,
3137 NGX_HTTP_VERSION_11);
3138 ngx_conf_merge_bitmask_value(conf->gzip_proxied, prev->gzip_proxied,
3139 (NGX_CONF_BITMASK_SET|NGX_HTTP_GZIP_PROXIED_OFF));
3142 ngx_conf_merge_ptr_value(conf->gzip_disable, prev->gzip_disable, NULL);
3145 if (conf->gzip_disable_msie6 == 3) {
3146 conf->gzip_disable_msie6 =
3147 (prev->gzip_disable_msie6 == 3) ? 0 : prev->gzip_disable_msie6;
3159 ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3161 ngx_http_core_srv_conf_t *scf = conf;
3163 ngx_str_t *value, size;
3166 ngx_http_listen_t *ls;
3169 * TODO: check duplicate 'listen' directives,
3170 * add resolved name to server names ???
3173 value = cf->args->elts;
3175 ngx_memzero(&u, sizeof(ngx_url_t));
3179 u.default_port = 80;
3181 if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
3183 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3184 "%s in \"%V\" of the \"listen\" directive",
3188 return NGX_CONF_ERROR;
3191 ls = ngx_array_push(&scf->listen);
3193 return NGX_CONF_ERROR;
3196 ngx_memzero(ls, sizeof(ngx_http_listen_t));
3198 ls->family = u.family;
3199 ls->addr = u.addr.in_addr;
3201 ls->file_name = cf->conf_file->file.name.data;
3202 ls->line = cf->conf_file->line;
3203 ls->conf.backlog = NGX_LISTEN_BACKLOG;
3204 ls->conf.rcvbuf = -1;
3205 ls->conf.sndbuf = -1;
3207 n = ngx_inet_ntop(AF_INET, &ls->addr, ls->conf.addr, NGX_INET_ADDRSTRLEN);
3208 ngx_sprintf(&ls->conf.addr[n], ":%ui", ls->port);
3210 if (cf->args->nelts == 2) {
3214 if (ngx_strcmp(value[2].data, "default") == 0) {
3215 ls->conf.default_server = 1;
3222 for ( /* void */ ; n < cf->args->nelts; n++) {
3224 if (ls->conf.default_server == 0) {
3225 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3226 "\"%V\" parameter can be specified for "
3227 "the default \"listen\" directive only",
3229 return NGX_CONF_ERROR;
3232 if (ngx_strcmp(value[n].data, "bind") == 0) {
3237 if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) {
3238 ls->conf.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8);
3241 if (ls->conf.backlog == NGX_ERROR || ls->conf.backlog == 0) {
3242 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3243 "invalid backlog \"%V\"", &value[n]);
3244 return NGX_CONF_ERROR;
3250 if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) {
3251 size.len = value[n].len - 7;
3252 size.data = value[n].data + 7;
3254 ls->conf.rcvbuf = ngx_parse_size(&size);
3257 if (ls->conf.rcvbuf == NGX_ERROR) {
3258 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3259 "invalid rcvbuf \"%V\"", &value[n]);
3260 return NGX_CONF_ERROR;
3266 if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) {
3267 size.len = value[n].len - 7;
3268 size.data = value[n].data + 7;
3270 ls->conf.sndbuf = ngx_parse_size(&size);
3273 if (ls->conf.sndbuf == NGX_ERROR) {
3274 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3275 "invalid sndbuf \"%V\"", &value[n]);
3276 return NGX_CONF_ERROR;
3282 if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) {
3283 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
3284 ls->conf.accept_filter = (char *) &value[n].data[14];
3287 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3288 "accept filters \"%V\" are not supported "
3289 "on this platform, ignored",
3295 if (ngx_strcmp(value[n].data, "deferred") == 0) {
3296 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
3297 ls->conf.deferred_accept = 1;
3300 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3301 "the deferred accept is not supported "
3302 "on this platform, ignored");
3307 if (ngx_strcmp(value[n].data, "ssl") == 0) {
3312 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3313 "the \"ssl\" parameter requires "
3314 "ngx_http_ssl_module");
3315 return NGX_CONF_ERROR;
3319 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3320 "the invalid \"%V\" parameter", &value[n]);
3321 return NGX_CONF_ERROR;
3329 ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3331 ngx_http_core_srv_conf_t *cscf = conf;
3334 ngx_str_t *value, name;
3336 ngx_http_server_name_t *sn;
3338 value = cf->args->elts;
3340 ch = value[1].data[0];
3342 if (cscf->server_name.data == NULL) {
3351 cscf->server_name.len = name.len;
3352 cscf->server_name.data = ngx_pstrdup(cf->pool, &name);
3353 if (cscf->server_name.data == NULL) {
3354 return NGX_CONF_ERROR;
3358 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3359 "the first server name must not be empty");
3360 return NGX_CONF_ERROR;
3364 for (i = 1; i < cf->args->nelts; i++) {
3366 ch = value[i].data[0];
3368 if ((ch == '*' && (value[i].len < 3 || value[i].data[1] != '.'))
3369 || (ch == '.' && value[i].len < 2))
3371 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3372 "server name \"%V\" is invalid", &value[i]);
3373 return NGX_CONF_ERROR;
3376 if (ngx_strchr(value[i].data, '/')) {
3377 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
3378 "server name \"%V\" has strange symbols",
3382 if (value[i].len == 1 && ch == '*') {
3383 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3384 "\"server_name *\" is unsupported, use "
3385 "\"server_name_in_redirect off\" instead");
3386 return NGX_CONF_ERROR;
3389 sn = ngx_array_push(&cscf->server_names);
3391 return NGX_CONF_ERROR;
3397 sn->core_srv_conf = cscf;
3398 sn->name = value[i];
3400 if (value[i].data[0] != '~') {
3407 u_char errstr[NGX_MAX_CONF_ERRSTR];
3409 err.len = NGX_MAX_CONF_ERRSTR;
3415 sn->regex = ngx_regex_compile(&value[i], 0, cf->pool, &err);
3417 if (sn->regex == NULL) {
3418 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
3419 return NGX_CONF_ERROR;
3422 sn->name = value[i];
3425 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3426 "the using of the regex \"%V\" "
3427 "requires PCRE library", &value[i]);
3429 return NGX_CONF_ERROR;
3438 ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3440 ngx_http_core_loc_conf_t *lcf = conf;
3443 ngx_uint_t alias, n;
3444 ngx_http_script_compile_t sc;
3446 alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0;
3448 if (lcf->root.data) {
3450 /* the (ngx_uint_t) cast is required by gcc 2.7.2.3 */
3452 if ((ngx_uint_t) lcf->alias == alias) {
3453 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3454 "\"%V\" directive is duplicate",
3457 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3458 "\"%V\" directive is duplicate, "
3459 "\"%s\" directive is specified before",
3460 &cmd->name, lcf->alias ? "alias" : "root");
3463 return NGX_CONF_ERROR;
3466 if (lcf->named && alias) {
3467 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3468 "the \"alias\" directive may not be used "
3469 "inside named location");
3471 return NGX_CONF_ERROR;
3476 if (lcf->regex && alias) {
3477 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3478 "the \"alias\" directive may not be used "
3479 "inside location given by regular expression");
3481 return NGX_CONF_ERROR;
3486 value = cf->args->elts;
3488 if (ngx_strstr(value[1].data, "$document_root")
3489 || ngx_strstr(value[1].data, "${document_root}"))
3491 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3492 "the $document_root variable may not be used "
3493 "in the \"%V\" directive",
3496 return NGX_CONF_ERROR;
3499 if (ngx_strstr(value[1].data, "$realpath_root")
3500 || ngx_strstr(value[1].data, "${realpath_root}"))
3502 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3503 "the $realpath_root variable may not be used "
3504 "in the \"%V\" directive",
3507 return NGX_CONF_ERROR;
3511 lcf->root = value[1];
3513 if (!alias && lcf->root.data[lcf->root.len - 1] == '/') {
3517 if (lcf->root.data[0] != '$') {
3518 if (ngx_conf_full_name(cf->cycle, &lcf->root, 0) == NGX_ERROR) {
3519 return NGX_CONF_ERROR;
3523 n = ngx_http_script_variables_count(&lcf->root);
3529 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
3532 sc.source = &lcf->root;
3533 sc.lengths = &lcf->root_lengths;
3534 sc.values = &lcf->root_values;
3536 sc.complete_lengths = 1;
3537 sc.complete_values = 1;
3539 if (ngx_http_script_compile(&sc) != NGX_OK) {
3540 return NGX_CONF_ERROR;
3547 static ngx_http_method_name_t ngx_methods_names[] = {
3548 { (u_char *) "GET", (uint32_t) ~NGX_HTTP_GET },
3549 { (u_char *) "HEAD", (uint32_t) ~NGX_HTTP_HEAD },
3550 { (u_char *) "POST", (uint32_t) ~NGX_HTTP_POST },
3551 { (u_char *) "PUT", (uint32_t) ~NGX_HTTP_PUT },
3552 { (u_char *) "DELETE", (uint32_t) ~NGX_HTTP_DELETE },
3553 { (u_char *) "MKCOL", (uint32_t) ~NGX_HTTP_MKCOL },
3554 { (u_char *) "COPY", (uint32_t) ~NGX_HTTP_COPY },
3555 { (u_char *) "MOVE", (uint32_t) ~NGX_HTTP_MOVE },
3556 { (u_char *) "OPTIONS", (uint32_t) ~NGX_HTTP_OPTIONS },
3557 { (u_char *) "PROPFIND" , (uint32_t) ~NGX_HTTP_PROPFIND },
3558 { (u_char *) "PROPPATCH", (uint32_t) ~NGX_HTTP_PROPPATCH },
3559 { (u_char *) "LOCK", (uint32_t) ~NGX_HTTP_LOCK },
3560 { (u_char *) "UNLOCK", (uint32_t) ~NGX_HTTP_UNLOCK },
3566 ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3568 ngx_http_core_loc_conf_t *pclcf = conf;
3575 ngx_http_module_t *module;
3576 ngx_http_conf_ctx_t *ctx, *pctx;
3577 ngx_http_method_name_t *name;
3578 ngx_http_core_loc_conf_t *clcf;
3580 if (pclcf->limit_except) {
3584 pclcf->limit_except = 0xffffffff;
3586 value = cf->args->elts;
3588 for (i = 1; i < cf->args->nelts; i++) {
3589 for (name = ngx_methods_names; name->name; name++) {
3591 if (ngx_strcasecmp(value[i].data, name->name) == 0) {
3592 pclcf->limit_except &= name->method;
3597 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3598 "invalid method \"%V\"", &value[i]);
3599 return NGX_CONF_ERROR;
3605 if (!(pclcf->limit_except & NGX_HTTP_GET)) {
3606 pclcf->limit_except &= (uint32_t) ~NGX_HTTP_HEAD;
3609 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
3611 return NGX_CONF_ERROR;
3615 ctx->main_conf = pctx->main_conf;
3616 ctx->srv_conf = pctx->srv_conf;
3618 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
3619 if (ctx->loc_conf == NULL) {
3620 return NGX_CONF_ERROR;
3623 for (i = 0; ngx_modules[i]; i++) {
3624 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
3628 module = ngx_modules[i]->ctx;
3630 if (module->create_loc_conf) {
3632 mconf = module->create_loc_conf(cf);
3633 if (mconf == NULL) {
3634 return NGX_CONF_ERROR;
3637 ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
3642 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
3643 pclcf->limit_except_loc_conf = ctx->loc_conf;
3644 clcf->loc_conf = ctx->loc_conf;
3645 clcf->name = pclcf->name;
3648 if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
3649 return NGX_CONF_ERROR;
3654 cf->cmd_type = NGX_HTTP_LMT_CONF;
3656 rv = ngx_conf_parse(cf, NULL);
3665 ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3667 ngx_http_core_loc_conf_t *clcf = conf;
3671 if (clcf->directio != NGX_CONF_UNSET) {
3672 return "is duplicate";
3675 value = cf->args->elts;
3677 if (ngx_strcmp(value[1].data, "off") == 0) {
3678 clcf->directio = NGX_OPEN_FILE_DIRECTIO_OFF;
3682 clcf->directio = ngx_parse_offset(&value[1]);
3683 if (clcf->directio == (off_t) NGX_ERROR) {
3684 return "invalid value";
3692 ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3694 ngx_http_core_loc_conf_t *lcf = conf;
3697 ngx_int_t overwrite;
3698 ngx_str_t *value, uri;
3699 ngx_uint_t i, n, nvar;
3700 ngx_array_t *uri_lengths, *uri_values;
3701 ngx_http_err_page_t *err;
3702 ngx_http_script_compile_t sc;
3704 if (lcf->error_pages == NULL) {
3705 lcf->error_pages = ngx_array_create(cf->pool, 4,
3706 sizeof(ngx_http_err_page_t));
3707 if (lcf->error_pages == NULL) {
3708 return NGX_CONF_ERROR;
3712 value = cf->args->elts;
3714 i = cf->args->nelts - 2;
3716 if (value[i].data[0] == '=') {
3718 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3719 "invalid value \"%V\"", &value[i]);
3720 return NGX_CONF_ERROR;
3723 if (value[i].len > 1) {
3724 overwrite = ngx_atoi(&value[i].data[1], value[i].len - 1);
3726 if (overwrite == NGX_ERROR) {
3727 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3728 "invalid value \"%V\"", &value[i]);
3729 return NGX_CONF_ERROR;
3743 uri = value[cf->args->nelts - 1];
3747 nvar = ngx_http_script_variables_count(&uri);
3750 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
3754 sc.lengths = &uri_lengths;
3755 sc.values = &uri_values;
3756 sc.variables = nvar;
3757 sc.complete_lengths = 1;
3758 sc.complete_values = 1;
3760 if (ngx_http_script_compile(&sc) != NGX_OK) {
3761 return NGX_CONF_ERROR;
3765 args = (u_char *) ngx_strchr(uri.data, '?');
3767 for (i = 1; i < cf->args->nelts - n; i++) {
3768 err = ngx_array_push(lcf->error_pages);
3770 return NGX_CONF_ERROR;
3773 err->status = ngx_atoi(value[i].data, value[i].len);
3775 if (err->status == NGX_ERROR || err->status == 499) {
3776 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3777 "invalid value \"%V\"", &value[i]);
3778 return NGX_CONF_ERROR;
3781 if (err->status < 400 || err->status > 599) {
3782 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3783 "value \"%V\" must be between 400 and 599",
3785 return NGX_CONF_ERROR;
3788 if (overwrite >= 0) {
3789 err->overwrite = overwrite;
3792 switch (err->status) {
3793 case NGX_HTTP_TO_HTTPS:
3794 case NGX_HTTPS_CERT_ERROR:
3795 case NGX_HTTPS_NO_CERT:
3796 err->overwrite = NGX_HTTP_BAD_REQUEST;
3800 err->overwrite = err->status;
3806 err->uri.len = args - uri.data;
3807 err->uri.data = uri.data;
3809 err->args.len = (uri.data + uri.len) - args;
3810 err->args.data = args;
3815 err->args.data = NULL;
3818 err->uri_lengths = uri_lengths;
3819 err->uri_values = uri_values;
3827 ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3829 ngx_http_core_loc_conf_t *clcf = conf;
3833 ngx_http_try_file_t *tf;
3834 ngx_http_script_compile_t sc;
3835 ngx_http_core_main_conf_t *cmcf;
3837 if (clcf->try_files) {
3838 return "is duplicate";
3841 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
3843 cmcf->try_files = 1;
3845 tf = ngx_pcalloc(cf->pool, cf->args->nelts * sizeof(ngx_http_try_file_t));
3847 return NGX_CONF_ERROR;
3850 clcf->try_files = tf;
3852 value = cf->args->elts;
3854 for (i = 0; i < cf->args->nelts - 1; i++) {
3856 tf[i].name = value[i + 1];
3858 if (tf[i].name.data[tf[i].name.len - 1] == '/') {
3863 n = ngx_http_script_variables_count(&tf[i].name);
3866 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
3869 sc.source = &tf[i].name;
3870 sc.lengths = &tf[i].lengths;
3871 sc.values = &tf[i].values;
3873 sc.complete_lengths = 1;
3874 sc.complete_values = 1;
3876 if (ngx_http_script_compile(&sc) != NGX_OK) {
3877 return NGX_CONF_ERROR;
3881 /* add trailing '\0' to length */
3891 ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3893 ngx_http_core_loc_conf_t *lcf = conf;
3896 ngx_str_t *value, s;
3900 if (lcf->open_file_cache != NGX_CONF_UNSET_PTR) {
3901 return "is duplicate";
3904 value = cf->args->elts;
3909 for (i = 1; i < cf->args->nelts; i++) {
3911 if (ngx_strncmp(value[i].data, "max=", 4) == 0) {
3913 max = ngx_atoi(value[i].data + 4, value[i].len - 4);
3914 if (max == NGX_ERROR) {
3921 if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) {
3923 s.len = value[i].len - 9;
3924 s.data = value[i].data + 9;
3926 inactive = ngx_parse_time(&s, 1);
3934 if (ngx_strcmp(value[i].data, "off") == 0) {
3936 lcf->open_file_cache = NULL;
3943 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3944 "invalid \"open_file_cache\" parameter \"%V\"",
3946 return NGX_CONF_ERROR;
3949 if (lcf->open_file_cache == NULL) {
3954 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3955 "\"open_file_cache\" must have \"max\" parameter");
3956 return NGX_CONF_ERROR;
3959 lcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive);
3960 if (lcf->open_file_cache) {
3964 return NGX_CONF_ERROR;
3969 ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3971 ngx_http_core_loc_conf_t *lcf = conf;
3973 lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args);
3974 if (lcf->err_log == NULL) {
3975 return NGX_CONF_ERROR;
3978 return ngx_set_error_log_levels(cf, lcf->err_log);
3983 ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3985 ngx_http_core_loc_conf_t *lcf = conf;
3989 if (lcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) {
3990 return "is duplicate";
3993 value = cf->args->elts;
3995 lcf->keepalive_timeout = ngx_parse_time(&value[1], 0);
3997 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) {
3998 return "invalid value";
4001 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) {
4002 return "value must be less than 597 hours";
4005 if (cf->args->nelts == 2) {
4009 lcf->keepalive_header = ngx_parse_time(&value[2], 1);
4011 if (lcf->keepalive_header == NGX_ERROR) {
4012 return "invalid value";
4015 if (lcf->keepalive_header == NGX_PARSE_LARGE_TIME) {
4016 return "value must be less than 68 years";
4024 ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4026 ngx_http_core_loc_conf_t *lcf = conf;
4028 if (lcf->internal != NGX_CONF_UNSET) {
4029 return "is duplicate";
4039 ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4041 ngx_http_core_loc_conf_t *clcf = conf;
4046 if (clcf->resolver) {
4047 return "is duplicate";
4050 value = cf->args->elts;
4052 ngx_memzero(&u, sizeof(ngx_url_t));
4057 if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
4058 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V: %s", &u.host, u.err);
4059 return NGX_CONF_ERROR;
4062 clcf->resolver = ngx_resolver_create(cf, &u.addrs[0]);
4063 if (clcf->resolver == NULL) {
4074 ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4076 ngx_http_core_loc_conf_t *clcf = conf;
4080 ngx_str_t err, *value;
4082 ngx_regex_elt_t *re;
4083 u_char errstr[NGX_MAX_CONF_ERRSTR];
4085 if (clcf->gzip_disable == NGX_CONF_UNSET_PTR) {
4086 clcf->gzip_disable = ngx_array_create(cf->pool, 2,
4087 sizeof(ngx_regex_elt_t));
4088 if (clcf->gzip_disable == NULL) {
4089 return NGX_CONF_ERROR;
4093 value = cf->args->elts;
4095 err.len = NGX_MAX_CONF_ERRSTR;
4098 for (i = 1; i < cf->args->nelts; i++) {
4100 if (ngx_strcmp(value[1].data, "msie6") == 0) {
4101 clcf->gzip_disable_msie6 = 1;
4105 re = ngx_array_push(clcf->gzip_disable);
4107 return NGX_CONF_ERROR;
4110 re->regex = ngx_regex_compile(&value[i], NGX_REGEX_CASELESS, cf->pool,
4113 if (re->regex == NULL) {
4114 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
4115 return NGX_CONF_ERROR;
4118 re->name = value[i].data;
4126 value = cf->args->elts;
4128 if (cf->args->nelts == 2 && ngx_strcmp(value[1].data, "msie6") == 0) {
4129 clcf->gzip_disable_msie6 = 1;
4133 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4134 "without PCRE library \"gzip_disable\" supports "
4135 "builtin \"msie6\" mask only");
4137 return NGX_CONF_ERROR;
4145 ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data)
4150 if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) {
4151 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4152 "\"send_lowat\" must be less than %d "
4153 "(sysctl net.inet.tcp.sendspace)",
4154 ngx_freebsd_net_inet_tcp_sendspace);
4156 return NGX_CONF_ERROR;
4159 #elif !(NGX_HAVE_SO_SNDLOWAT)
4162 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
4163 "\"send_lowat\" is not supported, ignored");
4174 ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data)
4178 if (*sp < NGX_MIN_POOL_SIZE) {
4179 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4180 "pool must be no less than %uz", NGX_MIN_POOL_SIZE);
4182 return NGX_CONF_ERROR;