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 #if (NGX_HAVE_FILE_AIO)
109 static ngx_conf_enum_t ngx_http_core_aio
[] = {
110 { ngx_string("off"), NGX_HTTP_AIO_OFF
},
111 { ngx_string("on"), NGX_HTTP_AIO_ON
},
112 #if (NGX_HAVE_AIO_SENDFILE)
113 { ngx_string("sendfile"), NGX_HTTP_AIO_SENDFILE
},
115 { ngx_null_string
, 0 }
121 static ngx_conf_enum_t ngx_http_core_satisfy
[] = {
122 { ngx_string("all"), NGX_HTTP_SATISFY_ALL
},
123 { ngx_string("any"), NGX_HTTP_SATISFY_ANY
},
124 { ngx_null_string
, 0 }
128 static ngx_conf_enum_t ngx_http_core_if_modified_since
[] = {
129 { ngx_string("off"), NGX_HTTP_IMS_OFF
},
130 { ngx_string("exact"), NGX_HTTP_IMS_EXACT
},
131 { ngx_string("before"), NGX_HTTP_IMS_BEFORE
},
132 { ngx_null_string
, 0 }
136 static ngx_path_init_t ngx_http_client_temp_path
= {
137 ngx_string(NGX_HTTP_CLIENT_TEMP_PATH
), { 0, 0, 0 }
143 static ngx_conf_enum_t ngx_http_gzip_http_version
[] = {
144 { ngx_string("1.0"), NGX_HTTP_VERSION_10
},
145 { ngx_string("1.1"), NGX_HTTP_VERSION_11
},
146 { ngx_null_string
, 0 }
150 static ngx_conf_bitmask_t ngx_http_gzip_proxied_mask
[] = {
151 { ngx_string("off"), NGX_HTTP_GZIP_PROXIED_OFF
},
152 { ngx_string("expired"), NGX_HTTP_GZIP_PROXIED_EXPIRED
},
153 { ngx_string("no-cache"), NGX_HTTP_GZIP_PROXIED_NO_CACHE
},
154 { ngx_string("no-store"), NGX_HTTP_GZIP_PROXIED_NO_STORE
},
155 { ngx_string("private"), NGX_HTTP_GZIP_PROXIED_PRIVATE
},
156 { ngx_string("no_last_modified"), NGX_HTTP_GZIP_PROXIED_NO_LM
},
157 { ngx_string("no_etag"), NGX_HTTP_GZIP_PROXIED_NO_ETAG
},
158 { ngx_string("auth"), NGX_HTTP_GZIP_PROXIED_AUTH
},
159 { ngx_string("any"), NGX_HTTP_GZIP_PROXIED_ANY
},
160 { ngx_null_string
, 0 }
164 static ngx_str_t ngx_http_gzip_no_cache
= ngx_string("no-cache");
165 static ngx_str_t ngx_http_gzip_no_store
= ngx_string("no-store");
166 static ngx_str_t ngx_http_gzip_private
= ngx_string("private");
171 static ngx_command_t ngx_http_core_commands
[] = {
173 { ngx_string("variables_hash_max_size"),
174 NGX_HTTP_MAIN_CONF
|NGX_CONF_TAKE1
,
175 ngx_conf_set_num_slot
,
176 NGX_HTTP_MAIN_CONF_OFFSET
,
177 offsetof(ngx_http_core_main_conf_t
, variables_hash_max_size
),
180 { ngx_string("variables_hash_bucket_size"),
181 NGX_HTTP_MAIN_CONF
|NGX_CONF_TAKE1
,
182 ngx_conf_set_num_slot
,
183 NGX_HTTP_MAIN_CONF_OFFSET
,
184 offsetof(ngx_http_core_main_conf_t
, variables_hash_bucket_size
),
187 { ngx_string("server_names_hash_max_size"),
188 NGX_HTTP_MAIN_CONF
|NGX_CONF_TAKE1
,
189 ngx_conf_set_num_slot
,
190 NGX_HTTP_MAIN_CONF_OFFSET
,
191 offsetof(ngx_http_core_main_conf_t
, server_names_hash_max_size
),
194 { ngx_string("server_names_hash_bucket_size"),
195 NGX_HTTP_MAIN_CONF
|NGX_CONF_TAKE1
,
196 ngx_conf_set_num_slot
,
197 NGX_HTTP_MAIN_CONF_OFFSET
,
198 offsetof(ngx_http_core_main_conf_t
, server_names_hash_bucket_size
),
201 { ngx_string("server"),
202 NGX_HTTP_MAIN_CONF
|NGX_CONF_BLOCK
|NGX_CONF_MULTI
|NGX_CONF_NOARGS
,
203 ngx_http_core_server
,
208 { ngx_string("connection_pool_size"),
209 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_TAKE1
,
210 ngx_conf_set_size_slot
,
211 NGX_HTTP_SRV_CONF_OFFSET
,
212 offsetof(ngx_http_core_srv_conf_t
, connection_pool_size
),
213 &ngx_http_core_pool_size_p
},
215 { ngx_string("request_pool_size"),
216 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_TAKE1
,
217 ngx_conf_set_size_slot
,
218 NGX_HTTP_SRV_CONF_OFFSET
,
219 offsetof(ngx_http_core_srv_conf_t
, request_pool_size
),
220 &ngx_http_core_pool_size_p
},
222 { ngx_string("client_header_timeout"),
223 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_TAKE1
,
224 ngx_conf_set_msec_slot
,
225 NGX_HTTP_SRV_CONF_OFFSET
,
226 offsetof(ngx_http_core_srv_conf_t
, client_header_timeout
),
229 { ngx_string("client_header_buffer_size"),
230 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_TAKE1
,
231 ngx_conf_set_size_slot
,
232 NGX_HTTP_SRV_CONF_OFFSET
,
233 offsetof(ngx_http_core_srv_conf_t
, client_header_buffer_size
),
236 { ngx_string("large_client_header_buffers"),
237 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_TAKE2
,
238 ngx_conf_set_bufs_slot
,
239 NGX_HTTP_SRV_CONF_OFFSET
,
240 offsetof(ngx_http_core_srv_conf_t
, large_client_header_buffers
),
243 { ngx_string("optimize_server_names"),
244 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_FLAG
,
245 ngx_conf_set_flag_slot
,
246 NGX_HTTP_LOC_CONF_OFFSET
,
247 offsetof(ngx_http_core_loc_conf_t
, server_name_in_redirect
),
248 &ngx_conf_deprecated_optimize_server_names
},
250 { ngx_string("ignore_invalid_headers"),
251 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_FLAG
,
252 ngx_conf_set_flag_slot
,
253 NGX_HTTP_SRV_CONF_OFFSET
,
254 offsetof(ngx_http_core_srv_conf_t
, ignore_invalid_headers
),
257 { ngx_string("merge_slashes"),
258 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_FLAG
,
259 ngx_conf_set_flag_slot
,
260 NGX_HTTP_SRV_CONF_OFFSET
,
261 offsetof(ngx_http_core_srv_conf_t
, merge_slashes
),
264 { ngx_string("underscores_in_headers"),
265 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_FLAG
,
266 ngx_conf_set_flag_slot
,
267 NGX_HTTP_SRV_CONF_OFFSET
,
268 offsetof(ngx_http_core_srv_conf_t
, underscores_in_headers
),
271 { ngx_string("location"),
272 NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_BLOCK
|NGX_CONF_TAKE12
,
273 ngx_http_core_location
,
274 NGX_HTTP_SRV_CONF_OFFSET
,
278 { ngx_string("listen"),
279 NGX_HTTP_SRV_CONF
|NGX_CONF_1MORE
,
280 ngx_http_core_listen
,
281 NGX_HTTP_SRV_CONF_OFFSET
,
285 { ngx_string("server_name"),
286 NGX_HTTP_SRV_CONF
|NGX_CONF_1MORE
,
287 ngx_http_core_server_name
,
288 NGX_HTTP_SRV_CONF_OFFSET
,
292 { ngx_string("types_hash_max_size"),
293 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
294 ngx_conf_set_num_slot
,
295 NGX_HTTP_LOC_CONF_OFFSET
,
296 offsetof(ngx_http_core_loc_conf_t
, types_hash_max_size
),
299 { ngx_string("types_hash_bucket_size"),
300 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
301 ngx_conf_set_num_slot
,
302 NGX_HTTP_LOC_CONF_OFFSET
,
303 offsetof(ngx_http_core_loc_conf_t
, types_hash_bucket_size
),
306 { ngx_string("types"),
307 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
308 |NGX_CONF_BLOCK
|NGX_CONF_NOARGS
,
310 NGX_HTTP_LOC_CONF_OFFSET
,
314 { ngx_string("default_type"),
315 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
316 ngx_conf_set_str_slot
,
317 NGX_HTTP_LOC_CONF_OFFSET
,
318 offsetof(ngx_http_core_loc_conf_t
, default_type
),
321 { ngx_string("root"),
322 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_HTTP_LIF_CONF
325 NGX_HTTP_LOC_CONF_OFFSET
,
329 { ngx_string("alias"),
330 NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
332 NGX_HTTP_LOC_CONF_OFFSET
,
336 { ngx_string("limit_except"),
337 NGX_HTTP_LOC_CONF
|NGX_CONF_BLOCK
|NGX_CONF_1MORE
,
338 ngx_http_core_limit_except
,
339 NGX_HTTP_LOC_CONF_OFFSET
,
343 { ngx_string("client_max_body_size"),
344 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
345 ngx_conf_set_off_slot
,
346 NGX_HTTP_LOC_CONF_OFFSET
,
347 offsetof(ngx_http_core_loc_conf_t
, client_max_body_size
),
350 { ngx_string("client_body_buffer_size"),
351 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
352 ngx_conf_set_size_slot
,
353 NGX_HTTP_LOC_CONF_OFFSET
,
354 offsetof(ngx_http_core_loc_conf_t
, client_body_buffer_size
),
357 { ngx_string("client_body_timeout"),
358 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
359 ngx_conf_set_msec_slot
,
360 NGX_HTTP_LOC_CONF_OFFSET
,
361 offsetof(ngx_http_core_loc_conf_t
, client_body_timeout
),
364 { ngx_string("client_body_temp_path"),
365 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1234
,
366 ngx_conf_set_path_slot
,
367 NGX_HTTP_LOC_CONF_OFFSET
,
368 offsetof(ngx_http_core_loc_conf_t
, client_body_temp_path
),
371 { ngx_string("client_body_in_file_only"),
372 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
373 ngx_conf_set_enum_slot
,
374 NGX_HTTP_LOC_CONF_OFFSET
,
375 offsetof(ngx_http_core_loc_conf_t
, client_body_in_file_only
),
376 &ngx_http_core_request_body_in_file
},
378 { ngx_string("client_body_in_single_buffer"),
379 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
380 ngx_conf_set_flag_slot
,
381 NGX_HTTP_LOC_CONF_OFFSET
,
382 offsetof(ngx_http_core_loc_conf_t
, client_body_in_single_buffer
),
385 { ngx_string("sendfile"),
386 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_HTTP_LIF_CONF
388 ngx_conf_set_flag_slot
,
389 NGX_HTTP_LOC_CONF_OFFSET
,
390 offsetof(ngx_http_core_loc_conf_t
, sendfile
),
393 { ngx_string("sendfile_max_chunk"),
394 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
395 ngx_conf_set_size_slot
,
396 NGX_HTTP_LOC_CONF_OFFSET
,
397 offsetof(ngx_http_core_loc_conf_t
, sendfile_max_chunk
),
400 #if (NGX_HAVE_FILE_AIO)
403 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
404 ngx_conf_set_enum_slot
,
405 NGX_HTTP_LOC_CONF_OFFSET
,
406 offsetof(ngx_http_core_loc_conf_t
, aio
),
407 &ngx_http_core_aio
},
411 { ngx_string("read_ahead"),
412 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
413 ngx_conf_set_size_slot
,
414 NGX_HTTP_LOC_CONF_OFFSET
,
415 offsetof(ngx_http_core_loc_conf_t
, read_ahead
),
418 { ngx_string("directio"),
419 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
420 ngx_http_core_directio
,
421 NGX_HTTP_LOC_CONF_OFFSET
,
425 { ngx_string("directio_alignment"),
426 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
427 ngx_conf_set_off_slot
,
428 NGX_HTTP_LOC_CONF_OFFSET
,
429 offsetof(ngx_http_core_loc_conf_t
, directio_alignment
),
432 { ngx_string("tcp_nopush"),
433 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
434 ngx_conf_set_flag_slot
,
435 NGX_HTTP_LOC_CONF_OFFSET
,
436 offsetof(ngx_http_core_loc_conf_t
, tcp_nopush
),
439 { ngx_string("tcp_nodelay"),
440 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
441 ngx_conf_set_flag_slot
,
442 NGX_HTTP_LOC_CONF_OFFSET
,
443 offsetof(ngx_http_core_loc_conf_t
, tcp_nodelay
),
446 { ngx_string("send_timeout"),
447 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
448 ngx_conf_set_msec_slot
,
449 NGX_HTTP_LOC_CONF_OFFSET
,
450 offsetof(ngx_http_core_loc_conf_t
, send_timeout
),
453 { ngx_string("send_lowat"),
454 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
455 ngx_conf_set_size_slot
,
456 NGX_HTTP_LOC_CONF_OFFSET
,
457 offsetof(ngx_http_core_loc_conf_t
, send_lowat
),
458 &ngx_http_core_lowat_post
},
460 { ngx_string("postpone_output"),
461 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
462 ngx_conf_set_size_slot
,
463 NGX_HTTP_LOC_CONF_OFFSET
,
464 offsetof(ngx_http_core_loc_conf_t
, postpone_output
),
467 { ngx_string("limit_rate"),
468 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_HTTP_LIF_CONF
470 ngx_conf_set_size_slot
,
471 NGX_HTTP_LOC_CONF_OFFSET
,
472 offsetof(ngx_http_core_loc_conf_t
, limit_rate
),
475 { ngx_string("limit_rate_after"),
476 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_HTTP_LIF_CONF
478 ngx_conf_set_size_slot
,
479 NGX_HTTP_LOC_CONF_OFFSET
,
480 offsetof(ngx_http_core_loc_conf_t
, limit_rate_after
),
483 { ngx_string("keepalive_timeout"),
484 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE12
,
485 ngx_http_core_keepalive
,
486 NGX_HTTP_LOC_CONF_OFFSET
,
490 { ngx_string("keepalive_requests"),
491 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
492 ngx_conf_set_num_slot
,
493 NGX_HTTP_LOC_CONF_OFFSET
,
494 offsetof(ngx_http_core_loc_conf_t
, keepalive_requests
),
497 { ngx_string("satisfy"),
498 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
499 ngx_conf_set_enum_slot
,
500 NGX_HTTP_LOC_CONF_OFFSET
,
501 offsetof(ngx_http_core_loc_conf_t
, satisfy
),
502 &ngx_http_core_satisfy
},
504 { ngx_string("satisfy_any"),
505 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
506 ngx_conf_set_flag_slot
,
507 NGX_HTTP_LOC_CONF_OFFSET
,
508 offsetof(ngx_http_core_loc_conf_t
, satisfy
),
509 &ngx_conf_deprecated_satisfy_any
},
511 { ngx_string("internal"),
512 NGX_HTTP_LOC_CONF
|NGX_CONF_NOARGS
,
513 ngx_http_core_internal
,
514 NGX_HTTP_LOC_CONF_OFFSET
,
518 { ngx_string("lingering_time"),
519 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
520 ngx_conf_set_msec_slot
,
521 NGX_HTTP_LOC_CONF_OFFSET
,
522 offsetof(ngx_http_core_loc_conf_t
, lingering_time
),
525 { ngx_string("lingering_timeout"),
526 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
527 ngx_conf_set_msec_slot
,
528 NGX_HTTP_LOC_CONF_OFFSET
,
529 offsetof(ngx_http_core_loc_conf_t
, lingering_timeout
),
532 { ngx_string("reset_timedout_connection"),
533 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
534 ngx_conf_set_flag_slot
,
535 NGX_HTTP_LOC_CONF_OFFSET
,
536 offsetof(ngx_http_core_loc_conf_t
, reset_timedout_connection
),
539 { ngx_string("server_name_in_redirect"),
540 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
541 ngx_conf_set_flag_slot
,
542 NGX_HTTP_LOC_CONF_OFFSET
,
543 offsetof(ngx_http_core_loc_conf_t
, server_name_in_redirect
),
546 { ngx_string("port_in_redirect"),
547 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
548 ngx_conf_set_flag_slot
,
549 NGX_HTTP_LOC_CONF_OFFSET
,
550 offsetof(ngx_http_core_loc_conf_t
, port_in_redirect
),
553 { ngx_string("msie_padding"),
554 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
555 ngx_conf_set_flag_slot
,
556 NGX_HTTP_LOC_CONF_OFFSET
,
557 offsetof(ngx_http_core_loc_conf_t
, msie_padding
),
560 { ngx_string("msie_refresh"),
561 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
562 ngx_conf_set_flag_slot
,
563 NGX_HTTP_LOC_CONF_OFFSET
,
564 offsetof(ngx_http_core_loc_conf_t
, msie_refresh
),
567 { ngx_string("log_not_found"),
568 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
569 ngx_conf_set_flag_slot
,
570 NGX_HTTP_LOC_CONF_OFFSET
,
571 offsetof(ngx_http_core_loc_conf_t
, log_not_found
),
574 { ngx_string("log_subrequest"),
575 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
576 ngx_conf_set_flag_slot
,
577 NGX_HTTP_LOC_CONF_OFFSET
,
578 offsetof(ngx_http_core_loc_conf_t
, log_subrequest
),
581 { ngx_string("recursive_error_pages"),
582 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
583 ngx_conf_set_flag_slot
,
584 NGX_HTTP_LOC_CONF_OFFSET
,
585 offsetof(ngx_http_core_loc_conf_t
, recursive_error_pages
),
588 { ngx_string("server_tokens"),
589 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
590 ngx_conf_set_flag_slot
,
591 NGX_HTTP_LOC_CONF_OFFSET
,
592 offsetof(ngx_http_core_loc_conf_t
, server_tokens
),
595 { ngx_string("if_modified_since"),
596 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
597 ngx_conf_set_enum_slot
,
598 NGX_HTTP_LOC_CONF_OFFSET
,
599 offsetof(ngx_http_core_loc_conf_t
, if_modified_since
),
600 &ngx_http_core_if_modified_since
},
602 { ngx_string("error_page"),
603 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_HTTP_LIF_CONF
605 ngx_http_core_error_page
,
606 NGX_HTTP_LOC_CONF_OFFSET
,
610 { ngx_string("try_files"),
611 NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_2MORE
,
612 ngx_http_core_try_files
,
613 NGX_HTTP_LOC_CONF_OFFSET
,
617 { ngx_string("post_action"),
618 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_HTTP_LIF_CONF
620 ngx_conf_set_str_slot
,
621 NGX_HTTP_LOC_CONF_OFFSET
,
622 offsetof(ngx_http_core_loc_conf_t
, post_action
),
625 { ngx_string("error_log"),
626 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_1MORE
,
627 ngx_http_core_error_log
,
628 NGX_HTTP_LOC_CONF_OFFSET
,
632 { ngx_string("open_file_cache"),
633 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE12
,
634 ngx_http_core_open_file_cache
,
635 NGX_HTTP_LOC_CONF_OFFSET
,
636 offsetof(ngx_http_core_loc_conf_t
, open_file_cache
),
639 { ngx_string("open_file_cache_valid"),
640 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
641 ngx_conf_set_sec_slot
,
642 NGX_HTTP_LOC_CONF_OFFSET
,
643 offsetof(ngx_http_core_loc_conf_t
, open_file_cache_valid
),
646 { ngx_string("open_file_cache_retest"),
647 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
648 ngx_conf_set_sec_slot
,
649 NGX_HTTP_LOC_CONF_OFFSET
,
650 offsetof(ngx_http_core_loc_conf_t
, open_file_cache_valid
),
651 &ngx_conf_deprecated_open_file_cache_retest
},
653 { ngx_string("open_file_cache_min_uses"),
654 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
655 ngx_conf_set_num_slot
,
656 NGX_HTTP_LOC_CONF_OFFSET
,
657 offsetof(ngx_http_core_loc_conf_t
, open_file_cache_min_uses
),
660 { ngx_string("open_file_cache_errors"),
661 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
662 ngx_conf_set_flag_slot
,
663 NGX_HTTP_LOC_CONF_OFFSET
,
664 offsetof(ngx_http_core_loc_conf_t
, open_file_cache_errors
),
667 { ngx_string("open_file_cache_events"),
668 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
669 ngx_conf_set_flag_slot
,
670 NGX_HTTP_LOC_CONF_OFFSET
,
671 offsetof(ngx_http_core_loc_conf_t
, open_file_cache_events
),
674 { ngx_string("resolver"),
675 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
676 ngx_http_core_resolver
,
677 NGX_HTTP_LOC_CONF_OFFSET
,
681 { ngx_string("resolver_timeout"),
682 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
683 ngx_conf_set_msec_slot
,
684 NGX_HTTP_LOC_CONF_OFFSET
,
685 offsetof(ngx_http_core_loc_conf_t
, resolver_timeout
),
690 { ngx_string("gzip_vary"),
691 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
692 ngx_conf_set_flag_slot
,
693 NGX_HTTP_LOC_CONF_OFFSET
,
694 offsetof(ngx_http_core_loc_conf_t
, gzip_vary
),
697 { ngx_string("gzip_http_version"),
698 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
699 ngx_conf_set_enum_slot
,
700 NGX_HTTP_LOC_CONF_OFFSET
,
701 offsetof(ngx_http_core_loc_conf_t
, gzip_http_version
),
702 &ngx_http_gzip_http_version
},
704 { ngx_string("gzip_proxied"),
705 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_1MORE
,
706 ngx_conf_set_bitmask_slot
,
707 NGX_HTTP_LOC_CONF_OFFSET
,
708 offsetof(ngx_http_core_loc_conf_t
, gzip_proxied
),
709 &ngx_http_gzip_proxied_mask
},
711 { ngx_string("gzip_disable"),
712 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_1MORE
,
713 ngx_http_gzip_disable
,
714 NGX_HTTP_LOC_CONF_OFFSET
,
724 static ngx_http_module_t ngx_http_core_module_ctx
= {
725 ngx_http_core_preconfiguration
, /* preconfiguration */
726 NULL
, /* postconfiguration */
728 ngx_http_core_create_main_conf
, /* create main configuration */
729 ngx_http_core_init_main_conf
, /* init main configuration */
731 ngx_http_core_create_srv_conf
, /* create server configuration */
732 ngx_http_core_merge_srv_conf
, /* merge server configuration */
734 ngx_http_core_create_loc_conf
, /* create location configuration */
735 ngx_http_core_merge_loc_conf
/* merge location configuration */
739 ngx_module_t ngx_http_core_module
= {
741 &ngx_http_core_module_ctx
, /* module context */
742 ngx_http_core_commands
, /* module directives */
743 NGX_HTTP_MODULE
, /* module type */
744 NULL
, /* init master */
745 NULL
, /* init module */
746 NULL
, /* init process */
747 NULL
, /* init thread */
748 NULL
, /* exit thread */
749 NULL
, /* exit process */
750 NULL
, /* exit master */
751 NGX_MODULE_V1_PADDING
755 ngx_str_t ngx_http_core_get_method
= { 3, (u_char
*) "GET " };
759 ngx_http_handler(ngx_http_request_t
*r
)
761 ngx_http_core_main_conf_t
*cmcf
;
763 r
->connection
->log
->action
= NULL
;
765 r
->connection
->unexpected_eof
= 0;
768 switch (r
->headers_in
.connection_type
) {
770 if (r
->http_version
> NGX_HTTP_VERSION_10
) {
777 case NGX_HTTP_CONNECTION_CLOSE
:
781 case NGX_HTTP_CONNECTION_KEEP_ALIVE
:
786 if (r
->keepalive
&& r
->headers_in
.msie
&& r
->method
== NGX_HTTP_POST
) {
789 * MSIE may wait for some time if an response for
790 * a POST request was sent over a keepalive connection
796 if (r
->headers_in
.content_length_n
> 0) {
797 r
->lingering_close
= 1;
800 r
->lingering_close
= 0;
803 r
->phase_handler
= 0;
806 cmcf
= ngx_http_get_module_main_conf(r
, ngx_http_core_module
);
807 r
->phase_handler
= cmcf
->phase_engine
.server_rewrite_index
;
810 if (r
->unparsed_uri
.len
) {
811 r
->valid_unparsed_uri
= 1;
814 r
->valid_location
= 1;
821 r
->write_event_handler
= ngx_http_core_run_phases
;
822 ngx_http_core_run_phases(r
);
827 ngx_http_core_run_phases(ngx_http_request_t
*r
)
830 ngx_http_phase_handler_t
*ph
;
831 ngx_http_core_main_conf_t
*cmcf
;
833 cmcf
= ngx_http_get_module_main_conf(r
, ngx_http_core_module
);
835 ph
= cmcf
->phase_engine
.handlers
;
837 while (ph
[r
->phase_handler
].checker
) {
839 rc
= ph
[r
->phase_handler
].checker(r
, &ph
[r
->phase_handler
]);
849 ngx_http_core_generic_phase(ngx_http_request_t
*r
, ngx_http_phase_handler_t
*ph
)
854 * generic phase checker,
855 * used by the post read, server rewrite, rewrite, and pre-access phases
858 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
859 "generic phase: %ui", r
->phase_handler
);
864 r
->phase_handler
= ph
->next
;
868 if (rc
== NGX_DECLINED
) {
873 if (rc
== NGX_AGAIN
|| rc
== NGX_DONE
) {
877 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
879 ngx_http_finalize_request(r
, rc
);
886 ngx_http_core_find_config_phase(ngx_http_request_t
*r
,
887 ngx_http_phase_handler_t
*ph
)
892 ngx_http_core_loc_conf_t
*clcf
;
894 r
->content_handler
= NULL
;
897 rc
= ngx_http_core_find_location(r
);
899 if (rc
== NGX_ERROR
) {
900 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
904 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
906 if (!r
->internal
&& clcf
->internal
) {
907 ngx_http_finalize_request(r
, NGX_HTTP_NOT_FOUND
);
911 ngx_log_debug2(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
912 "using configuration \"%s%V\"",
913 (clcf
->noname
? "*" : (clcf
->exact_match
? "=" : "")),
916 ngx_http_update_location_config(r
);
918 ngx_log_debug2(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
920 r
->headers_in
.content_length_n
, clcf
->client_max_body_size
);
922 if (r
->headers_in
.content_length_n
!= -1
924 && clcf
->client_max_body_size
925 && clcf
->client_max_body_size
< r
->headers_in
.content_length_n
)
927 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
928 "client intended to send too large body: %O bytes",
929 r
->headers_in
.content_length_n
);
931 (void) ngx_http_discard_request_body(r
);
932 ngx_http_finalize_request(r
, NGX_HTTP_REQUEST_ENTITY_TOO_LARGE
);
936 if (rc
== NGX_DONE
) {
937 r
->headers_out
.location
= ngx_list_push(&r
->headers_out
.headers
);
938 if (r
->headers_out
.location
== NULL
) {
939 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
944 * we do not need to set the r->headers_out.location->hash and
945 * r->headers_out.location->key fields
948 if (r
->args
.len
== 0) {
949 r
->headers_out
.location
->value
= clcf
->name
;
952 len
= clcf
->name
.len
+ 1 + r
->args
.len
;
953 p
= ngx_pnalloc(r
->pool
, len
);
956 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
960 r
->headers_out
.location
->value
.len
= len
;
961 r
->headers_out
.location
->value
.data
= p
;
963 p
= ngx_cpymem(p
, clcf
->name
.data
, clcf
->name
.len
);
965 ngx_memcpy(p
, r
->args
.data
, r
->args
.len
);
968 ngx_http_finalize_request(r
, NGX_HTTP_MOVED_PERMANENTLY
);
978 ngx_http_core_post_rewrite_phase(ngx_http_request_t
*r
,
979 ngx_http_phase_handler_t
*ph
)
981 ngx_http_core_srv_conf_t
*cscf
;
983 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
984 "post rewrite phase: %ui", r
->phase_handler
);
986 if (!r
->uri_changed
) {
991 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
992 "uri changes: %d", r
->uri_changes
);
995 * gcc before 3.3 compiles the broken code for
996 * if (r->uri_changes-- == 0)
997 * if the r->uri_changes is defined as
998 * unsigned uri_changes:4
1003 if (r
->uri_changes
== 0) {
1004 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
1005 "rewrite or internal redirection cycle "
1006 "while processing \"%V\"", &r
->uri
);
1008 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
1012 r
->phase_handler
= ph
->next
;
1014 cscf
= ngx_http_get_module_srv_conf(r
, ngx_http_core_module
);
1015 r
->loc_conf
= cscf
->ctx
->loc_conf
;
1022 ngx_http_core_access_phase(ngx_http_request_t
*r
, ngx_http_phase_handler_t
*ph
)
1025 ngx_http_core_loc_conf_t
*clcf
;
1028 r
->phase_handler
= ph
->next
;
1032 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1033 "access phase: %ui", r
->phase_handler
);
1035 rc
= ph
->handler(r
);
1037 if (rc
== NGX_DECLINED
) {
1042 if (rc
== NGX_AGAIN
|| rc
== NGX_DONE
) {
1046 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1048 if (clcf
->satisfy
== NGX_HTTP_SATISFY_ALL
) {
1059 if (r
->headers_out
.www_authenticate
) {
1060 r
->headers_out
.www_authenticate
->hash
= 0;
1063 r
->phase_handler
= ph
->next
;
1067 if (rc
== NGX_HTTP_FORBIDDEN
|| rc
== NGX_HTTP_UNAUTHORIZED
) {
1068 r
->access_code
= rc
;
1075 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
1077 ngx_http_finalize_request(r
, rc
);
1083 ngx_http_core_post_access_phase(ngx_http_request_t
*r
,
1084 ngx_http_phase_handler_t
*ph
)
1086 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1087 "post access phase: %ui", r
->phase_handler
);
1089 if (r
->access_code
) {
1091 if (r
->access_code
== NGX_HTTP_FORBIDDEN
) {
1092 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
1093 "access forbidden by rule");
1096 ngx_http_finalize_request(r
, r
->access_code
);
1106 ngx_http_core_try_files_phase(ngx_http_request_t
*r
,
1107 ngx_http_phase_handler_t
*ph
)
1109 size_t len
, root
, alias
, reserve
, allocated
;
1111 ngx_str_t path
, args
;
1112 ngx_uint_t test_dir
;
1113 ngx_http_try_file_t
*tf
;
1114 ngx_open_file_info_t of
;
1115 ngx_http_script_code_pt code
;
1116 ngx_http_script_engine_t e
;
1117 ngx_http_core_loc_conf_t
*clcf
;
1118 ngx_http_script_len_code_pt lcode
;
1120 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1121 "try files phase: %ui", r
->phase_handler
);
1123 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1125 if (clcf
->try_files
== NULL
) {
1133 /* suppress MSVC warning */
1136 tf
= clcf
->try_files
;
1138 alias
= clcf
->alias
? clcf
->name
.len
: 0;
1143 ngx_memzero(&e
, sizeof(ngx_http_script_engine_t
));
1145 e
.ip
= tf
->lengths
->elts
;
1148 /* 1 is for terminating '\0' as in static names */
1151 while (*(uintptr_t *) e
.ip
) {
1152 lcode
= *(ngx_http_script_len_code_pt
*) e
.ip
;
1160 /* 16 bytes are preallocation */
1161 reserve
= ngx_abs((ssize_t
) (len
- r
->uri
.len
)) + alias
+ 16;
1163 if (reserve
> allocated
) {
1165 /* we just need to allocate path and to copy a root */
1167 if (ngx_http_map_uri_to_path(r
, &path
, &root
, reserve
) == NULL
) {
1168 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
1172 name
= path
.data
+ root
;
1173 allocated
= path
.len
- root
- (r
->uri
.len
- alias
);
1176 if (tf
->values
== NULL
) {
1178 /* tf->name.len includes the terminating '\0' */
1180 ngx_memcpy(name
, tf
->name
.data
, tf
->name
.len
);
1182 path
.len
= (name
+ tf
->name
.len
- 1) - path
.data
;
1185 e
.ip
= tf
->values
->elts
;
1189 while (*(uintptr_t *) e
.ip
) {
1190 code
= *(ngx_http_script_code_pt
*) e
.ip
;
1191 code((ngx_http_script_engine_t
*) &e
);
1194 path
.len
= e
.pos
- path
.data
;
1198 if (alias
&& ngx_strncmp(name
, clcf
->name
.data
, alias
) == 0) {
1199 ngx_memcpy(name
, name
+ alias
, len
- alias
);
1204 test_dir
= tf
->test_dir
;
1208 ngx_log_debug2(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1209 "try to use file: \"%s\" \"%s\"", name
, path
.data
);
1211 if (tf
->lengths
== NULL
&& tf
->name
.len
== 0) {
1214 ngx_http_finalize_request(r
, tf
->code
);
1221 if (path
.data
[0] == '@') {
1222 (void) ngx_http_named_location(r
, &path
);
1225 ngx_http_split_args(r
, &path
, &args
);
1227 (void) ngx_http_internal_redirect(r
, &path
, &args
);
1230 ngx_http_finalize_request(r
, NGX_DONE
);
1234 ngx_memzero(&of
, sizeof(ngx_open_file_info_t
));
1236 of
.directio
= clcf
->directio
;
1237 of
.valid
= clcf
->open_file_cache_valid
;
1238 of
.min_uses
= clcf
->open_file_cache_min_uses
;
1240 of
.errors
= clcf
->open_file_cache_errors
;
1241 of
.events
= clcf
->open_file_cache_events
;
1243 if (ngx_open_cached_file(clcf
->open_file_cache
, &path
, &of
, r
->pool
)
1246 if (of
.err
!= NGX_ENOENT
1247 && of
.err
!= NGX_ENOTDIR
1248 && of
.err
!= NGX_ENAMETOOLONG
)
1250 ngx_log_error(NGX_LOG_CRIT
, r
->connection
->log
, of
.err
,
1251 "%s \"%s\" failed", of
.failed
, path
.data
);
1257 if (of
.is_dir
&& !test_dir
) {
1268 r
->uri
.len
= alias
+ path
.len
;
1269 r
->uri
.data
= ngx_pnalloc(r
->pool
, r
->uri
.len
);
1270 if (r
->uri
.data
== NULL
) {
1271 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
1275 p
= ngx_copy(r
->uri
.data
, clcf
->name
.data
, alias
);
1276 ngx_memcpy(p
, name
, path
.len
);
1279 ngx_http_set_exten(r
);
1281 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1282 "try file uri: \"%V\"", &r
->uri
);
1293 ngx_http_core_content_phase(ngx_http_request_t
*r
,
1294 ngx_http_phase_handler_t
*ph
)
1300 if (r
->content_handler
) {
1301 r
->write_event_handler
= ngx_http_request_empty_handler
;
1302 ngx_http_finalize_request(r
, r
->content_handler(r
));
1306 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1307 "content phase: %ui", r
->phase_handler
);
1309 rc
= ph
->handler(r
);
1311 if (rc
!= NGX_DECLINED
) {
1312 ngx_http_finalize_request(r
, rc
);
1316 /* rc == NGX_DECLINED */
1325 /* no content handler was found */
1327 if (r
->uri
.data
[r
->uri
.len
- 1] == '/' && !r
->zero_in_uri
) {
1329 if (ngx_http_map_uri_to_path(r
, &path
, &root
, 0) != NULL
) {
1330 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
1331 "directory index of \"%s\" is forbidden", path
.data
);
1334 ngx_http_finalize_request(r
, NGX_HTTP_FORBIDDEN
);
1338 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0, "no handler found");
1340 ngx_http_finalize_request(r
, NGX_HTTP_NOT_FOUND
);
1346 ngx_http_update_location_config(ngx_http_request_t
*r
)
1348 ngx_http_core_loc_conf_t
*clcf
;
1350 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1352 if (r
->method
& clcf
->limit_except
) {
1353 r
->loc_conf
= clcf
->limit_except_loc_conf
;
1354 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1358 r
->connection
->log
->file
= clcf
->error_log
->file
;
1360 if (!(r
->connection
->log
->log_level
& NGX_LOG_DEBUG_CONNECTION
)) {
1361 r
->connection
->log
->log_level
= clcf
->error_log
->log_level
;
1365 if ((ngx_io
.flags
& NGX_IO_SENDFILE
) && clcf
->sendfile
) {
1366 r
->connection
->sendfile
= 1;
1369 r
->connection
->sendfile
= 0;
1372 if (clcf
->client_body_in_file_only
) {
1373 r
->request_body_in_file_only
= 1;
1374 r
->request_body_in_persistent_file
= 1;
1375 r
->request_body_in_clean_file
=
1376 clcf
->client_body_in_file_only
== NGX_HTTP_REQUEST_BODY_FILE_CLEAN
;
1377 r
->request_body_file_log_level
= NGX_LOG_NOTICE
;
1380 r
->request_body_file_log_level
= NGX_LOG_WARN
;
1383 r
->request_body_in_single_buf
= clcf
->client_body_in_single_buffer
;
1386 if (clcf
->keepalive_timeout
== 0) {
1389 } else if (r
->connection
->requests
>= clcf
->keepalive_requests
) {
1394 if (!clcf
->tcp_nopush
) {
1395 /* disable TCP_NOPUSH/TCP_CORK use */
1396 r
->connection
->tcp_nopush
= NGX_TCP_NOPUSH_DISABLED
;
1399 if (r
->limit_rate
== 0) {
1400 r
->limit_rate
= clcf
->limit_rate
;
1403 if (clcf
->handler
) {
1404 r
->content_handler
= clcf
->handler
;
1410 * NGX_OK - exact or regex match
1411 * NGX_DONE - auto redirect
1412 * NGX_AGAIN - inclusive match
1413 * NGX_ERROR - regex error
1414 * NGX_DECLINED - no match
1418 ngx_http_core_find_location(ngx_http_request_t
*r
)
1421 ngx_http_core_loc_conf_t
*pclcf
;
1425 ngx_http_core_loc_conf_t
*clcf
, **clcfp
;
1430 pclcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1432 rc
= ngx_http_core_find_static_location(r
, pclcf
->static_locations
);
1434 if (rc
== NGX_AGAIN
) {
1437 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1439 noregex
= clcf
->noregex
;
1442 /* look up nested locations */
1444 rc
= ngx_http_core_find_location(r
);
1447 if (rc
== NGX_OK
|| rc
== NGX_DONE
) {
1451 /* rc == NGX_DECLINED or rc == NGX_AGAIN in nested location */
1455 if (noregex
== 0 && pclcf
->regex_locations
) {
1457 for (clcfp
= pclcf
->regex_locations
; *clcfp
; clcfp
++) {
1459 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1460 "test location: ~ \"%V\"", &(*clcfp
)->name
);
1462 n
= ngx_http_regex_exec(r
, (*clcfp
)->regex
, &r
->uri
);
1465 r
->loc_conf
= (*clcfp
)->loc_conf
;
1467 /* look up nested locations */
1469 rc
= ngx_http_core_find_location(r
);
1471 return (rc
== NGX_ERROR
) ? rc
: NGX_OK
;
1474 if (n
== NGX_DECLINED
) {
1488 * NGX_OK - exact match
1489 * NGX_DONE - auto redirect
1490 * NGX_AGAIN - inclusive match
1491 * NGX_DECLINED - no match
1495 ngx_http_core_find_static_location(ngx_http_request_t
*r
,
1496 ngx_http_location_tree_node_t
*node
)
1513 ngx_log_debug2(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1514 "test location: \"%*s\"", node
->len
, node
->name
);
1516 n
= (len
<= (size_t) node
->len
) ? len
: node
->len
;
1518 rc
= ngx_filename_cmp(uri
, node
->name
, n
);
1521 node
= (rc
< 0) ? node
->left
: node
->right
;
1526 if (len
> (size_t) node
->len
) {
1528 if (node
->inclusive
) {
1530 r
->loc_conf
= node
->inclusive
->loc_conf
;
1547 if (len
== (size_t) node
->len
) {
1549 r
->loc_conf
= (node
->exact
) ? node
->exact
->loc_conf
:
1550 node
->inclusive
->loc_conf
;
1554 /* len < node->len */
1556 if (len
+ 1 == (size_t) node
->len
&& node
->auto_redirect
) {
1558 r
->loc_conf
= (node
->exact
) ? node
->exact
->loc_conf
:
1559 node
->inclusive
->loc_conf
;
1569 ngx_http_test_content_type(ngx_http_request_t
*r
, ngx_hash_t
*types_hash
)
1575 if (r
->headers_out
.content_type
.len
== 0) {
1579 len
= r
->headers_out
.content_type_len
;
1581 if (r
->headers_out
.content_type_lowcase
== NULL
) {
1583 lowcase
= ngx_pnalloc(r
->pool
, len
);
1584 if (lowcase
== NULL
) {
1588 r
->headers_out
.content_type_lowcase
= lowcase
;
1592 for (i
= 0; i
< len
; i
++) {
1593 c
= ngx_tolower(r
->headers_out
.content_type
.data
[i
]);
1594 hash
= ngx_hash(hash
, c
);
1598 r
->headers_out
.content_type_hash
= hash
;
1601 return ngx_hash_find(types_hash
, r
->headers_out
.content_type_hash
,
1602 r
->headers_out
.content_type_lowcase
, len
);
1607 ngx_http_set_content_type(ngx_http_request_t
*r
)
1612 ngx_http_core_loc_conf_t
*clcf
;
1614 if (r
->headers_out
.content_type
.len
) {
1618 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1624 for (i
= 0; i
< r
->exten
.len
; i
++) {
1625 c
= r
->exten
.data
[i
];
1627 if (c
>= 'A' && c
<= 'Z') {
1629 exten
= ngx_pnalloc(r
->pool
, r
->exten
.len
);
1630 if (exten
== NULL
) {
1634 hash
= ngx_hash_strlow(exten
, r
->exten
.data
, r
->exten
.len
);
1636 r
->exten
.data
= exten
;
1641 hash
= ngx_hash(hash
, c
);
1644 type
= ngx_hash_find(&clcf
->types_hash
, hash
,
1645 r
->exten
.data
, r
->exten
.len
);
1648 r
->headers_out
.content_type_len
= type
->len
;
1649 r
->headers_out
.content_type
= *type
;
1655 r
->headers_out
.content_type_len
= clcf
->default_type
.len
;
1656 r
->headers_out
.content_type
= clcf
->default_type
;
1663 ngx_http_set_exten(ngx_http_request_t
*r
)
1668 r
->exten
.data
= NULL
;
1670 for (i
= r
->uri
.len
- 1; i
> 1; i
--) {
1671 if (r
->uri
.data
[i
] == '.' && r
->uri
.data
[i
- 1] != '/') {
1673 r
->exten
.len
= r
->uri
.len
- i
- 1;
1674 r
->exten
.data
= &r
->uri
.data
[i
+ 1];
1678 } else if (r
->uri
.data
[i
] == '/') {
1688 ngx_http_send_header(ngx_http_request_t
*r
)
1690 if (r
->err_status
) {
1691 r
->headers_out
.status
= r
->err_status
;
1692 r
->headers_out
.status_line
.len
= 0;
1695 return ngx_http_top_header_filter(r
);
1700 ngx_http_output_filter(ngx_http_request_t
*r
, ngx_chain_t
*in
)
1703 ngx_connection_t
*c
;
1707 ngx_log_debug2(NGX_LOG_DEBUG_HTTP
, c
->log
, 0,
1708 "http output filter \"%V?%V\"", &r
->uri
, &r
->args
);
1710 rc
= ngx_http_top_body_filter(r
, in
);
1712 if (rc
== NGX_ERROR
) {
1713 /* NGX_ERROR may be returned by any filter */
1722 ngx_http_map_uri_to_path(ngx_http_request_t
*r
, ngx_str_t
*path
,
1723 size_t *root_length
, size_t reserved
)
1727 ngx_http_core_loc_conf_t
*clcf
;
1729 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1731 alias
= clcf
->alias
? clcf
->name
.len
: 0;
1733 if (alias
&& !r
->valid_location
) {
1734 ngx_log_error(NGX_LOG_ALERT
, r
->connection
->log
, 0,
1735 "\"alias\" could not be used in location \"%V\" "
1736 "where URI was rewritten", &clcf
->name
);
1740 if (clcf
->root_lengths
== NULL
) {
1742 *root_length
= clcf
->root
.len
;
1744 path
->len
= clcf
->root
.len
+ reserved
+ r
->uri
.len
- alias
+ 1;
1746 path
->data
= ngx_pnalloc(r
->pool
, path
->len
);
1747 if (path
->data
== NULL
) {
1751 last
= ngx_copy(path
->data
, clcf
->root
.data
, clcf
->root
.len
);
1756 ngx_uint_t captures
;
1758 captures
= alias
&& clcf
->regex
;
1759 reserved
+= captures
? 1 : r
->uri
.len
- alias
+ 1;
1761 reserved
+= r
->uri
.len
- alias
+ 1;
1764 if (ngx_http_script_run(r
, path
, clcf
->root_lengths
->elts
, reserved
,
1765 clcf
->root_values
->elts
)
1771 if (ngx_conf_full_name((ngx_cycle_t
*) ngx_cycle
, path
, 0) != NGX_OK
) {
1775 *root_length
= path
->len
- reserved
;
1776 last
= path
->data
+ *root_length
;
1786 last
= ngx_cpystrn(last
, r
->uri
.data
+ alias
, r
->uri
.len
- alias
+ 1);
1793 ngx_http_auth_basic_user(ngx_http_request_t
*r
)
1795 ngx_str_t auth
, encoded
;
1798 if (r
->headers_in
.user
.len
== 0 && r
->headers_in
.user
.data
!= NULL
) {
1799 return NGX_DECLINED
;
1802 if (r
->headers_in
.authorization
== NULL
) {
1803 r
->headers_in
.user
.data
= (u_char
*) "";
1804 return NGX_DECLINED
;
1807 encoded
= r
->headers_in
.authorization
->value
;
1809 if (encoded
.len
< sizeof("Basic ") - 1
1810 || ngx_strncasecmp(encoded
.data
, (u_char
*) "Basic ",
1811 sizeof("Basic ") - 1)
1814 r
->headers_in
.user
.data
= (u_char
*) "";
1815 return NGX_DECLINED
;
1818 encoded
.len
-= sizeof("Basic ") - 1;
1819 encoded
.data
+= sizeof("Basic ") - 1;
1821 while (encoded
.len
&& encoded
.data
[0] == ' ') {
1826 if (encoded
.len
== 0) {
1827 r
->headers_in
.user
.data
= (u_char
*) "";
1828 return NGX_DECLINED
;
1831 auth
.len
= ngx_base64_decoded_length(encoded
.len
);
1832 auth
.data
= ngx_pnalloc(r
->pool
, auth
.len
+ 1);
1833 if (auth
.data
== NULL
) {
1837 if (ngx_decode_base64(&auth
, &encoded
) != NGX_OK
) {
1838 r
->headers_in
.user
.data
= (u_char
*) "";
1839 return NGX_DECLINED
;
1842 auth
.data
[auth
.len
] = '\0';
1844 for (len
= 0; len
< auth
.len
; len
++) {
1845 if (auth
.data
[len
] == ':') {
1850 if (len
== 0 || len
== auth
.len
) {
1851 r
->headers_in
.user
.data
= (u_char
*) "";
1852 return NGX_DECLINED
;
1855 r
->headers_in
.user
.len
= len
;
1856 r
->headers_in
.user
.data
= auth
.data
;
1857 r
->headers_in
.passwd
.len
= auth
.len
- len
- 1;
1858 r
->headers_in
.passwd
.data
= &auth
.data
[len
+ 1];
1867 ngx_http_gzip_ok(ngx_http_request_t
*r
)
1869 time_t date
, expires
;
1872 ngx_table_elt_t
*e
, *d
;
1873 ngx_http_core_loc_conf_t
*clcf
;
1878 || r
->headers_in
.accept_encoding
== NULL
1879 || ngx_strcasestrn(r
->headers_in
.accept_encoding
->value
.data
,
1884 * if the URL (without the "http://" prefix) is longer than 253 bytes,
1885 * then MSIE 4.x can not handle the compressed stream - it waits
1886 * too long, hangs up or crashes
1889 || (r
->headers_in
.msie4
&& r
->unparsed_uri
.len
> 200))
1891 return NGX_DECLINED
;
1894 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1896 if (r
->headers_in
.msie6
&& clcf
->gzip_disable_msie6
) {
1897 return NGX_DECLINED
;
1900 if (r
->http_version
< clcf
->gzip_http_version
) {
1901 return NGX_DECLINED
;
1904 if (r
->headers_in
.via
== NULL
) {
1908 p
= clcf
->gzip_proxied
;
1910 if (p
& NGX_HTTP_GZIP_PROXIED_OFF
) {
1911 return NGX_DECLINED
;
1914 if (p
& NGX_HTTP_GZIP_PROXIED_ANY
) {
1918 if (r
->headers_in
.authorization
&& (p
& NGX_HTTP_GZIP_PROXIED_AUTH
)) {
1922 e
= r
->headers_out
.expires
;
1926 if (!(p
& NGX_HTTP_GZIP_PROXIED_EXPIRED
)) {
1927 return NGX_DECLINED
;
1930 expires
= ngx_http_parse_time(e
->value
.data
, e
->value
.len
);
1931 if (expires
== NGX_ERROR
) {
1932 return NGX_DECLINED
;
1935 d
= r
->headers_out
.date
;
1938 date
= ngx_http_parse_time(d
->value
.data
, d
->value
.len
);
1939 if (date
== NGX_ERROR
) {
1940 return NGX_DECLINED
;
1947 if (expires
< date
) {
1951 return NGX_DECLINED
;
1954 cc
= &r
->headers_out
.cache_control
;
1958 if ((p
& NGX_HTTP_GZIP_PROXIED_NO_CACHE
)
1959 && ngx_http_parse_multi_header_lines(cc
, &ngx_http_gzip_no_cache
,
1966 if ((p
& NGX_HTTP_GZIP_PROXIED_NO_STORE
)
1967 && ngx_http_parse_multi_header_lines(cc
, &ngx_http_gzip_no_store
,
1974 if ((p
& NGX_HTTP_GZIP_PROXIED_PRIVATE
)
1975 && ngx_http_parse_multi_header_lines(cc
, &ngx_http_gzip_private
,
1982 return NGX_DECLINED
;
1985 if ((p
& NGX_HTTP_GZIP_PROXIED_NO_LM
) && r
->headers_out
.last_modified
) {
1986 return NGX_DECLINED
;
1989 if ((p
& NGX_HTTP_GZIP_PROXIED_NO_ETAG
) && r
->headers_out
.etag
) {
1990 return NGX_DECLINED
;
1997 if (clcf
->gzip_disable
&& r
->headers_in
.user_agent
) {
1999 if (ngx_regex_exec_array(clcf
->gzip_disable
,
2000 &r
->headers_in
.user_agent
->value
,
2004 return NGX_DECLINED
;
2019 ngx_http_subrequest(ngx_http_request_t
*r
,
2020 ngx_str_t
*uri
, ngx_str_t
*args
, ngx_http_request_t
**psr
,
2021 ngx_http_post_subrequest_t
*ps
, ngx_uint_t flags
)
2023 ngx_connection_t
*c
;
2024 ngx_http_request_t
*sr
;
2025 ngx_http_core_srv_conf_t
*cscf
;
2026 ngx_http_postponed_request_t
*pr
, *p
;
2028 r
->main
->subrequests
--;
2030 if (r
->main
->subrequests
== 0) {
2031 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
2032 "subrequests cycle while processing \"%V\"", uri
);
2033 r
->main
->subrequests
= 1;
2037 sr
= ngx_pcalloc(r
->pool
, sizeof(ngx_http_request_t
));
2042 sr
->signature
= NGX_HTTP_MODULE
;
2047 sr
->ctx
= ngx_pcalloc(r
->pool
, sizeof(void *) * ngx_http_max_module
);
2048 if (sr
->ctx
== NULL
) {
2052 if (ngx_list_init(&sr
->headers_out
.headers
, r
->pool
, 20,
2053 sizeof(ngx_table_elt_t
))
2059 cscf
= ngx_http_get_module_srv_conf(r
, ngx_http_core_module
);
2060 sr
->main_conf
= cscf
->ctx
->main_conf
;
2061 sr
->srv_conf
= cscf
->ctx
->srv_conf
;
2062 sr
->loc_conf
= cscf
->ctx
->loc_conf
;
2066 sr
->headers_in
= r
->headers_in
;
2068 ngx_http_clear_content_length(sr
);
2069 ngx_http_clear_accept_ranges(sr
);
2070 ngx_http_clear_last_modified(sr
);
2072 sr
->request_body
= r
->request_body
;
2074 sr
->method
= NGX_HTTP_GET
;
2075 sr
->http_version
= r
->http_version
;
2077 sr
->request_line
= r
->request_line
;
2084 ngx_log_debug2(NGX_LOG_DEBUG_HTTP
, c
->log
, 0,
2085 "http subrequest \"%V?%V\"", uri
, &sr
->args
);
2087 sr
->zero_in_uri
= (flags
& NGX_HTTP_ZERO_IN_URI
) != 0;
2088 sr
->subrequest_in_memory
= (flags
& NGX_HTTP_SUBREQUEST_IN_MEMORY
) != 0;
2089 sr
->waited
= (flags
& NGX_HTTP_SUBREQUEST_WAITED
) != 0;
2091 sr
->unparsed_uri
= r
->unparsed_uri
;
2092 sr
->method_name
= ngx_http_core_get_method
;
2093 sr
->http_protocol
= r
->http_protocol
;
2095 ngx_http_set_exten(sr
);
2099 sr
->post_subrequest
= ps
;
2100 sr
->read_event_handler
= ngx_http_request_empty_handler
;
2101 sr
->write_event_handler
= ngx_http_handler
;
2103 if (c
->data
== r
&& r
->postponed
== NULL
) {
2107 sr
->variables
= r
->variables
;
2109 sr
->log_handler
= r
->log_handler
;
2111 pr
= ngx_palloc(r
->pool
, sizeof(ngx_http_postponed_request_t
));
2121 for (p
= r
->postponed
; p
->next
; p
= p
->next
) { /* void */ }
2130 sr
->discard_body
= r
->discard_body
;
2131 sr
->expect_tested
= 1;
2132 sr
->main_filter_need_in_memory
= r
->main_filter_need_in_memory
;
2134 sr
->uri_changes
= NGX_HTTP_MAX_URI_CHANGES
+ 1;
2136 r
->main
->subrequests
++;
2141 return ngx_http_post_request(sr
, NULL
);
2146 ngx_http_internal_redirect(ngx_http_request_t
*r
,
2147 ngx_str_t
*uri
, ngx_str_t
*args
)
2149 ngx_http_core_srv_conf_t
*cscf
;
2153 if (r
->uri_changes
== 0) {
2154 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
2155 "rewrite or internal redirection cycle "
2156 "while internal redirect to \"%V\"", uri
);
2159 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
2170 r
->args
.data
= NULL
;
2173 ngx_log_debug2(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
2174 "internal redirect: \"%V?%V\"", uri
, &r
->args
);
2176 ngx_http_set_exten(r
);
2178 /* clear the modules contexts */
2179 ngx_memzero(r
->ctx
, sizeof(void *) * ngx_http_max_module
);
2181 cscf
= ngx_http_get_module_srv_conf(r
, ngx_http_core_module
);
2182 r
->loc_conf
= cscf
->ctx
->loc_conf
;
2184 ngx_http_update_location_config(r
);
2186 #if (NGX_HTTP_CACHE)
2193 ngx_http_handler(r
);
2200 ngx_http_named_location(ngx_http_request_t
*r
, ngx_str_t
*name
)
2202 ngx_http_core_srv_conf_t
*cscf
;
2203 ngx_http_core_loc_conf_t
**clcfp
;
2204 ngx_http_core_main_conf_t
*cmcf
;
2208 cscf
= ngx_http_get_module_srv_conf(r
, ngx_http_core_module
);
2210 if (cscf
->named_locations
) {
2212 for (clcfp
= cscf
->named_locations
; *clcfp
; clcfp
++) {
2214 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
2215 "test location: \"%V\"", &(*clcfp
)->name
);
2217 if (name
->len
!= (*clcfp
)->name
.len
2218 || ngx_strncmp(name
->data
, (*clcfp
)->name
.data
, name
->len
) != 0)
2223 ngx_log_debug3(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
2224 "using location: %V \"%V?%V\"",
2225 name
, &r
->uri
, &r
->args
);
2228 r
->content_handler
= NULL
;
2229 r
->loc_conf
= (*clcfp
)->loc_conf
;
2231 ngx_http_update_location_config(r
);
2233 cmcf
= ngx_http_get_module_main_conf(r
, ngx_http_core_module
);
2235 r
->phase_handler
= cmcf
->phase_engine
.location_rewrite_index
;
2237 ngx_http_core_run_phases(r
);
2243 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
2244 "could not find named location \"%V\"", name
);
2246 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
2252 ngx_http_cleanup_t
*
2253 ngx_http_cleanup_add(ngx_http_request_t
*r
, size_t size
)
2255 ngx_http_cleanup_t
*cln
;
2259 cln
= ngx_palloc(r
->pool
, sizeof(ngx_http_cleanup_t
));
2265 cln
->data
= ngx_palloc(r
->pool
, size
);
2266 if (cln
->data
== NULL
) {
2274 cln
->handler
= NULL
;
2275 cln
->next
= r
->cleanup
;
2279 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
2280 "http cleanup add: %p", cln
);
2287 ngx_http_core_server(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *dummy
)
2293 ngx_http_module_t
*module
;
2294 ngx_http_conf_ctx_t
*ctx
, *http_ctx
;
2295 ngx_http_core_srv_conf_t
*cscf
, **cscfp
;
2296 ngx_http_core_main_conf_t
*cmcf
;
2298 ctx
= ngx_pcalloc(cf
->pool
, sizeof(ngx_http_conf_ctx_t
));
2300 return NGX_CONF_ERROR
;
2304 ctx
->main_conf
= http_ctx
->main_conf
;
2306 /* the server{}'s srv_conf */
2308 ctx
->srv_conf
= ngx_pcalloc(cf
->pool
, sizeof(void *) * ngx_http_max_module
);
2309 if (ctx
->srv_conf
== NULL
) {
2310 return NGX_CONF_ERROR
;
2313 /* the server{}'s loc_conf */
2315 ctx
->loc_conf
= ngx_pcalloc(cf
->pool
, sizeof(void *) * ngx_http_max_module
);
2316 if (ctx
->loc_conf
== NULL
) {
2317 return NGX_CONF_ERROR
;
2320 for (i
= 0; ngx_modules
[i
]; i
++) {
2321 if (ngx_modules
[i
]->type
!= NGX_HTTP_MODULE
) {
2325 module
= ngx_modules
[i
]->ctx
;
2327 if (module
->create_srv_conf
) {
2328 mconf
= module
->create_srv_conf(cf
);
2329 if (mconf
== NULL
) {
2330 return NGX_CONF_ERROR
;
2333 ctx
->srv_conf
[ngx_modules
[i
]->ctx_index
] = mconf
;
2336 if (module
->create_loc_conf
) {
2337 mconf
= module
->create_loc_conf(cf
);
2338 if (mconf
== NULL
) {
2339 return NGX_CONF_ERROR
;
2342 ctx
->loc_conf
[ngx_modules
[i
]->ctx_index
] = mconf
;
2347 /* the server configuration context */
2349 cscf
= ctx
->srv_conf
[ngx_http_core_module
.ctx_index
];
2353 cmcf
= ctx
->main_conf
[ngx_http_core_module
.ctx_index
];
2355 cscfp
= ngx_array_push(&cmcf
->servers
);
2356 if (cscfp
== NULL
) {
2357 return NGX_CONF_ERROR
;
2363 /* parse inside server{} */
2367 cf
->cmd_type
= NGX_HTTP_SRV_CONF
;
2369 rv
= ngx_conf_parse(cf
, NULL
);
2378 ngx_http_core_location(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *dummy
)
2383 ngx_str_t
*value
, *name
;
2386 ngx_http_module_t
*module
;
2387 ngx_http_conf_ctx_t
*ctx
, *pctx
;
2388 ngx_http_core_loc_conf_t
*clcf
, *pclcf
;
2390 ctx
= ngx_pcalloc(cf
->pool
, sizeof(ngx_http_conf_ctx_t
));
2392 return NGX_CONF_ERROR
;
2396 ctx
->main_conf
= pctx
->main_conf
;
2397 ctx
->srv_conf
= pctx
->srv_conf
;
2399 ctx
->loc_conf
= ngx_pcalloc(cf
->pool
, sizeof(void *) * ngx_http_max_module
);
2400 if (ctx
->loc_conf
== NULL
) {
2401 return NGX_CONF_ERROR
;
2404 for (i
= 0; ngx_modules
[i
]; i
++) {
2405 if (ngx_modules
[i
]->type
!= NGX_HTTP_MODULE
) {
2409 module
= ngx_modules
[i
]->ctx
;
2411 if (module
->create_loc_conf
) {
2412 ctx
->loc_conf
[ngx_modules
[i
]->ctx_index
] =
2413 module
->create_loc_conf(cf
);
2414 if (ctx
->loc_conf
[ngx_modules
[i
]->ctx_index
] == NULL
) {
2415 return NGX_CONF_ERROR
;
2420 clcf
= ctx
->loc_conf
[ngx_http_core_module
.ctx_index
];
2421 clcf
->loc_conf
= ctx
->loc_conf
;
2423 value
= cf
->args
->elts
;
2425 if (cf
->args
->nelts
== 3) {
2428 mod
= value
[1].data
;
2431 if (len
== 1 && mod
[0] == '=') {
2434 clcf
->exact_match
= 1;
2436 } else if (len
== 2 && mod
[0] == '^' && mod
[1] == '~') {
2441 } else if (len
== 1 && mod
[0] == '~') {
2443 if (ngx_http_core_regex_location(cf
, clcf
, name
, 0) != NGX_OK
) {
2444 return NGX_CONF_ERROR
;
2447 } else if (len
== 2 && mod
[0] == '~' && mod
[1] == '*') {
2449 if (ngx_http_core_regex_location(cf
, clcf
, name
, 1) != NGX_OK
) {
2450 return NGX_CONF_ERROR
;
2454 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
2455 "invalid location modifier \"%V\"", &value
[1]);
2456 return NGX_CONF_ERROR
;
2463 if (name
->data
[0] == '=') {
2465 clcf
->name
.len
= name
->len
- 1;
2466 clcf
->name
.data
= name
->data
+ 1;
2467 clcf
->exact_match
= 1;
2469 } else if (name
->data
[0] == '^' && name
->data
[1] == '~') {
2471 clcf
->name
.len
= name
->len
- 2;
2472 clcf
->name
.data
= name
->data
+ 2;
2475 } else if (name
->data
[0] == '~') {
2480 if (name
->data
[0] == '*') {
2485 if (ngx_http_core_regex_location(cf
, clcf
, name
, 1) != NGX_OK
) {
2486 return NGX_CONF_ERROR
;
2490 if (ngx_http_core_regex_location(cf
, clcf
, name
, 0) != NGX_OK
) {
2491 return NGX_CONF_ERROR
;
2499 if (name
->data
[0] == '@') {
2505 pclcf
= pctx
->loc_conf
[ngx_http_core_module
.ctx_index
];
2507 if (pclcf
->name
.len
) {
2509 /* nested location */
2512 clcf
->prev_location
= pclcf
;
2515 if (pclcf
->exact_match
) {
2516 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
2517 "location \"%V\" could not be inside "
2518 "the exact location \"%V\"",
2519 &clcf
->name
, &pclcf
->name
);
2520 return NGX_CONF_ERROR
;
2524 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
2525 "location \"%V\" could not be inside "
2526 "the named location \"%V\"",
2527 &clcf
->name
, &pclcf
->name
);
2528 return NGX_CONF_ERROR
;
2532 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
2533 "named location \"%V\" must be "
2534 "on server level only",
2536 return NGX_CONF_ERROR
;
2539 len
= pclcf
->name
.len
;
2542 if (clcf
->regex
== NULL
2543 && ngx_strncmp(clcf
->name
.data
, pclcf
->name
.data
, len
) != 0)
2545 if (ngx_strncmp(clcf
->name
.data
, pclcf
->name
.data
, len
) != 0)
2548 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
2549 "location \"%V\" is outside location \"%V\"",
2550 &clcf
->name
, &pclcf
->name
);
2551 return NGX_CONF_ERROR
;
2555 if (ngx_http_add_location(cf
, &pclcf
->locations
, clcf
) != NGX_OK
) {
2556 return NGX_CONF_ERROR
;
2561 cf
->cmd_type
= NGX_HTTP_LOC_CONF
;
2563 rv
= ngx_conf_parse(cf
, NULL
);
2572 ngx_http_core_regex_location(ngx_conf_t
*cf
, ngx_http_core_loc_conf_t
*clcf
,
2573 ngx_str_t
*regex
, ngx_uint_t caseless
)
2576 ngx_regex_compile_t rc
;
2577 u_char errstr
[NGX_MAX_CONF_ERRSTR
];
2579 ngx_memzero(&rc
, sizeof(ngx_regex_compile_t
));
2581 rc
.pattern
= *regex
;
2582 rc
.err
.len
= NGX_MAX_CONF_ERRSTR
;
2583 rc
.err
.data
= errstr
;
2585 #if (NGX_HAVE_CASELESS_FILESYSTEM)
2586 rc
.options
= NGX_REGEX_CASELESS
;
2589 clcf
->regex
= ngx_http_regex_compile(cf
, &rc
);
2590 if (clcf
->regex
== NULL
) {
2594 clcf
->name
= *regex
;
2600 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
2601 "the using of the regex \"%V\" requires PCRE library",
2610 ngx_http_core_types(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
2612 ngx_http_core_loc_conf_t
*clcf
= conf
;
2617 if (clcf
->types
== NULL
) {
2618 clcf
->types
= ngx_array_create(cf
->pool
, 64, sizeof(ngx_hash_key_t
));
2619 if (clcf
->types
== NULL
) {
2620 return NGX_CONF_ERROR
;
2625 cf
->handler
= ngx_http_core_type
;
2626 cf
->handler_conf
= conf
;
2628 rv
= ngx_conf_parse(cf
, NULL
);
2637 ngx_http_core_type(ngx_conf_t
*cf
, ngx_command_t
*dummy
, void *conf
)
2639 ngx_http_core_loc_conf_t
*clcf
= conf
;
2641 ngx_str_t
*value
, *content_type
, *old
, file
;
2642 ngx_uint_t i
, n
, hash
;
2643 ngx_hash_key_t
*type
;
2645 value
= cf
->args
->elts
;
2647 if (ngx_strcmp(value
[0].data
, "include") == 0) {
2650 if (ngx_conf_full_name(cf
->cycle
, &file
, 1) != NGX_OK
) {
2651 return NGX_CONF_ERROR
;
2654 ngx_log_debug1(NGX_LOG_DEBUG_CORE
, cf
->log
, 0, "include %s", file
.data
);
2656 return ngx_conf_parse(cf
, &file
);
2659 content_type
= ngx_palloc(cf
->pool
, sizeof(ngx_str_t
));
2660 if (content_type
== NULL
) {
2661 return NGX_CONF_ERROR
;
2664 *content_type
= value
[0];
2666 for (i
= 1; i
< cf
->args
->nelts
; i
++) {
2668 hash
= ngx_hash_strlow(value
[i
].data
, value
[i
].data
, value
[i
].len
);
2670 type
= clcf
->types
->elts
;
2671 for (n
= 0; n
< clcf
->types
->nelts
; n
++) {
2672 if (ngx_strcmp(value
[i
].data
, type
[n
].key
.data
) == 0) {
2673 old
= type
[n
].value
;
2674 type
[n
].value
= content_type
;
2676 ngx_conf_log_error(NGX_LOG_WARN
, cf
, 0,
2677 "duplicate extention \"%V\", "
2678 "content type: \"%V\", "
2679 "old content type: \"%V\"",
2680 &value
[i
], content_type
, old
);
2686 type
= ngx_array_push(clcf
->types
);
2688 return NGX_CONF_ERROR
;
2691 type
->key
= value
[i
];
2692 type
->key_hash
= hash
;
2693 type
->value
= content_type
;
2701 ngx_http_core_preconfiguration(ngx_conf_t
*cf
)
2703 return ngx_http_variables_add_core_vars(cf
);
2708 ngx_http_core_create_main_conf(ngx_conf_t
*cf
)
2710 ngx_http_core_main_conf_t
*cmcf
;
2712 cmcf
= ngx_pcalloc(cf
->pool
, sizeof(ngx_http_core_main_conf_t
));
2717 if (ngx_array_init(&cmcf
->servers
, cf
->pool
, 4,
2718 sizeof(ngx_http_core_srv_conf_t
*))
2724 cmcf
->server_names_hash_max_size
= NGX_CONF_UNSET_UINT
;
2725 cmcf
->server_names_hash_bucket_size
= NGX_CONF_UNSET_UINT
;
2727 cmcf
->variables_hash_max_size
= NGX_CONF_UNSET_UINT
;
2728 cmcf
->variables_hash_bucket_size
= NGX_CONF_UNSET_UINT
;
2735 ngx_http_core_init_main_conf(ngx_conf_t
*cf
, void *conf
)
2737 ngx_http_core_main_conf_t
*cmcf
= conf
;
2739 if (cmcf
->server_names_hash_max_size
== NGX_CONF_UNSET_UINT
) {
2740 cmcf
->server_names_hash_max_size
= 512;
2743 if (cmcf
->server_names_hash_bucket_size
== NGX_CONF_UNSET_UINT
) {
2744 cmcf
->server_names_hash_bucket_size
= ngx_cacheline_size
;
2747 cmcf
->server_names_hash_bucket_size
=
2748 ngx_align(cmcf
->server_names_hash_bucket_size
, ngx_cacheline_size
);
2751 if (cmcf
->variables_hash_max_size
== NGX_CONF_UNSET_UINT
) {
2752 cmcf
->variables_hash_max_size
= 512;
2755 if (cmcf
->variables_hash_bucket_size
== NGX_CONF_UNSET_UINT
) {
2756 cmcf
->variables_hash_bucket_size
= 64;
2759 cmcf
->variables_hash_bucket_size
=
2760 ngx_align(cmcf
->variables_hash_bucket_size
, ngx_cacheline_size
);
2762 if (cmcf
->ncaptures
) {
2763 cmcf
->ncaptures
= (cmcf
->ncaptures
+ 1) * 3;
2771 ngx_http_core_create_srv_conf(ngx_conf_t
*cf
)
2773 ngx_http_core_srv_conf_t
*cscf
;
2775 cscf
= ngx_pcalloc(cf
->pool
, sizeof(ngx_http_core_srv_conf_t
));
2781 * set by ngx_pcalloc():
2783 * conf->client_large_buffers.num = 0;
2786 if (ngx_array_init(&cscf
->server_names
, cf
->temp_pool
, 4,
2787 sizeof(ngx_http_server_name_t
))
2793 cscf
->connection_pool_size
= NGX_CONF_UNSET_SIZE
;
2794 cscf
->request_pool_size
= NGX_CONF_UNSET_SIZE
;
2795 cscf
->client_header_timeout
= NGX_CONF_UNSET_MSEC
;
2796 cscf
->client_header_buffer_size
= NGX_CONF_UNSET_SIZE
;
2797 cscf
->ignore_invalid_headers
= NGX_CONF_UNSET
;
2798 cscf
->merge_slashes
= NGX_CONF_UNSET
;
2799 cscf
->underscores_in_headers
= NGX_CONF_UNSET
;
2806 ngx_http_core_merge_srv_conf(ngx_conf_t
*cf
, void *parent
, void *child
)
2808 ngx_http_core_srv_conf_t
*prev
= parent
;
2809 ngx_http_core_srv_conf_t
*conf
= child
;
2811 struct sockaddr_in
*sin
;
2812 ngx_http_listen_opt_t lsopt
;
2813 ngx_http_server_name_t
*sn
;
2815 /* TODO: it does not merge, it inits only */
2817 ngx_conf_merge_size_value(conf
->connection_pool_size
,
2818 prev
->connection_pool_size
, 256);
2819 ngx_conf_merge_size_value(conf
->request_pool_size
,
2820 prev
->request_pool_size
, 4096);
2821 ngx_conf_merge_msec_value(conf
->client_header_timeout
,
2822 prev
->client_header_timeout
, 60000);
2823 ngx_conf_merge_size_value(conf
->client_header_buffer_size
,
2824 prev
->client_header_buffer_size
, 1024);
2825 ngx_conf_merge_bufs_value(conf
->large_client_header_buffers
,
2826 prev
->large_client_header_buffers
,
2829 if (conf
->large_client_header_buffers
.size
< conf
->connection_pool_size
) {
2830 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
2831 "the \"large_client_header_buffers\" size must be "
2832 "equal to or bigger than \"connection_pool_size\"");
2833 return NGX_CONF_ERROR
;
2836 ngx_conf_merge_value(conf
->ignore_invalid_headers
,
2837 prev
->ignore_invalid_headers
, 1);
2839 ngx_conf_merge_value(conf
->merge_slashes
, prev
->merge_slashes
, 1);
2841 ngx_conf_merge_value(conf
->underscores_in_headers
,
2842 prev
->underscores_in_headers
, 0);
2844 if (!conf
->listen
) {
2845 ngx_memzero(&lsopt
, sizeof(ngx_http_listen_opt_t
));
2847 sin
= (struct sockaddr_in
*) &lsopt
.sockaddr
;
2849 sin
->sin_family
= AF_INET
;
2851 sin
->sin_port
= htons(80);
2853 sin
->sin_port
= htons((getuid() == 0) ? 80 : 8000);
2855 sin
->sin_addr
.s_addr
= INADDR_ANY
;
2857 lsopt
.socklen
= sizeof(struct sockaddr_in
);
2859 lsopt
.backlog
= NGX_LISTEN_BACKLOG
;
2864 (void) ngx_sock_ntop((struct sockaddr
*) &lsopt
.sockaddr
, lsopt
.addr
,
2865 NGX_SOCKADDR_STRLEN
, 1);
2867 if (ngx_http_add_listen(cf
, conf
, &lsopt
) == NGX_OK
) {
2872 if (conf
->server_name
.data
== NULL
) {
2873 conf
->server_name
= cf
->cycle
->hostname
;
2875 sn
= ngx_array_push(&conf
->server_names
);
2877 return NGX_CONF_ERROR
;
2884 sn
->name
.len
= conf
->server_name
.len
;
2885 sn
->name
.data
= conf
->server_name
.data
;
2893 ngx_http_core_create_loc_conf(ngx_conf_t
*cf
)
2895 ngx_http_core_loc_conf_t
*clcf
;
2897 clcf
= ngx_pcalloc(cf
->pool
, sizeof(ngx_http_core_loc_conf_t
));
2903 * set by ngx_pcalloc():
2905 * clcf->root = { 0, NULL };
2906 * clcf->limit_except = 0;
2907 * clcf->post_action = { 0, NULL };
2908 * clcf->types = NULL;
2909 * clcf->default_type = { 0, NULL };
2910 * clcf->error_log = NULL;
2911 * clcf->error_pages = NULL;
2912 * clcf->try_files = NULL;
2913 * clcf->client_body_path = NULL;
2914 * clcf->regex = NULL;
2915 * clcf->exact_match = 0;
2916 * clcf->auto_redirect = 0;
2918 * clcf->gzip_proxied = 0;
2921 clcf
->client_max_body_size
= NGX_CONF_UNSET
;
2922 clcf
->client_body_buffer_size
= NGX_CONF_UNSET_SIZE
;
2923 clcf
->client_body_timeout
= NGX_CONF_UNSET_MSEC
;
2924 clcf
->satisfy
= NGX_CONF_UNSET_UINT
;
2925 clcf
->if_modified_since
= NGX_CONF_UNSET_UINT
;
2926 clcf
->client_body_in_file_only
= NGX_CONF_UNSET_UINT
;
2927 clcf
->client_body_in_single_buffer
= NGX_CONF_UNSET
;
2928 clcf
->internal
= NGX_CONF_UNSET
;
2929 clcf
->sendfile
= NGX_CONF_UNSET
;
2930 clcf
->sendfile_max_chunk
= NGX_CONF_UNSET_SIZE
;
2931 #if (NGX_HAVE_FILE_AIO)
2932 clcf
->aio
= NGX_CONF_UNSET
;
2934 clcf
->read_ahead
= NGX_CONF_UNSET_SIZE
;
2935 clcf
->directio
= NGX_CONF_UNSET
;
2936 clcf
->directio_alignment
= NGX_CONF_UNSET
;
2937 clcf
->tcp_nopush
= NGX_CONF_UNSET
;
2938 clcf
->tcp_nodelay
= NGX_CONF_UNSET
;
2939 clcf
->send_timeout
= NGX_CONF_UNSET_MSEC
;
2940 clcf
->send_lowat
= NGX_CONF_UNSET_SIZE
;
2941 clcf
->postpone_output
= NGX_CONF_UNSET_SIZE
;
2942 clcf
->limit_rate
= NGX_CONF_UNSET_SIZE
;
2943 clcf
->limit_rate_after
= NGX_CONF_UNSET_SIZE
;
2944 clcf
->keepalive_timeout
= NGX_CONF_UNSET_MSEC
;
2945 clcf
->keepalive_header
= NGX_CONF_UNSET
;
2946 clcf
->keepalive_requests
= NGX_CONF_UNSET_UINT
;
2947 clcf
->lingering_time
= NGX_CONF_UNSET_MSEC
;
2948 clcf
->lingering_timeout
= NGX_CONF_UNSET_MSEC
;
2949 clcf
->resolver_timeout
= NGX_CONF_UNSET_MSEC
;
2950 clcf
->reset_timedout_connection
= NGX_CONF_UNSET
;
2951 clcf
->server_name_in_redirect
= NGX_CONF_UNSET
;
2952 clcf
->port_in_redirect
= NGX_CONF_UNSET
;
2953 clcf
->msie_padding
= NGX_CONF_UNSET
;
2954 clcf
->msie_refresh
= NGX_CONF_UNSET
;
2955 clcf
->log_not_found
= NGX_CONF_UNSET
;
2956 clcf
->log_subrequest
= NGX_CONF_UNSET
;
2957 clcf
->recursive_error_pages
= NGX_CONF_UNSET
;
2958 clcf
->server_tokens
= NGX_CONF_UNSET
;
2959 clcf
->types_hash_max_size
= NGX_CONF_UNSET_UINT
;
2960 clcf
->types_hash_bucket_size
= NGX_CONF_UNSET_UINT
;
2962 clcf
->open_file_cache
= NGX_CONF_UNSET_PTR
;
2963 clcf
->open_file_cache_valid
= NGX_CONF_UNSET
;
2964 clcf
->open_file_cache_min_uses
= NGX_CONF_UNSET_UINT
;
2965 clcf
->open_file_cache_errors
= NGX_CONF_UNSET
;
2966 clcf
->open_file_cache_events
= NGX_CONF_UNSET
;
2969 clcf
->gzip_vary
= NGX_CONF_UNSET
;
2970 clcf
->gzip_http_version
= NGX_CONF_UNSET_UINT
;
2972 clcf
->gzip_disable
= NGX_CONF_UNSET_PTR
;
2973 clcf
->gzip_disable_msie6
= 3;
2981 static ngx_str_t ngx_http_core_text_html_type
= ngx_string("text/html");
2982 static ngx_str_t ngx_http_core_image_gif_type
= ngx_string("image/gif");
2983 static ngx_str_t ngx_http_core_image_jpeg_type
= ngx_string("image/jpeg");
2985 static ngx_hash_key_t ngx_http_core_default_types
[] = {
2986 { ngx_string("html"), 0, &ngx_http_core_text_html_type
},
2987 { ngx_string("gif"), 0, &ngx_http_core_image_gif_type
},
2988 { ngx_string("jpg"), 0, &ngx_http_core_image_jpeg_type
},
2989 { ngx_null_string
, 0, NULL
}
2994 ngx_http_core_merge_loc_conf(ngx_conf_t
*cf
, void *parent
, void *child
)
2996 ngx_http_core_loc_conf_t
*prev
= parent
;
2997 ngx_http_core_loc_conf_t
*conf
= child
;
3000 ngx_hash_key_t
*type
;
3001 ngx_hash_init_t types_hash
;
3003 if (conf
->root
.data
== NULL
) {
3005 conf
->alias
= prev
->alias
;
3006 conf
->root
= prev
->root
;
3007 conf
->root_lengths
= prev
->root_lengths
;
3008 conf
->root_values
= prev
->root_values
;
3010 if (prev
->root
.data
== NULL
) {
3011 conf
->root
.len
= sizeof("html") - 1;
3012 conf
->root
.data
= (u_char
*) "html";
3014 if (ngx_conf_full_name(cf
->cycle
, &conf
->root
, 0) != NGX_OK
) {
3015 return NGX_CONF_ERROR
;
3020 if (conf
->post_action
.data
== NULL
) {
3021 conf
->post_action
= prev
->post_action
;
3024 ngx_conf_merge_uint_value(conf
->types_hash_max_size
,
3025 prev
->types_hash_max_size
, 1024);
3027 ngx_conf_merge_uint_value(conf
->types_hash_bucket_size
,
3028 prev
->types_hash_bucket_size
,
3029 ngx_cacheline_size
);
3031 conf
->types_hash_bucket_size
= ngx_align(conf
->types_hash_bucket_size
,
3032 ngx_cacheline_size
);
3035 * the special handling the "types" directive in the "http" section
3036 * to inherit the http's conf->types_hash to all servers
3039 if (prev
->types
&& prev
->types_hash
.buckets
== NULL
) {
3041 types_hash
.hash
= &prev
->types_hash
;
3042 types_hash
.key
= ngx_hash_key_lc
;
3043 types_hash
.max_size
= conf
->types_hash_max_size
;
3044 types_hash
.bucket_size
= conf
->types_hash_bucket_size
;
3045 types_hash
.name
= "types_hash";
3046 types_hash
.pool
= cf
->pool
;
3047 types_hash
.temp_pool
= NULL
;
3049 if (ngx_hash_init(&types_hash
, prev
->types
->elts
, prev
->types
->nelts
)
3052 return NGX_CONF_ERROR
;
3056 if (conf
->types
== NULL
) {
3057 conf
->types
= prev
->types
;
3058 conf
->types_hash
= prev
->types_hash
;
3061 if (conf
->types
== NULL
) {
3062 conf
->types
= ngx_array_create(cf
->pool
, 4, sizeof(ngx_hash_key_t
));
3063 if (conf
->types
== NULL
) {
3064 return NGX_CONF_ERROR
;
3067 for (i
= 0; ngx_http_core_default_types
[i
].key
.len
; i
++) {
3068 type
= ngx_array_push(conf
->types
);
3070 return NGX_CONF_ERROR
;
3073 type
->key
= ngx_http_core_default_types
[i
].key
;
3075 ngx_hash_key_lc(ngx_http_core_default_types
[i
].key
.data
,
3076 ngx_http_core_default_types
[i
].key
.len
);
3077 type
->value
= ngx_http_core_default_types
[i
].value
;
3081 if (conf
->types_hash
.buckets
== NULL
) {
3083 types_hash
.hash
= &conf
->types_hash
;
3084 types_hash
.key
= ngx_hash_key_lc
;
3085 types_hash
.max_size
= conf
->types_hash_max_size
;
3086 types_hash
.bucket_size
= conf
->types_hash_bucket_size
;
3087 types_hash
.name
= "mime_types_hash";
3088 types_hash
.pool
= cf
->pool
;
3089 types_hash
.temp_pool
= NULL
;
3091 if (ngx_hash_init(&types_hash
, conf
->types
->elts
, conf
->types
->nelts
)
3094 return NGX_CONF_ERROR
;
3098 if (conf
->error_log
== NULL
) {
3099 if (prev
->error_log
) {
3100 conf
->error_log
= prev
->error_log
;
3102 conf
->error_log
= &cf
->cycle
->new_log
;
3106 if (conf
->error_pages
== NULL
&& prev
->error_pages
) {
3107 conf
->error_pages
= prev
->error_pages
;
3110 ngx_conf_merge_str_value(conf
->default_type
,
3111 prev
->default_type
, "text/plain");
3113 ngx_conf_merge_off_value(conf
->client_max_body_size
,
3114 prev
->client_max_body_size
, 1 * 1024 * 1024);
3115 ngx_conf_merge_size_value(conf
->client_body_buffer_size
,
3116 prev
->client_body_buffer_size
,
3117 (size_t) 2 * ngx_pagesize
);
3118 ngx_conf_merge_msec_value(conf
->client_body_timeout
,
3119 prev
->client_body_timeout
, 60000);
3121 ngx_conf_merge_uint_value(conf
->satisfy
, prev
->satisfy
,
3122 NGX_HTTP_SATISFY_ALL
);
3123 ngx_conf_merge_uint_value(conf
->if_modified_since
, prev
->if_modified_since
,
3124 NGX_HTTP_IMS_EXACT
);
3125 ngx_conf_merge_uint_value(conf
->client_body_in_file_only
,
3126 prev
->client_body_in_file_only
, 0);
3127 ngx_conf_merge_value(conf
->client_body_in_single_buffer
,
3128 prev
->client_body_in_single_buffer
, 0);
3129 ngx_conf_merge_value(conf
->internal
, prev
->internal
, 0);
3130 ngx_conf_merge_value(conf
->sendfile
, prev
->sendfile
, 0);
3131 ngx_conf_merge_size_value(conf
->sendfile_max_chunk
,
3132 prev
->sendfile_max_chunk
, 0);
3133 #if (NGX_HAVE_FILE_AIO)
3134 ngx_conf_merge_value(conf
->aio
, prev
->aio
, 0);
3136 ngx_conf_merge_size_value(conf
->read_ahead
, prev
->read_ahead
, 0);
3137 ngx_conf_merge_off_value(conf
->directio
, prev
->directio
,
3138 NGX_MAX_OFF_T_VALUE
);
3139 ngx_conf_merge_off_value(conf
->directio_alignment
, prev
->directio_alignment
,
3141 ngx_conf_merge_value(conf
->tcp_nopush
, prev
->tcp_nopush
, 0);
3142 ngx_conf_merge_value(conf
->tcp_nodelay
, prev
->tcp_nodelay
, 1);
3144 ngx_conf_merge_msec_value(conf
->send_timeout
, prev
->send_timeout
, 60000);
3145 ngx_conf_merge_size_value(conf
->send_lowat
, prev
->send_lowat
, 0);
3146 ngx_conf_merge_size_value(conf
->postpone_output
, prev
->postpone_output
,
3148 ngx_conf_merge_size_value(conf
->limit_rate
, prev
->limit_rate
, 0);
3149 ngx_conf_merge_size_value(conf
->limit_rate_after
, prev
->limit_rate_after
,
3151 ngx_conf_merge_msec_value(conf
->keepalive_timeout
,
3152 prev
->keepalive_timeout
, 75000);
3153 ngx_conf_merge_sec_value(conf
->keepalive_header
,
3154 prev
->keepalive_header
, 0);
3155 ngx_conf_merge_uint_value(conf
->keepalive_requests
,
3156 prev
->keepalive_requests
, 100);
3157 ngx_conf_merge_msec_value(conf
->lingering_time
,
3158 prev
->lingering_time
, 30000);
3159 ngx_conf_merge_msec_value(conf
->lingering_timeout
,
3160 prev
->lingering_timeout
, 5000);
3161 ngx_conf_merge_msec_value(conf
->resolver_timeout
,
3162 prev
->resolver_timeout
, 30000);
3164 if (conf
->resolver
== NULL
) {
3166 if (prev
->resolver
== NULL
) {
3169 * create dummy resolver in http {} context
3170 * to inherit it in all servers
3173 prev
->resolver
= ngx_resolver_create(cf
, NULL
);
3174 if (prev
->resolver
== NULL
) {
3175 return NGX_CONF_ERROR
;
3179 conf
->resolver
= prev
->resolver
;
3182 if (ngx_conf_merge_path_value(cf
, &conf
->client_body_temp_path
,
3183 prev
->client_body_temp_path
,
3184 &ngx_http_client_temp_path
)
3187 return NGX_CONF_ERROR
;
3190 ngx_conf_merge_value(conf
->reset_timedout_connection
,
3191 prev
->reset_timedout_connection
, 0);
3192 ngx_conf_merge_value(conf
->server_name_in_redirect
,
3193 prev
->server_name_in_redirect
, 1);
3194 ngx_conf_merge_value(conf
->port_in_redirect
, prev
->port_in_redirect
, 1);
3195 ngx_conf_merge_value(conf
->msie_padding
, prev
->msie_padding
, 1);
3196 ngx_conf_merge_value(conf
->msie_refresh
, prev
->msie_refresh
, 0);
3197 ngx_conf_merge_value(conf
->log_not_found
, prev
->log_not_found
, 1);
3198 ngx_conf_merge_value(conf
->log_subrequest
, prev
->log_subrequest
, 0);
3199 ngx_conf_merge_value(conf
->recursive_error_pages
,
3200 prev
->recursive_error_pages
, 0);
3201 ngx_conf_merge_value(conf
->server_tokens
, prev
->server_tokens
, 1);
3203 ngx_conf_merge_ptr_value(conf
->open_file_cache
,
3204 prev
->open_file_cache
, NULL
);
3206 ngx_conf_merge_sec_value(conf
->open_file_cache_valid
,
3207 prev
->open_file_cache_valid
, 60);
3209 ngx_conf_merge_uint_value(conf
->open_file_cache_min_uses
,
3210 prev
->open_file_cache_min_uses
, 1);
3212 ngx_conf_merge_sec_value(conf
->open_file_cache_errors
,
3213 prev
->open_file_cache_errors
, 0);
3215 ngx_conf_merge_sec_value(conf
->open_file_cache_events
,
3216 prev
->open_file_cache_events
, 0);
3219 ngx_conf_merge_value(conf
->gzip_vary
, prev
->gzip_vary
, 0);
3220 ngx_conf_merge_uint_value(conf
->gzip_http_version
, prev
->gzip_http_version
,
3221 NGX_HTTP_VERSION_11
);
3222 ngx_conf_merge_bitmask_value(conf
->gzip_proxied
, prev
->gzip_proxied
,
3223 (NGX_CONF_BITMASK_SET
|NGX_HTTP_GZIP_PROXIED_OFF
));
3226 ngx_conf_merge_ptr_value(conf
->gzip_disable
, prev
->gzip_disable
, NULL
);
3229 if (conf
->gzip_disable_msie6
== 3) {
3230 conf
->gzip_disable_msie6
=
3231 (prev
->gzip_disable_msie6
== 3) ? 0 : prev
->gzip_disable_msie6
;
3241 ngx_http_core_listen(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
3243 ngx_http_core_srv_conf_t
*cscf
= conf
;
3245 ngx_str_t
*value
, size
;
3248 ngx_http_listen_opt_t lsopt
;
3252 value
= cf
->args
->elts
;
3254 ngx_memzero(&u
, sizeof(ngx_url_t
));
3258 u
.default_port
= 80;
3260 if (ngx_parse_url(cf
->pool
, &u
) != NGX_OK
) {
3262 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3263 "%s in \"%V\" of the \"listen\" directive",
3267 return NGX_CONF_ERROR
;
3270 ngx_memzero(&lsopt
, sizeof(ngx_http_listen_opt_t
));
3272 ngx_memcpy(lsopt
.sockaddr
, u
.sockaddr
, u
.socklen
);
3274 lsopt
.socklen
= u
.socklen
;
3275 lsopt
.backlog
= NGX_LISTEN_BACKLOG
;
3278 lsopt
.wildcard
= u
.wildcard
;
3280 (void) ngx_sock_ntop((struct sockaddr
*) &lsopt
.sockaddr
, lsopt
.addr
,
3281 NGX_SOCKADDR_STRLEN
, 1);
3283 for (n
= 2; n
< cf
->args
->nelts
; n
++) {
3285 if (ngx_strcmp(value
[n
].data
, "default_server") == 0
3286 || ngx_strcmp(value
[n
].data
, "default") == 0)
3288 lsopt
.default_server
= 1;
3292 if (ngx_strcmp(value
[n
].data
, "bind") == 0) {
3298 if (ngx_strncmp(value
[n
].data
, "backlog=", 8) == 0) {
3299 lsopt
.backlog
= ngx_atoi(value
[n
].data
+ 8, value
[n
].len
- 8);
3303 if (lsopt
.backlog
== NGX_ERROR
|| lsopt
.backlog
== 0) {
3304 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3305 "invalid backlog \"%V\"", &value
[n
]);
3306 return NGX_CONF_ERROR
;
3312 if (ngx_strncmp(value
[n
].data
, "rcvbuf=", 7) == 0) {
3313 size
.len
= value
[n
].len
- 7;
3314 size
.data
= value
[n
].data
+ 7;
3316 lsopt
.rcvbuf
= ngx_parse_size(&size
);
3320 if (lsopt
.rcvbuf
== NGX_ERROR
) {
3321 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3322 "invalid rcvbuf \"%V\"", &value
[n
]);
3323 return NGX_CONF_ERROR
;
3329 if (ngx_strncmp(value
[n
].data
, "sndbuf=", 7) == 0) {
3330 size
.len
= value
[n
].len
- 7;
3331 size
.data
= value
[n
].data
+ 7;
3333 lsopt
.sndbuf
= ngx_parse_size(&size
);
3337 if (lsopt
.sndbuf
== NGX_ERROR
) {
3338 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3339 "invalid sndbuf \"%V\"", &value
[n
]);
3340 return NGX_CONF_ERROR
;
3346 if (ngx_strncmp(value
[n
].data
, "accept_filter=", 14) == 0) {
3347 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
3348 lsopt
.accept_filter
= (char *) &value
[n
].data
[14];
3352 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3353 "accept filters \"%V\" are not supported "
3354 "on this platform, ignored",
3360 if (ngx_strcmp(value
[n
].data
, "deferred") == 0) {
3361 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
3362 lsopt
.deferred_accept
= 1;
3366 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3367 "the deferred accept is not supported "
3368 "on this platform, ignored");
3373 if (ngx_strncmp(value
[n
].data
, "ipv6only=o", 10) == 0) {
3374 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
3375 struct sockaddr
*sa
;
3377 sa
= (struct sockaddr
*) lsopt
.sockaddr
;
3379 if (sa
->sa_family
== AF_INET6
) {
3381 if (ngx_strcmp(&value
[n
].data
[10], "n") == 0) {
3384 } else if (ngx_strcmp(&value
[n
].data
[10], "ff") == 0) {
3388 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3389 "invalid ipv6only flags \"%s\"",
3391 return NGX_CONF_ERROR
;
3398 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3399 "ipv6only is not supported "
3400 "on addr \"%s\", ignored", lsopt
.addr
);
3405 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3406 "bind ipv6only is not supported "
3407 "on this platform");
3408 return NGX_CONF_ERROR
;
3412 if (ngx_strcmp(value
[n
].data
, "ssl") == 0) {
3418 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3419 "the \"ssl\" parameter requires "
3420 "ngx_http_ssl_module");
3421 return NGX_CONF_ERROR
;
3425 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3426 "the invalid \"%V\" parameter", &value
[n
]);
3427 return NGX_CONF_ERROR
;
3430 if (ngx_http_add_listen(cf
, cscf
, &lsopt
) == NGX_OK
) {
3434 return NGX_CONF_ERROR
;
3439 ngx_http_core_server_name(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
3441 ngx_http_core_srv_conf_t
*cscf
= conf
;
3444 ngx_str_t
*value
, name
;
3446 ngx_http_server_name_t
*sn
;
3448 value
= cf
->args
->elts
;
3450 ch
= value
[1].data
[0];
3452 if (cscf
->server_name
.data
== NULL
) {
3461 cscf
->server_name
.len
= name
.len
;
3462 cscf
->server_name
.data
= ngx_pstrdup(cf
->pool
, &name
);
3463 if (cscf
->server_name
.data
== NULL
) {
3464 return NGX_CONF_ERROR
;
3468 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3469 "the first server name must not be empty");
3470 return NGX_CONF_ERROR
;
3474 for (i
= 1; i
< cf
->args
->nelts
; i
++) {
3476 ch
= value
[i
].data
[0];
3478 if ((ch
== '*' && (value
[i
].len
< 3 || value
[i
].data
[1] != '.'))
3479 || (ch
== '.' && value
[i
].len
< 2))
3481 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3482 "server name \"%V\" is invalid", &value
[i
]);
3483 return NGX_CONF_ERROR
;
3486 if (ngx_strchr(value
[i
].data
, '/')) {
3487 ngx_conf_log_error(NGX_LOG_WARN
, cf
, 0,
3488 "server name \"%V\" has strange symbols",
3492 if (value
[i
].len
== 1 && ch
== '*') {
3493 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3494 "\"server_name *\" is unsupported, use "
3495 "\"server_name_in_redirect off\" instead");
3496 return NGX_CONF_ERROR
;
3499 sn
= ngx_array_push(&cscf
->server_names
);
3501 return NGX_CONF_ERROR
;
3508 sn
->name
= value
[i
];
3510 ngx_strlow(sn
->name
.data
, sn
->name
.data
, sn
->name
.len
);
3512 if (value
[i
].data
[0] != '~') {
3518 ngx_regex_compile_t rc
;
3519 u_char errstr
[NGX_MAX_CONF_ERRSTR
];
3521 if (value
[i
].len
== 1) {
3522 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3523 "empty regex in server name \"%V\"", &value
[i
]);
3524 return NGX_CONF_ERROR
;
3530 ngx_memzero(&rc
, sizeof(ngx_regex_compile_t
));
3532 rc
.pattern
= value
[i
];
3533 rc
.err
.len
= NGX_MAX_CONF_ERRSTR
;
3534 rc
.err
.data
= errstr
;
3536 sn
->regex
= ngx_http_regex_compile(cf
, &rc
);
3537 if (sn
->regex
== NULL
) {
3538 return NGX_CONF_ERROR
;
3541 sn
->name
= value
[i
];
3542 cscf
->captures
= (rc
.captures
> 0);
3545 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3546 "the using of the regex \"%V\" "
3547 "requires PCRE library", &value
[i
]);
3549 return NGX_CONF_ERROR
;
3558 ngx_http_core_root(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
3560 ngx_http_core_loc_conf_t
*clcf
= conf
;
3563 ngx_uint_t alias
, n
;
3564 ngx_http_script_compile_t sc
;
3566 alias
= (cmd
->name
.len
== sizeof("alias") - 1) ? 1 : 0;
3568 if (clcf
->root
.data
) {
3570 /* the (ngx_uint_t) cast is required by gcc 2.7.2.3 */
3572 if ((ngx_uint_t
) clcf
->alias
== alias
) {
3573 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3574 "\"%V\" directive is duplicate",
3577 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3578 "\"%V\" directive is duplicate, "
3579 "\"%s\" directive is specified before",
3580 &cmd
->name
, clcf
->alias
? "alias" : "root");
3583 return NGX_CONF_ERROR
;
3586 if (clcf
->named
&& alias
) {
3587 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3588 "the \"alias\" directive may not be used "
3589 "inside named location");
3591 return NGX_CONF_ERROR
;
3594 value
= cf
->args
->elts
;
3596 if (ngx_strstr(value
[1].data
, "$document_root")
3597 || ngx_strstr(value
[1].data
, "${document_root}"))
3599 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3600 "the $document_root variable may not be used "
3601 "in the \"%V\" directive",
3604 return NGX_CONF_ERROR
;
3607 if (ngx_strstr(value
[1].data
, "$realpath_root")
3608 || ngx_strstr(value
[1].data
, "${realpath_root}"))
3610 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3611 "the $realpath_root variable may not be used "
3612 "in the \"%V\" directive",
3615 return NGX_CONF_ERROR
;
3618 clcf
->alias
= alias
;
3619 clcf
->root
= value
[1];
3621 if (!alias
&& clcf
->root
.data
[clcf
->root
.len
- 1] == '/') {
3625 if (clcf
->root
.data
[0] != '$') {
3626 if (ngx_conf_full_name(cf
->cycle
, &clcf
->root
, 0) != NGX_OK
) {
3627 return NGX_CONF_ERROR
;
3631 n
= ngx_http_script_variables_count(&clcf
->root
);
3633 ngx_memzero(&sc
, sizeof(ngx_http_script_compile_t
));
3637 sc
.source
= &clcf
->root
;
3638 sc
.lengths
= &clcf
->root_lengths
;
3639 sc
.values
= &clcf
->root_values
;
3641 sc
.complete_lengths
= 1;
3642 sc
.complete_values
= 1;
3644 if (ngx_http_script_compile(&sc
) != NGX_OK
) {
3645 return NGX_CONF_ERROR
;
3653 static ngx_http_method_name_t ngx_methods_names
[] = {
3654 { (u_char
*) "GET", (uint32_t) ~NGX_HTTP_GET
},
3655 { (u_char
*) "HEAD", (uint32_t) ~NGX_HTTP_HEAD
},
3656 { (u_char
*) "POST", (uint32_t) ~NGX_HTTP_POST
},
3657 { (u_char
*) "PUT", (uint32_t) ~NGX_HTTP_PUT
},
3658 { (u_char
*) "DELETE", (uint32_t) ~NGX_HTTP_DELETE
},
3659 { (u_char
*) "MKCOL", (uint32_t) ~NGX_HTTP_MKCOL
},
3660 { (u_char
*) "COPY", (uint32_t) ~NGX_HTTP_COPY
},
3661 { (u_char
*) "MOVE", (uint32_t) ~NGX_HTTP_MOVE
},
3662 { (u_char
*) "OPTIONS", (uint32_t) ~NGX_HTTP_OPTIONS
},
3663 { (u_char
*) "PROPFIND" , (uint32_t) ~NGX_HTTP_PROPFIND
},
3664 { (u_char
*) "PROPPATCH", (uint32_t) ~NGX_HTTP_PROPPATCH
},
3665 { (u_char
*) "LOCK", (uint32_t) ~NGX_HTTP_LOCK
},
3666 { (u_char
*) "UNLOCK", (uint32_t) ~NGX_HTTP_UNLOCK
},
3672 ngx_http_core_limit_except(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
3674 ngx_http_core_loc_conf_t
*pclcf
= conf
;
3681 ngx_http_module_t
*module
;
3682 ngx_http_conf_ctx_t
*ctx
, *pctx
;
3683 ngx_http_method_name_t
*name
;
3684 ngx_http_core_loc_conf_t
*clcf
;
3686 if (pclcf
->limit_except
) {
3690 pclcf
->limit_except
= 0xffffffff;
3692 value
= cf
->args
->elts
;
3694 for (i
= 1; i
< cf
->args
->nelts
; i
++) {
3695 for (name
= ngx_methods_names
; name
->name
; name
++) {
3697 if (ngx_strcasecmp(value
[i
].data
, name
->name
) == 0) {
3698 pclcf
->limit_except
&= name
->method
;
3703 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3704 "invalid method \"%V\"", &value
[i
]);
3705 return NGX_CONF_ERROR
;
3711 if (!(pclcf
->limit_except
& NGX_HTTP_GET
)) {
3712 pclcf
->limit_except
&= (uint32_t) ~NGX_HTTP_HEAD
;
3715 ctx
= ngx_pcalloc(cf
->pool
, sizeof(ngx_http_conf_ctx_t
));
3717 return NGX_CONF_ERROR
;
3721 ctx
->main_conf
= pctx
->main_conf
;
3722 ctx
->srv_conf
= pctx
->srv_conf
;
3724 ctx
->loc_conf
= ngx_pcalloc(cf
->pool
, sizeof(void *) * ngx_http_max_module
);
3725 if (ctx
->loc_conf
== NULL
) {
3726 return NGX_CONF_ERROR
;
3729 for (i
= 0; ngx_modules
[i
]; i
++) {
3730 if (ngx_modules
[i
]->type
!= NGX_HTTP_MODULE
) {
3734 module
= ngx_modules
[i
]->ctx
;
3736 if (module
->create_loc_conf
) {
3738 mconf
= module
->create_loc_conf(cf
);
3739 if (mconf
== NULL
) {
3740 return NGX_CONF_ERROR
;
3743 ctx
->loc_conf
[ngx_modules
[i
]->ctx_index
] = mconf
;
3748 clcf
= ctx
->loc_conf
[ngx_http_core_module
.ctx_index
];
3749 pclcf
->limit_except_loc_conf
= ctx
->loc_conf
;
3750 clcf
->loc_conf
= ctx
->loc_conf
;
3751 clcf
->name
= pclcf
->name
;
3754 if (ngx_http_add_location(cf
, &pclcf
->locations
, clcf
) != NGX_OK
) {
3755 return NGX_CONF_ERROR
;
3760 cf
->cmd_type
= NGX_HTTP_LMT_CONF
;
3762 rv
= ngx_conf_parse(cf
, NULL
);
3771 ngx_http_core_directio(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
3773 ngx_http_core_loc_conf_t
*clcf
= conf
;
3777 if (clcf
->directio
!= NGX_CONF_UNSET
) {
3778 return "is duplicate";
3781 value
= cf
->args
->elts
;
3783 if (ngx_strcmp(value
[1].data
, "off") == 0) {
3784 clcf
->directio
= NGX_OPEN_FILE_DIRECTIO_OFF
;
3788 clcf
->directio
= ngx_parse_offset(&value
[1]);
3789 if (clcf
->directio
== (off_t
) NGX_ERROR
) {
3790 return "invalid value";
3798 ngx_http_core_error_page(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
3800 ngx_http_core_loc_conf_t
*clcf
= conf
;
3803 ngx_int_t overwrite
;
3804 ngx_str_t
*value
, uri
, args
;
3806 ngx_http_err_page_t
*err
;
3807 ngx_http_complex_value_t cv
;
3808 ngx_http_compile_complex_value_t ccv
;
3810 if (clcf
->error_pages
== NULL
) {
3811 clcf
->error_pages
= ngx_array_create(cf
->pool
, 4,
3812 sizeof(ngx_http_err_page_t
));
3813 if (clcf
->error_pages
== NULL
) {
3814 return NGX_CONF_ERROR
;
3818 value
= cf
->args
->elts
;
3820 i
= cf
->args
->nelts
- 2;
3822 if (value
[i
].data
[0] == '=') {
3824 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3825 "invalid value \"%V\"", &value
[i
]);
3826 return NGX_CONF_ERROR
;
3829 if (value
[i
].len
> 1) {
3830 overwrite
= ngx_atoi(&value
[i
].data
[1], value
[i
].len
- 1);
3832 if (overwrite
== NGX_ERROR
) {
3833 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3834 "invalid value \"%V\"", &value
[i
]);
3835 return NGX_CONF_ERROR
;
3849 uri
= value
[cf
->args
->nelts
- 1];
3851 ngx_memzero(&ccv
, sizeof(ngx_http_compile_complex_value_t
));
3855 ccv
.complex_value
= &cv
;
3857 if (ngx_http_compile_complex_value(&ccv
) != NGX_OK
) {
3858 return NGX_CONF_ERROR
;
3864 if (cv
.lengths
== NULL
&& uri
.data
[0] == '/') {
3865 p
= (u_char
*) ngx_strchr(uri
.data
, '?');
3868 cv
.value
.len
= p
- uri
.data
;
3869 cv
.value
.data
= uri
.data
;
3871 args
.len
= (uri
.data
+ uri
.len
) - p
;
3876 for (i
= 1; i
< cf
->args
->nelts
- n
; i
++) {
3877 err
= ngx_array_push(clcf
->error_pages
);
3879 return NGX_CONF_ERROR
;
3882 err
->status
= ngx_atoi(value
[i
].data
, value
[i
].len
);
3884 if (err
->status
== NGX_ERROR
|| err
->status
== 499) {
3885 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3886 "invalid value \"%V\"", &value
[i
]);
3887 return NGX_CONF_ERROR
;
3890 if (err
->status
< 400 || err
->status
> 599) {
3891 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3892 "value \"%V\" must be between 400 and 599",
3894 return NGX_CONF_ERROR
;
3897 if (overwrite
>= 0) {
3898 err
->overwrite
= overwrite
;
3901 switch (err
->status
) {
3902 case NGX_HTTP_TO_HTTPS
:
3903 case NGX_HTTPS_CERT_ERROR
:
3904 case NGX_HTTPS_NO_CERT
:
3905 err
->overwrite
= NGX_HTTP_BAD_REQUEST
;
3909 err
->overwrite
= err
->status
;
3923 ngx_http_core_try_files(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
3925 ngx_http_core_loc_conf_t
*clcf
= conf
;
3930 ngx_http_try_file_t
*tf
;
3931 ngx_http_script_compile_t sc
;
3932 ngx_http_core_main_conf_t
*cmcf
;
3934 if (clcf
->try_files
) {
3935 return "is duplicate";
3938 cmcf
= ngx_http_conf_get_module_main_conf(cf
, ngx_http_core_module
);
3940 cmcf
->try_files
= 1;
3942 tf
= ngx_pcalloc(cf
->pool
, cf
->args
->nelts
* sizeof(ngx_http_try_file_t
));
3944 return NGX_CONF_ERROR
;
3947 clcf
->try_files
= tf
;
3949 value
= cf
->args
->elts
;
3951 for (i
= 0; i
< cf
->args
->nelts
- 1; i
++) {
3953 tf
[i
].name
= value
[i
+ 1];
3955 if (tf
[i
].name
.data
[tf
[i
].name
.len
- 1] == '/') {
3958 tf
[i
].name
.data
[tf
[i
].name
.len
] = '\0';
3961 n
= ngx_http_script_variables_count(&tf
[i
].name
);
3964 ngx_memzero(&sc
, sizeof(ngx_http_script_compile_t
));
3967 sc
.source
= &tf
[i
].name
;
3968 sc
.lengths
= &tf
[i
].lengths
;
3969 sc
.values
= &tf
[i
].values
;
3971 sc
.complete_lengths
= 1;
3972 sc
.complete_values
= 1;
3974 if (ngx_http_script_compile(&sc
) != NGX_OK
) {
3975 return NGX_CONF_ERROR
;
3979 /* add trailing '\0' to length */
3984 if (tf
[i
- 1].name
.data
[0] == '=') {
3986 code
= ngx_atoi(tf
[i
- 1].name
.data
+ 1, tf
[i
- 1].name
.len
- 2);
3988 if (code
== NGX_ERROR
) {
3989 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3990 "invalid code \"%*s\"",
3991 tf
[i
- 1].name
.len
- 1, tf
[i
- 1].name
.data
);
3992 return NGX_CONF_ERROR
;
4003 ngx_http_core_open_file_cache(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
4005 ngx_http_core_loc_conf_t
*clcf
= conf
;
4008 ngx_str_t
*value
, s
;
4012 if (clcf
->open_file_cache
!= NGX_CONF_UNSET_PTR
) {
4013 return "is duplicate";
4016 value
= cf
->args
->elts
;
4021 for (i
= 1; i
< cf
->args
->nelts
; i
++) {
4023 if (ngx_strncmp(value
[i
].data
, "max=", 4) == 0) {
4025 max
= ngx_atoi(value
[i
].data
+ 4, value
[i
].len
- 4);
4026 if (max
== NGX_ERROR
) {
4033 if (ngx_strncmp(value
[i
].data
, "inactive=", 9) == 0) {
4035 s
.len
= value
[i
].len
- 9;
4036 s
.data
= value
[i
].data
+ 9;
4038 inactive
= ngx_parse_time(&s
, 1);
4046 if (ngx_strcmp(value
[i
].data
, "off") == 0) {
4048 clcf
->open_file_cache
= NULL
;
4055 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4056 "invalid \"open_file_cache\" parameter \"%V\"",
4058 return NGX_CONF_ERROR
;
4061 if (clcf
->open_file_cache
== NULL
) {
4066 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4067 "\"open_file_cache\" must have \"max\" parameter");
4068 return NGX_CONF_ERROR
;
4071 clcf
->open_file_cache
= ngx_open_file_cache_init(cf
->pool
, max
, inactive
);
4072 if (clcf
->open_file_cache
) {
4076 return NGX_CONF_ERROR
;
4081 ngx_http_core_error_log(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
4083 ngx_http_core_loc_conf_t
*clcf
= conf
;
4087 if (clcf
->error_log
) {
4088 return "is duplicate";
4091 value
= cf
->args
->elts
;
4093 clcf
->error_log
= ngx_log_create(cf
->cycle
, &value
[1]);
4094 if (clcf
->error_log
== NULL
) {
4095 return NGX_CONF_ERROR
;
4098 if (cf
->args
->nelts
== 2) {
4099 clcf
->error_log
->log_level
= NGX_LOG_ERR
;
4103 return ngx_log_set_levels(cf
, clcf
->error_log
);
4108 ngx_http_core_keepalive(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
4110 ngx_http_core_loc_conf_t
*clcf
= conf
;
4114 if (clcf
->keepalive_timeout
!= NGX_CONF_UNSET_MSEC
) {
4115 return "is duplicate";
4118 value
= cf
->args
->elts
;
4120 clcf
->keepalive_timeout
= ngx_parse_time(&value
[1], 0);
4122 if (clcf
->keepalive_timeout
== (ngx_msec_t
) NGX_ERROR
) {
4123 return "invalid value";
4126 if (clcf
->keepalive_timeout
== (ngx_msec_t
) NGX_PARSE_LARGE_TIME
) {
4127 return "value must be less than 597 hours";
4130 if (cf
->args
->nelts
== 2) {
4134 clcf
->keepalive_header
= ngx_parse_time(&value
[2], 1);
4136 if (clcf
->keepalive_header
== NGX_ERROR
) {
4137 return "invalid value";
4140 if (clcf
->keepalive_header
== NGX_PARSE_LARGE_TIME
) {
4141 return "value must be less than 68 years";
4149 ngx_http_core_internal(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
4151 ngx_http_core_loc_conf_t
*clcf
= conf
;
4153 if (clcf
->internal
!= NGX_CONF_UNSET
) {
4154 return "is duplicate";
4164 ngx_http_core_resolver(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
4166 ngx_http_core_loc_conf_t
*clcf
= conf
;
4171 if (clcf
->resolver
) {
4172 return "is duplicate";
4175 value
= cf
->args
->elts
;
4177 ngx_memzero(&u
, sizeof(ngx_url_t
));
4182 if (ngx_inet_resolve_host(cf
->pool
, &u
) != NGX_OK
) {
4183 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0, "%V: %s", &u
.host
, u
.err
);
4184 return NGX_CONF_ERROR
;
4187 clcf
->resolver
= ngx_resolver_create(cf
, &u
.addrs
[0]);
4188 if (clcf
->resolver
== NULL
) {
4199 ngx_http_gzip_disable(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
4201 ngx_http_core_loc_conf_t
*clcf
= conf
;
4207 ngx_regex_elt_t
*re
;
4208 ngx_regex_compile_t rc
;
4209 u_char errstr
[NGX_MAX_CONF_ERRSTR
];
4211 if (clcf
->gzip_disable
== NGX_CONF_UNSET_PTR
) {
4212 clcf
->gzip_disable
= ngx_array_create(cf
->pool
, 2,
4213 sizeof(ngx_regex_elt_t
));
4214 if (clcf
->gzip_disable
== NULL
) {
4215 return NGX_CONF_ERROR
;
4219 value
= cf
->args
->elts
;
4221 ngx_memzero(&rc
, sizeof(ngx_regex_compile_t
));
4224 rc
.err
.len
= NGX_MAX_CONF_ERRSTR
;
4225 rc
.err
.data
= errstr
;
4227 for (i
= 1; i
< cf
->args
->nelts
; i
++) {
4229 if (ngx_strcmp(value
[1].data
, "msie6") == 0) {
4230 clcf
->gzip_disable_msie6
= 1;
4234 re
= ngx_array_push(clcf
->gzip_disable
);
4236 return NGX_CONF_ERROR
;
4239 rc
.pattern
= value
[1];
4240 rc
.options
= NGX_REGEX_CASELESS
;
4242 if (ngx_regex_compile(&rc
) != NGX_OK
) {
4243 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0, "%V", &rc
.err
);
4244 return NGX_CONF_ERROR
;
4247 re
->regex
= rc
.regex
;
4248 re
->name
= value
[i
].data
;
4256 value
= cf
->args
->elts
;
4258 if (cf
->args
->nelts
== 2 && ngx_strcmp(value
[1].data
, "msie6") == 0) {
4259 clcf
->gzip_disable_msie6
= 1;
4263 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4264 "without PCRE library \"gzip_disable\" supports "
4265 "builtin \"msie6\" mask only");
4267 return NGX_CONF_ERROR
;
4275 ngx_http_core_lowat_check(ngx_conf_t
*cf
, void *post
, void *data
)
4280 if ((u_long
) *np
>= ngx_freebsd_net_inet_tcp_sendspace
) {
4281 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4282 "\"send_lowat\" must be less than %d "
4283 "(sysctl net.inet.tcp.sendspace)",
4284 ngx_freebsd_net_inet_tcp_sendspace
);
4286 return NGX_CONF_ERROR
;
4289 #elif !(NGX_HAVE_SO_SNDLOWAT)
4292 ngx_conf_log_error(NGX_LOG_WARN
, cf
, 0,
4293 "\"send_lowat\" is not supported, ignored");
4304 ngx_http_core_pool_size(ngx_conf_t
*cf
, void *post
, void *data
)
4308 if (*sp
< NGX_MIN_POOL_SIZE
) {
4309 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4310 "pool must be no less than %uz", NGX_MIN_POOL_SIZE
);
4312 return NGX_CONF_ERROR
;