nginx 0.8.26
[nginx.git] / src / http / ngx_http_core_module.c
blobe6b1162a0d2a6e257e26699b266589c084158add
2 /*
3 * Copyright (C) Igor Sysoev
4 */
7 #include <ngx_config.h>
8 #include <ngx_core.h>
9 #include <ngx_http.h>
12 typedef struct {
13 u_char *name;
14 uint32_t method;
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,
38 void *dummy);
39 static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd,
40 void *dummy);
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,
45 void *conf);
46 static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy,
47 void *conf);
49 static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
50 void *conf);
51 static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
52 void *conf);
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,
55 void *conf);
56 static char *ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd,
57 void *conf);
58 static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd,
59 void *conf);
60 static char *ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd,
61 void *conf);
62 static char *ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd,
63 void *conf);
64 static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
65 void *conf);
66 static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
67 void *conf);
68 static char *ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd,
69 void *conf);
70 static char *ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
71 void *conf);
72 #if (NGX_HTTP_GZIP)
73 static char *ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd,
74 void *conf);
75 #endif
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 },
114 #endif
115 { ngx_null_string, 0 }
118 #endif
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 }
141 #if (NGX_HTTP_GZIP)
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");
168 #endif
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),
178 NULL },
180 { ngx_string("variables_hash_bucket_size"),
181 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
182 ngx_conf_set_num_slot,
183 NGX_HTTP_MAIN_CONF_OFFSET,
184 offsetof(ngx_http_core_main_conf_t, variables_hash_bucket_size),
185 NULL },
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),
192 NULL },
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),
199 NULL },
201 { ngx_string("server"),
202 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_MULTI|NGX_CONF_NOARGS,
203 ngx_http_core_server,
206 NULL },
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),
227 NULL },
229 { ngx_string("client_header_buffer_size"),
230 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
231 ngx_conf_set_size_slot,
232 NGX_HTTP_SRV_CONF_OFFSET,
233 offsetof(ngx_http_core_srv_conf_t, client_header_buffer_size),
234 NULL },
236 { ngx_string("large_client_header_buffers"),
237 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE2,
238 ngx_conf_set_bufs_slot,
239 NGX_HTTP_SRV_CONF_OFFSET,
240 offsetof(ngx_http_core_srv_conf_t, large_client_header_buffers),
241 NULL },
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),
255 NULL },
257 { ngx_string("merge_slashes"),
258 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
259 ngx_conf_set_flag_slot,
260 NGX_HTTP_SRV_CONF_OFFSET,
261 offsetof(ngx_http_core_srv_conf_t, merge_slashes),
262 NULL },
264 { ngx_string("underscores_in_headers"),
265 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
266 ngx_conf_set_flag_slot,
267 NGX_HTTP_SRV_CONF_OFFSET,
268 offsetof(ngx_http_core_srv_conf_t, underscores_in_headers),
269 NULL },
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,
276 NULL },
278 { ngx_string("listen"),
279 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
280 ngx_http_core_listen,
281 NGX_HTTP_SRV_CONF_OFFSET,
283 NULL },
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,
290 NULL },
292 { ngx_string("types_hash_max_size"),
293 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
294 ngx_conf_set_num_slot,
295 NGX_HTTP_LOC_CONF_OFFSET,
296 offsetof(ngx_http_core_loc_conf_t, types_hash_max_size),
297 NULL },
299 { ngx_string("types_hash_bucket_size"),
300 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
301 ngx_conf_set_num_slot,
302 NGX_HTTP_LOC_CONF_OFFSET,
303 offsetof(ngx_http_core_loc_conf_t, types_hash_bucket_size),
304 NULL },
306 { ngx_string("types"),
307 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF
308 |NGX_CONF_BLOCK|NGX_CONF_NOARGS,
309 ngx_http_core_types,
310 NGX_HTTP_LOC_CONF_OFFSET,
312 NULL },
314 { ngx_string("default_type"),
315 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
316 ngx_conf_set_str_slot,
317 NGX_HTTP_LOC_CONF_OFFSET,
318 offsetof(ngx_http_core_loc_conf_t, default_type),
319 NULL },
321 { ngx_string("root"),
322 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
323 |NGX_CONF_TAKE1,
324 ngx_http_core_root,
325 NGX_HTTP_LOC_CONF_OFFSET,
327 NULL },
329 { ngx_string("alias"),
330 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
331 ngx_http_core_root,
332 NGX_HTTP_LOC_CONF_OFFSET,
334 NULL },
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,
341 NULL },
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),
348 NULL },
350 { ngx_string("client_body_buffer_size"),
351 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
352 ngx_conf_set_size_slot,
353 NGX_HTTP_LOC_CONF_OFFSET,
354 offsetof(ngx_http_core_loc_conf_t, client_body_buffer_size),
355 NULL },
357 { ngx_string("client_body_timeout"),
358 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
359 ngx_conf_set_msec_slot,
360 NGX_HTTP_LOC_CONF_OFFSET,
361 offsetof(ngx_http_core_loc_conf_t, client_body_timeout),
362 NULL },
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),
369 NULL },
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),
383 NULL },
385 { ngx_string("sendfile"),
386 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
387 |NGX_CONF_TAKE1,
388 ngx_conf_set_flag_slot,
389 NGX_HTTP_LOC_CONF_OFFSET,
390 offsetof(ngx_http_core_loc_conf_t, sendfile),
391 NULL },
393 { ngx_string("sendfile_max_chunk"),
394 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
395 ngx_conf_set_size_slot,
396 NGX_HTTP_LOC_CONF_OFFSET,
397 offsetof(ngx_http_core_loc_conf_t, sendfile_max_chunk),
398 NULL },
400 #if (NGX_HAVE_FILE_AIO)
402 { ngx_string("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 },
409 #endif
411 { ngx_string("read_ahead"),
412 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
413 ngx_conf_set_size_slot,
414 NGX_HTTP_LOC_CONF_OFFSET,
415 offsetof(ngx_http_core_loc_conf_t, read_ahead),
416 NULL },
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,
423 NULL },
425 { ngx_string("directio_alignment"),
426 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
427 ngx_conf_set_off_slot,
428 NGX_HTTP_LOC_CONF_OFFSET,
429 offsetof(ngx_http_core_loc_conf_t, directio_alignment),
430 NULL },
432 { ngx_string("tcp_nopush"),
433 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
434 ngx_conf_set_flag_slot,
435 NGX_HTTP_LOC_CONF_OFFSET,
436 offsetof(ngx_http_core_loc_conf_t, tcp_nopush),
437 NULL },
439 { ngx_string("tcp_nodelay"),
440 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
441 ngx_conf_set_flag_slot,
442 NGX_HTTP_LOC_CONF_OFFSET,
443 offsetof(ngx_http_core_loc_conf_t, tcp_nodelay),
444 NULL },
446 { ngx_string("send_timeout"),
447 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
448 ngx_conf_set_msec_slot,
449 NGX_HTTP_LOC_CONF_OFFSET,
450 offsetof(ngx_http_core_loc_conf_t, send_timeout),
451 NULL },
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),
465 NULL },
467 { ngx_string("limit_rate"),
468 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
469 |NGX_CONF_TAKE1,
470 ngx_conf_set_size_slot,
471 NGX_HTTP_LOC_CONF_OFFSET,
472 offsetof(ngx_http_core_loc_conf_t, limit_rate),
473 NULL },
475 { ngx_string("limit_rate_after"),
476 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
477 |NGX_CONF_TAKE1,
478 ngx_conf_set_size_slot,
479 NGX_HTTP_LOC_CONF_OFFSET,
480 offsetof(ngx_http_core_loc_conf_t, limit_rate_after),
481 NULL },
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,
488 NULL },
490 { ngx_string("keepalive_requests"),
491 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
492 ngx_conf_set_num_slot,
493 NGX_HTTP_LOC_CONF_OFFSET,
494 offsetof(ngx_http_core_loc_conf_t, keepalive_requests),
495 NULL },
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,
516 NULL },
518 { ngx_string("lingering_time"),
519 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
520 ngx_conf_set_msec_slot,
521 NGX_HTTP_LOC_CONF_OFFSET,
522 offsetof(ngx_http_core_loc_conf_t, lingering_time),
523 NULL },
525 { ngx_string("lingering_timeout"),
526 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
527 ngx_conf_set_msec_slot,
528 NGX_HTTP_LOC_CONF_OFFSET,
529 offsetof(ngx_http_core_loc_conf_t, lingering_timeout),
530 NULL },
532 { ngx_string("reset_timedout_connection"),
533 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
534 ngx_conf_set_flag_slot,
535 NGX_HTTP_LOC_CONF_OFFSET,
536 offsetof(ngx_http_core_loc_conf_t, reset_timedout_connection),
537 NULL },
539 { ngx_string("server_name_in_redirect"),
540 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
541 ngx_conf_set_flag_slot,
542 NGX_HTTP_LOC_CONF_OFFSET,
543 offsetof(ngx_http_core_loc_conf_t, server_name_in_redirect),
544 NULL },
546 { ngx_string("port_in_redirect"),
547 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
548 ngx_conf_set_flag_slot,
549 NGX_HTTP_LOC_CONF_OFFSET,
550 offsetof(ngx_http_core_loc_conf_t, port_in_redirect),
551 NULL },
553 { ngx_string("msie_padding"),
554 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
555 ngx_conf_set_flag_slot,
556 NGX_HTTP_LOC_CONF_OFFSET,
557 offsetof(ngx_http_core_loc_conf_t, msie_padding),
558 NULL },
560 { ngx_string("msie_refresh"),
561 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
562 ngx_conf_set_flag_slot,
563 NGX_HTTP_LOC_CONF_OFFSET,
564 offsetof(ngx_http_core_loc_conf_t, msie_refresh),
565 NULL },
567 { ngx_string("log_not_found"),
568 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
569 ngx_conf_set_flag_slot,
570 NGX_HTTP_LOC_CONF_OFFSET,
571 offsetof(ngx_http_core_loc_conf_t, log_not_found),
572 NULL },
574 { ngx_string("log_subrequest"),
575 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
576 ngx_conf_set_flag_slot,
577 NGX_HTTP_LOC_CONF_OFFSET,
578 offsetof(ngx_http_core_loc_conf_t, log_subrequest),
579 NULL },
581 { ngx_string("recursive_error_pages"),
582 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
583 ngx_conf_set_flag_slot,
584 NGX_HTTP_LOC_CONF_OFFSET,
585 offsetof(ngx_http_core_loc_conf_t, recursive_error_pages),
586 NULL },
588 { ngx_string("server_tokens"),
589 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
590 ngx_conf_set_flag_slot,
591 NGX_HTTP_LOC_CONF_OFFSET,
592 offsetof(ngx_http_core_loc_conf_t, server_tokens),
593 NULL },
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
604 |NGX_CONF_2MORE,
605 ngx_http_core_error_page,
606 NGX_HTTP_LOC_CONF_OFFSET,
608 NULL },
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,
615 NULL },
617 { ngx_string("post_action"),
618 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
619 |NGX_CONF_TAKE1,
620 ngx_conf_set_str_slot,
621 NGX_HTTP_LOC_CONF_OFFSET,
622 offsetof(ngx_http_core_loc_conf_t, post_action),
623 NULL },
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,
630 NULL },
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),
637 NULL },
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),
644 NULL },
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),
658 NULL },
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),
665 NULL },
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),
672 NULL },
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,
679 NULL },
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),
686 NULL },
688 #if (NGX_HTTP_GZIP)
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),
695 NULL },
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,
716 NULL },
718 #endif
720 ngx_null_command
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 = {
740 NGX_MODULE_V1,
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 " };
758 void
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;
767 if (!r->internal) {
768 switch (r->headers_in.connection_type) {
769 case 0:
770 if (r->http_version > NGX_HTTP_VERSION_10) {
771 r->keepalive = 1;
772 } else {
773 r->keepalive = 0;
775 break;
777 case NGX_HTTP_CONNECTION_CLOSE:
778 r->keepalive = 0;
779 break;
781 case NGX_HTTP_CONNECTION_KEEP_ALIVE:
782 r->keepalive = 1;
783 break;
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
793 r->keepalive = 0;
796 if (r->headers_in.content_length_n > 0) {
797 r->lingering_close = 1;
799 } else {
800 r->lingering_close = 0;
803 r->phase_handler = 0;
805 } else {
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;
815 #if (NGX_HTTP_GZIP)
816 r->gzip_tested = 0;
817 r->gzip_ok = 0;
818 r->gzip_vary = 0;
819 #endif
821 r->write_event_handler = ngx_http_core_run_phases;
822 ngx_http_core_run_phases(r);
826 void
827 ngx_http_core_run_phases(ngx_http_request_t *r)
829 ngx_int_t rc;
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]);
841 if (rc == NGX_OK) {
842 return;
848 ngx_int_t
849 ngx_http_core_generic_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
851 ngx_int_t rc;
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);
861 rc = ph->handler(r);
863 if (rc == NGX_OK) {
864 r->phase_handler = ph->next;
865 return NGX_AGAIN;
868 if (rc == NGX_DECLINED) {
869 r->phase_handler++;
870 return NGX_AGAIN;
873 if (rc == NGX_AGAIN || rc == NGX_DONE) {
874 return NGX_OK;
877 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
879 ngx_http_finalize_request(r, rc);
881 return NGX_OK;
885 ngx_int_t
886 ngx_http_core_find_config_phase(ngx_http_request_t *r,
887 ngx_http_phase_handler_t *ph)
889 u_char *p;
890 size_t len;
891 ngx_int_t rc;
892 ngx_http_core_loc_conf_t *clcf;
894 r->content_handler = NULL;
895 r->uri_changed = 0;
897 rc = ngx_http_core_find_location(r);
899 if (rc == NGX_ERROR) {
900 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
901 return NGX_OK;
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);
908 return NGX_OK;
911 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
912 "using configuration \"%s%V\"",
913 (clcf->noname ? "*" : (clcf->exact_match ? "=" : "")),
914 &clcf->name);
916 ngx_http_update_location_config(r);
918 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
919 "http cl:%O max:%O",
920 r->headers_in.content_length_n, clcf->client_max_body_size);
922 if (r->headers_in.content_length_n != -1
923 && !r->discard_body
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);
933 return NGX_OK;
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);
940 return NGX_OK;
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;
951 } else {
952 len = clcf->name.len + 1 + r->args.len;
953 p = ngx_pnalloc(r->pool, len);
955 if (p == NULL) {
956 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
957 return NGX_OK;
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);
964 *p++ = '?';
965 ngx_memcpy(p, r->args.data, r->args.len);
968 ngx_http_finalize_request(r, NGX_HTTP_MOVED_PERMANENTLY);
969 return NGX_OK;
972 r->phase_handler++;
973 return NGX_AGAIN;
977 ngx_int_t
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) {
987 r->phase_handler++;
988 return NGX_AGAIN;
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
1001 r->uri_changes--;
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);
1009 return NGX_OK;
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;
1017 return NGX_AGAIN;
1021 ngx_int_t
1022 ngx_http_core_access_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
1024 ngx_int_t rc;
1025 ngx_http_core_loc_conf_t *clcf;
1027 if (r != r->main) {
1028 r->phase_handler = ph->next;
1029 return NGX_AGAIN;
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) {
1038 r->phase_handler++;
1039 return NGX_AGAIN;
1042 if (rc == NGX_AGAIN || rc == NGX_DONE) {
1043 return NGX_OK;
1046 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1048 if (clcf->satisfy == NGX_HTTP_SATISFY_ALL) {
1050 if (rc == NGX_OK) {
1051 r->phase_handler++;
1052 return NGX_AGAIN;
1055 } else {
1056 if (rc == NGX_OK) {
1057 r->access_code = 0;
1059 if (r->headers_out.www_authenticate) {
1060 r->headers_out.www_authenticate->hash = 0;
1063 r->phase_handler = ph->next;
1064 return NGX_AGAIN;
1067 if (rc == NGX_HTTP_FORBIDDEN || rc == NGX_HTTP_UNAUTHORIZED) {
1068 r->access_code = rc;
1070 r->phase_handler++;
1071 return NGX_AGAIN;
1075 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
1077 ngx_http_finalize_request(r, rc);
1078 return NGX_OK;
1082 ngx_int_t
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);
1097 return NGX_OK;
1100 r->phase_handler++;
1101 return NGX_AGAIN;
1105 ngx_int_t
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;
1110 u_char *p, *name;
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) {
1126 r->phase_handler++;
1127 return NGX_AGAIN;
1130 allocated = 0;
1131 root = 0;
1132 name = NULL;
1133 /* suppress MSVC warning */
1134 path.data = NULL;
1136 tf = clcf->try_files;
1138 alias = clcf->alias ? clcf->name.len : 0;
1140 for ( ;; ) {
1142 if (tf->lengths) {
1143 ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
1145 e.ip = tf->lengths->elts;
1146 e.request = r;
1148 /* 1 is for terminating '\0' as in static names */
1149 len = 1;
1151 while (*(uintptr_t *) e.ip) {
1152 lcode = *(ngx_http_script_len_code_pt *) e.ip;
1153 len += lcode(&e);
1156 } else {
1157 len = tf->name.len;
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);
1169 return NGX_OK;
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;
1184 } else {
1185 e.ip = tf->values->elts;
1186 e.pos = name;
1187 e.flushed = 1;
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;
1196 *e.pos = '\0';
1198 if (alias && ngx_strncmp(name, clcf->name.data, alias) == 0) {
1199 ngx_memcpy(name, name + alias, len - alias);
1200 path.len -= alias;
1204 test_dir = tf->test_dir;
1206 tf++;
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) {
1213 if (tf->code) {
1214 ngx_http_finalize_request(r, tf->code);
1215 return NGX_OK;
1218 path.len -= root;
1219 path.data += root;
1221 if (path.data[0] == '@') {
1222 (void) ngx_http_named_location(r, &path);
1224 } else {
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);
1231 return NGX_OK;
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;
1239 of.test_only = 1;
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)
1244 != NGX_OK)
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);
1254 continue;
1257 if (of.is_dir && !test_dir) {
1258 continue;
1261 path.len -= root;
1262 path.data += root;
1264 if (!alias) {
1265 r->uri = path;
1267 } else {
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);
1272 return NGX_OK;
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);
1284 r->phase_handler++;
1285 return NGX_AGAIN;
1288 /* not reached */
1292 ngx_int_t
1293 ngx_http_core_content_phase(ngx_http_request_t *r,
1294 ngx_http_phase_handler_t *ph)
1296 size_t root;
1297 ngx_int_t rc;
1298 ngx_str_t path;
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));
1303 return NGX_OK;
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);
1313 return NGX_OK;
1316 /* rc == NGX_DECLINED */
1318 ph++;
1320 if (ph->checker) {
1321 r->phase_handler++;
1322 return NGX_AGAIN;
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);
1335 return NGX_OK;
1338 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no handler found");
1340 ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
1341 return NGX_OK;
1345 void
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);
1357 if (r == r->main) {
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;
1368 } else {
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;
1379 } else {
1380 r->request_body_file_log_level = NGX_LOG_WARN;
1383 r->request_body_in_single_buf = clcf->client_body_in_single_buffer;
1385 if (r->keepalive) {
1386 if (clcf->keepalive_timeout == 0) {
1387 r->keepalive = 0;
1389 } else if (r->connection->requests >= clcf->keepalive_requests) {
1390 r->keepalive = 0;
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
1417 static ngx_int_t
1418 ngx_http_core_find_location(ngx_http_request_t *r)
1420 ngx_int_t rc;
1421 ngx_http_core_loc_conf_t *pclcf;
1422 #if (NGX_PCRE)
1423 ngx_int_t n;
1424 ngx_uint_t noregex;
1425 ngx_http_core_loc_conf_t *clcf, **clcfp;
1427 noregex = 0;
1428 #endif
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) {
1436 #if (NGX_PCRE)
1437 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1439 noregex = clcf->noregex;
1440 #endif
1442 /* look up nested locations */
1444 rc = ngx_http_core_find_location(r);
1447 if (rc == NGX_OK || rc == NGX_DONE) {
1448 return rc;
1451 /* rc == NGX_DECLINED or rc == NGX_AGAIN in nested location */
1453 #if (NGX_PCRE)
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);
1464 if (n == NGX_OK) {
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) {
1475 continue;
1478 return NGX_ERROR;
1481 #endif
1483 return rc;
1488 * NGX_OK - exact match
1489 * NGX_DONE - auto redirect
1490 * NGX_AGAIN - inclusive match
1491 * NGX_DECLINED - no match
1494 static ngx_int_t
1495 ngx_http_core_find_static_location(ngx_http_request_t *r,
1496 ngx_http_location_tree_node_t *node)
1498 u_char *uri;
1499 size_t len, n;
1500 ngx_int_t rc, rv;
1502 len = r->uri.len;
1503 uri = r->uri.data;
1505 rv = NGX_DECLINED;
1507 for ( ;; ) {
1509 if (node == NULL) {
1510 return rv;
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);
1520 if (rc != 0) {
1521 node = (rc < 0) ? node->left : node->right;
1523 continue;
1526 if (len > (size_t) node->len) {
1528 if (node->inclusive) {
1530 r->loc_conf = node->inclusive->loc_conf;
1531 rv = NGX_AGAIN;
1533 node = node->tree;
1534 uri += n;
1535 len -= n;
1537 continue;
1540 /* exact only */
1542 node = node->right;
1544 continue;
1547 if (len == (size_t) node->len) {
1549 r->loc_conf = (node->exact) ? node->exact->loc_conf:
1550 node->inclusive->loc_conf;
1551 return NGX_OK;
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;
1560 rv = NGX_DONE;
1563 node = node->left;
1568 void *
1569 ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash)
1571 u_char c, *lowcase;
1572 size_t len;
1573 ngx_uint_t i, hash;
1575 if (r->headers_out.content_type.len == 0) {
1576 return NULL;
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) {
1585 return NULL;
1588 r->headers_out.content_type_lowcase = lowcase;
1590 hash = 0;
1592 for (i = 0; i < len; i++) {
1593 c = ngx_tolower(r->headers_out.content_type.data[i]);
1594 hash = ngx_hash(hash, c);
1595 lowcase[i] = 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);
1606 ngx_int_t
1607 ngx_http_set_content_type(ngx_http_request_t *r)
1609 u_char c, *exten;
1610 ngx_str_t *type;
1611 ngx_uint_t i, hash;
1612 ngx_http_core_loc_conf_t *clcf;
1614 if (r->headers_out.content_type.len) {
1615 return NGX_OK;
1618 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1620 if (r->exten.len) {
1622 hash = 0;
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) {
1631 return NGX_ERROR;
1634 hash = ngx_hash_strlow(exten, r->exten.data, r->exten.len);
1636 r->exten.data = exten;
1638 break;
1641 hash = ngx_hash(hash, c);
1644 type = ngx_hash_find(&clcf->types_hash, hash,
1645 r->exten.data, r->exten.len);
1647 if (type) {
1648 r->headers_out.content_type_len = type->len;
1649 r->headers_out.content_type = *type;
1651 return NGX_OK;
1655 r->headers_out.content_type_len = clcf->default_type.len;
1656 r->headers_out.content_type = clcf->default_type;
1658 return NGX_OK;
1662 void
1663 ngx_http_set_exten(ngx_http_request_t *r)
1665 ngx_int_t i;
1667 r->exten.len = 0;
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];
1676 return;
1678 } else if (r->uri.data[i] == '/') {
1679 return;
1683 return;
1687 ngx_int_t
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);
1699 ngx_int_t
1700 ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
1702 ngx_int_t rc;
1703 ngx_connection_t *c;
1705 c = r->connection;
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 */
1714 c->error = 1;
1717 return rc;
1721 u_char *
1722 ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,
1723 size_t *root_length, size_t reserved)
1725 u_char *last;
1726 size_t alias;
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);
1737 return NULL;
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) {
1748 return NULL;
1751 last = ngx_copy(path->data, clcf->root.data, clcf->root.len);
1753 } else {
1755 #if (NGX_PCRE)
1756 ngx_uint_t captures;
1758 captures = alias && clcf->regex;
1759 reserved += captures ? 1 : r->uri.len - alias + 1;
1760 #else
1761 reserved += r->uri.len - alias + 1;
1762 #endif
1764 if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved,
1765 clcf->root_values->elts)
1766 == NULL)
1768 return NULL;
1771 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, path, 0) != NGX_OK) {
1772 return NULL;
1775 *root_length = path->len - reserved;
1776 last = path->data + *root_length;
1778 #if (NGX_PCRE)
1779 if (captures) {
1780 *last = '\0';
1781 return last;
1783 #endif
1786 last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1);
1788 return last;
1792 ngx_int_t
1793 ngx_http_auth_basic_user(ngx_http_request_t *r)
1795 ngx_str_t auth, encoded;
1796 ngx_uint_t len;
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)
1812 != 0)
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] == ' ') {
1822 encoded.len--;
1823 encoded.data++;
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) {
1834 return NGX_ERROR;
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] == ':') {
1846 break;
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];
1860 return NGX_OK;
1864 #if (NGX_HTTP_GZIP)
1866 ngx_int_t
1867 ngx_http_gzip_ok(ngx_http_request_t *r)
1869 time_t date, expires;
1870 ngx_uint_t p;
1871 ngx_array_t *cc;
1872 ngx_table_elt_t *e, *d;
1873 ngx_http_core_loc_conf_t *clcf;
1875 r->gzip_tested = 1;
1877 if (r != r->main
1878 || r->headers_in.accept_encoding == NULL
1879 || ngx_strcasestrn(r->headers_in.accept_encoding->value.data,
1880 "gzip", 4 - 1)
1881 == NULL
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) {
1905 goto ok;
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) {
1915 goto ok;
1918 if (r->headers_in.authorization && (p & NGX_HTTP_GZIP_PROXIED_AUTH)) {
1919 goto ok;
1922 e = r->headers_out.expires;
1924 if (e) {
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;
1937 if (d) {
1938 date = ngx_http_parse_time(d->value.data, d->value.len);
1939 if (date == NGX_ERROR) {
1940 return NGX_DECLINED;
1943 } else {
1944 date = ngx_time();
1947 if (expires < date) {
1948 goto ok;
1951 return NGX_DECLINED;
1954 cc = &r->headers_out.cache_control;
1956 if (cc->elts) {
1958 if ((p & NGX_HTTP_GZIP_PROXIED_NO_CACHE)
1959 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_cache,
1960 NULL)
1961 >= 0)
1963 goto ok;
1966 if ((p & NGX_HTTP_GZIP_PROXIED_NO_STORE)
1967 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_store,
1968 NULL)
1969 >= 0)
1971 goto ok;
1974 if ((p & NGX_HTTP_GZIP_PROXIED_PRIVATE)
1975 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_private,
1976 NULL)
1977 >= 0)
1979 goto ok;
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;
1995 #if (NGX_PCRE)
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,
2001 r->connection->log)
2002 != NGX_DECLINED)
2004 return NGX_DECLINED;
2008 #endif
2010 r->gzip_ok = 1;
2012 return NGX_OK;
2015 #endif
2018 ngx_int_t
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;
2034 return NGX_ERROR;
2037 sr = ngx_pcalloc(r->pool, sizeof(ngx_http_request_t));
2038 if (sr == NULL) {
2039 return NGX_ERROR;
2042 sr->signature = NGX_HTTP_MODULE;
2044 c = r->connection;
2045 sr->connection = c;
2047 sr->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
2048 if (sr->ctx == NULL) {
2049 return NGX_ERROR;
2052 if (ngx_list_init(&sr->headers_out.headers, r->pool, 20,
2053 sizeof(ngx_table_elt_t))
2054 != NGX_OK)
2056 return NGX_ERROR;
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;
2064 sr->pool = r->pool;
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;
2078 sr->uri = *uri;
2080 if (args) {
2081 sr->args = *args;
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);
2097 sr->main = r->main;
2098 sr->parent = r;
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) {
2104 c->data = sr;
2107 sr->variables = r->variables;
2109 sr->log_handler = r->log_handler;
2111 pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t));
2112 if (pr == NULL) {
2113 return NGX_ERROR;
2116 pr->request = sr;
2117 pr->out = NULL;
2118 pr->next = NULL;
2120 if (r->postponed) {
2121 for (p = r->postponed; p->next; p = p->next) { /* void */ }
2122 p->next = pr;
2124 } else {
2125 r->postponed = pr;
2128 sr->internal = 1;
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++;
2137 r->main->count++;
2139 *psr = sr;
2141 return ngx_http_post_request(sr, NULL);
2145 ngx_int_t
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;
2151 r->uri_changes--;
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);
2158 r->main->count++;
2159 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
2160 return NGX_DONE;
2163 r->uri = *uri;
2165 if (args) {
2166 r->args = *args;
2168 } else {
2169 r->args.len = 0;
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)
2187 r->cache = NULL;
2188 #endif
2190 r->internal = 1;
2191 r->main->count++;
2193 ngx_http_handler(r);
2195 return NGX_DONE;
2199 ngx_int_t
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;
2206 r->main->count++;
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)
2220 continue;
2223 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2224 "using location: %V \"%V?%V\"",
2225 name, &r->uri, &r->args);
2227 r->internal = 1;
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);
2239 return NGX_DONE;
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);
2248 return NGX_DONE;
2252 ngx_http_cleanup_t *
2253 ngx_http_cleanup_add(ngx_http_request_t *r, size_t size)
2255 ngx_http_cleanup_t *cln;
2257 r = r->main;
2259 cln = ngx_palloc(r->pool, sizeof(ngx_http_cleanup_t));
2260 if (cln == NULL) {
2261 return NULL;
2264 if (size) {
2265 cln->data = ngx_palloc(r->pool, size);
2266 if (cln->data == NULL) {
2267 return NULL;
2270 } else {
2271 cln->data = NULL;
2274 cln->handler = NULL;
2275 cln->next = r->cleanup;
2277 r->cleanup = cln;
2279 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2280 "http cleanup add: %p", cln);
2282 return cln;
2286 static char *
2287 ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
2289 char *rv;
2290 void *mconf;
2291 ngx_uint_t i;
2292 ngx_conf_t pcf;
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));
2299 if (ctx == NULL) {
2300 return NGX_CONF_ERROR;
2303 http_ctx = cf->ctx;
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) {
2322 continue;
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];
2350 cscf->ctx = ctx;
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;
2360 *cscfp = cscf;
2363 /* parse inside server{} */
2365 pcf = *cf;
2366 cf->ctx = ctx;
2367 cf->cmd_type = NGX_HTTP_SRV_CONF;
2369 rv = ngx_conf_parse(cf, NULL);
2371 *cf = pcf;
2373 return rv;
2377 static char *
2378 ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
2380 char *rv;
2381 u_char *mod;
2382 size_t len;
2383 ngx_str_t *value, *name;
2384 ngx_uint_t i;
2385 ngx_conf_t save;
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));
2391 if (ctx == NULL) {
2392 return NGX_CONF_ERROR;
2395 pctx = cf->ctx;
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) {
2406 continue;
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) {
2427 len = value[1].len;
2428 mod = value[1].data;
2429 name = &value[2];
2431 if (len == 1 && mod[0] == '=') {
2433 clcf->name = *name;
2434 clcf->exact_match = 1;
2436 } else if (len == 2 && mod[0] == '^' && mod[1] == '~') {
2438 clcf->name = *name;
2439 clcf->noregex = 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;
2453 } else {
2454 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2455 "invalid location modifier \"%V\"", &value[1]);
2456 return NGX_CONF_ERROR;
2459 } else {
2461 name = &value[1];
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;
2473 clcf->noregex = 1;
2475 } else if (name->data[0] == '~') {
2477 name->len--;
2478 name->data++;
2480 if (name->data[0] == '*') {
2482 name->len--;
2483 name->data++;
2485 if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
2486 return NGX_CONF_ERROR;
2489 } else {
2490 if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
2491 return NGX_CONF_ERROR;
2495 } else {
2497 clcf->name = *name;
2499 if (name->data[0] == '@') {
2500 clcf->named = 1;
2505 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
2507 if (pclcf->name.len) {
2509 /* nested location */
2511 #if 0
2512 clcf->prev_location = pclcf;
2513 #endif
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;
2523 if (pclcf->named) {
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;
2531 if (clcf->named) {
2532 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2533 "named location \"%V\" must be "
2534 "on server level only",
2535 &clcf->name);
2536 return NGX_CONF_ERROR;
2539 len = pclcf->name.len;
2541 #if (NGX_PCRE)
2542 if (clcf->regex == NULL
2543 && ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0)
2544 #else
2545 if (ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0)
2546 #endif
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;
2559 save = *cf;
2560 cf->ctx = ctx;
2561 cf->cmd_type = NGX_HTTP_LOC_CONF;
2563 rv = ngx_conf_parse(cf, NULL);
2565 *cf = save;
2567 return rv;
2571 static ngx_int_t
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)
2575 #if (NGX_PCRE)
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;
2587 #endif
2589 clcf->regex = ngx_http_regex_compile(cf, &rc);
2590 if (clcf->regex == NULL) {
2591 return NGX_ERROR;
2594 clcf->name = *regex;
2596 return NGX_OK;
2598 #else
2600 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2601 "the using of the regex \"%V\" requires PCRE library",
2602 regex);
2603 return NGX_ERROR;
2605 #endif
2609 static char *
2610 ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2612 ngx_http_core_loc_conf_t *clcf = conf;
2614 char *rv;
2615 ngx_conf_t save;
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;
2624 save = *cf;
2625 cf->handler = ngx_http_core_type;
2626 cf->handler_conf = conf;
2628 rv = ngx_conf_parse(cf, NULL);
2630 *cf = save;
2632 return rv;
2636 static char *
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) {
2648 file = value[1];
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);
2681 continue;
2686 type = ngx_array_push(clcf->types);
2687 if (type == NULL) {
2688 return NGX_CONF_ERROR;
2691 type->key = value[i];
2692 type->key_hash = hash;
2693 type->value = content_type;
2696 return NGX_CONF_OK;
2700 static ngx_int_t
2701 ngx_http_core_preconfiguration(ngx_conf_t *cf)
2703 return ngx_http_variables_add_core_vars(cf);
2707 static void *
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));
2713 if (cmcf == NULL) {
2714 return NULL;
2717 if (ngx_array_init(&cmcf->servers, cf->pool, 4,
2718 sizeof(ngx_http_core_srv_conf_t *))
2719 != NGX_OK)
2721 return NULL;
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;
2730 return cmcf;
2734 static char *
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;
2766 return NGX_CONF_OK;
2770 static void *
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));
2776 if (cscf == NULL) {
2777 return NULL;
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))
2788 != NGX_OK)
2790 return NULL;
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;
2801 return cscf;
2805 static char *
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,
2827 4, ngx_pagesize);
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;
2850 #if (NGX_WIN32)
2851 sin->sin_port = htons(80);
2852 #else
2853 sin->sin_port = htons((getuid() == 0) ? 80 : 8000);
2854 #endif
2855 sin->sin_addr.s_addr = INADDR_ANY;
2857 lsopt.socklen = sizeof(struct sockaddr_in);
2859 lsopt.backlog = NGX_LISTEN_BACKLOG;
2860 lsopt.rcvbuf = -1;
2861 lsopt.sndbuf = -1;
2862 lsopt.wildcard = 1;
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) {
2868 return NGX_CONF_OK;
2872 if (conf->server_name.data == NULL) {
2873 conf->server_name = cf->cycle->hostname;
2875 sn = ngx_array_push(&conf->server_names);
2876 if (sn == NULL) {
2877 return NGX_CONF_ERROR;
2880 #if (NGX_PCRE)
2881 sn->regex = NULL;
2882 #endif
2883 sn->server = conf;
2884 sn->name.len = conf->server_name.len;
2885 sn->name.data = conf->server_name.data;
2888 return NGX_CONF_OK;
2892 static void *
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));
2898 if (clcf == NULL) {
2899 return NULL;
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;
2917 * clcf->alias = 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;
2933 #endif
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;
2968 #if (NGX_HTTP_GZIP)
2969 clcf->gzip_vary = NGX_CONF_UNSET;
2970 clcf->gzip_http_version = NGX_CONF_UNSET_UINT;
2971 #if (NGX_PCRE)
2972 clcf->gzip_disable = NGX_CONF_UNSET_PTR;
2973 clcf->gzip_disable_msie6 = 3;
2974 #endif
2975 #endif
2977 return clcf;
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 }
2993 static char *
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;
2999 ngx_uint_t i;
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)
3050 != NGX_OK)
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);
3069 if (type == NULL) {
3070 return NGX_CONF_ERROR;
3073 type->key = ngx_http_core_default_types[i].key;
3074 type->key_hash =
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)
3092 != NGX_OK)
3094 return NGX_CONF_ERROR;
3098 if (conf->error_log == NULL) {
3099 if (prev->error_log) {
3100 conf->error_log = prev->error_log;
3101 } else {
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);
3135 #endif
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,
3140 512);
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,
3147 1460);
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)
3185 != NGX_OK)
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);
3217 #if (NGX_HTTP_GZIP)
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));
3225 #if (NGX_PCRE)
3226 ngx_conf_merge_ptr_value(conf->gzip_disable, prev->gzip_disable, NULL);
3227 #endif
3229 if (conf->gzip_disable_msie6 == 3) {
3230 conf->gzip_disable_msie6 =
3231 (prev->gzip_disable_msie6 == 3) ? 0 : prev->gzip_disable_msie6;
3234 #endif
3236 return NGX_CONF_OK;
3240 static char *
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;
3246 ngx_url_t u;
3247 ngx_uint_t n;
3248 ngx_http_listen_opt_t lsopt;
3250 cscf->listen = 1;
3252 value = cf->args->elts;
3254 ngx_memzero(&u, sizeof(ngx_url_t));
3256 u.url = value[1];
3257 u.listen = 1;
3258 u.default_port = 80;
3260 if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
3261 if (u.err) {
3262 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3263 "%s in \"%V\" of the \"listen\" directive",
3264 u.err, &u.url);
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;
3276 lsopt.rcvbuf = -1;
3277 lsopt.sndbuf = -1;
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;
3289 continue;
3292 if (ngx_strcmp(value[n].data, "bind") == 0) {
3293 lsopt.set = 1;
3294 lsopt.bind = 1;
3295 continue;
3298 if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) {
3299 lsopt.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8);
3300 lsopt.set = 1;
3301 lsopt.bind = 1;
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;
3309 continue;
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);
3317 lsopt.set = 1;
3318 lsopt.bind = 1;
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;
3326 continue;
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);
3334 lsopt.set = 1;
3335 lsopt.bind = 1;
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;
3343 continue;
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];
3349 lsopt.set = 1;
3350 lsopt.bind = 1;
3351 #else
3352 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3353 "accept filters \"%V\" are not supported "
3354 "on this platform, ignored",
3355 &value[n]);
3356 #endif
3357 continue;
3360 if (ngx_strcmp(value[n].data, "deferred") == 0) {
3361 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
3362 lsopt.deferred_accept = 1;
3363 lsopt.set = 1;
3364 lsopt.bind = 1;
3365 #else
3366 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3367 "the deferred accept is not supported "
3368 "on this platform, ignored");
3369 #endif
3370 continue;
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) {
3382 lsopt.ipv6only = 1;
3384 } else if (ngx_strcmp(&value[n].data[10], "ff") == 0) {
3385 lsopt.ipv6only = 2;
3387 } else {
3388 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3389 "invalid ipv6only flags \"%s\"",
3390 &value[n].data[9]);
3391 return NGX_CONF_ERROR;
3394 lsopt.set = 1;
3395 lsopt.bind = 1;
3397 } else {
3398 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3399 "ipv6only is not supported "
3400 "on addr \"%s\", ignored", lsopt.addr);
3403 continue;
3404 #else
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;
3409 #endif
3412 if (ngx_strcmp(value[n].data, "ssl") == 0) {
3413 #if (NGX_HTTP_SSL)
3414 lsopt.set = 1;
3415 lsopt.ssl = 1;
3416 continue;
3417 #else
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;
3422 #endif
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) {
3431 return NGX_CONF_OK;
3434 return NGX_CONF_ERROR;
3438 static char *
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;
3443 u_char ch;
3444 ngx_str_t *value, name;
3445 ngx_uint_t i;
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) {
3453 if (value[1].len) {
3454 name = value[1];
3456 if (ch == '.') {
3457 name.len--;
3458 name.data++;
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;
3467 } else {
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",
3489 &value[i]);
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);
3500 if (sn == NULL) {
3501 return NGX_CONF_ERROR;
3504 #if (NGX_PCRE)
3505 sn->regex = NULL;
3506 #endif
3507 sn->server = cscf;
3508 sn->name = value[i];
3510 ngx_strlow(sn->name.data, sn->name.data, sn->name.len);
3512 if (value[i].data[0] != '~') {
3513 continue;
3516 #if (NGX_PCRE)
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;
3527 value[i].len--;
3528 value[i].data++;
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);
3544 #else
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;
3550 #endif
3553 return NGX_CONF_OK;
3557 static char *
3558 ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3560 ngx_http_core_loc_conf_t *clcf = conf;
3562 ngx_str_t *value;
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",
3575 &cmd->name);
3576 } else {
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",
3602 &cmd->name);
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",
3613 &cmd->name);
3615 return NGX_CONF_ERROR;
3618 clcf->alias = alias;
3619 clcf->root = value[1];
3621 if (!alias && clcf->root.data[clcf->root.len - 1] == '/') {
3622 clcf->root.len--;
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));
3635 if (n) {
3636 sc.cf = cf;
3637 sc.source = &clcf->root;
3638 sc.lengths = &clcf->root_lengths;
3639 sc.values = &clcf->root_values;
3640 sc.variables = n;
3641 sc.complete_lengths = 1;
3642 sc.complete_values = 1;
3644 if (ngx_http_script_compile(&sc) != NGX_OK) {
3645 return NGX_CONF_ERROR;
3649 return NGX_CONF_OK;
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 },
3667 { NULL, 0 }
3671 static char *
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;
3676 char *rv;
3677 void *mconf;
3678 ngx_str_t *value;
3679 ngx_uint_t i;
3680 ngx_conf_t save;
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) {
3687 return "duplicate";
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;
3699 goto next;
3703 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3704 "invalid method \"%V\"", &value[i]);
3705 return NGX_CONF_ERROR;
3707 next:
3708 continue;
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));
3716 if (ctx == NULL) {
3717 return NGX_CONF_ERROR;
3720 pctx = cf->ctx;
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) {
3731 continue;
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;
3752 clcf->noname = 1;
3754 if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
3755 return NGX_CONF_ERROR;
3758 save = *cf;
3759 cf->ctx = ctx;
3760 cf->cmd_type = NGX_HTTP_LMT_CONF;
3762 rv = ngx_conf_parse(cf, NULL);
3764 *cf = save;
3766 return rv;
3770 static char *
3771 ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3773 ngx_http_core_loc_conf_t *clcf = conf;
3775 ngx_str_t *value;
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;
3785 return NGX_CONF_OK;
3788 clcf->directio = ngx_parse_offset(&value[1]);
3789 if (clcf->directio == (off_t) NGX_ERROR) {
3790 return "invalid value";
3793 return NGX_CONF_OK;
3797 static char *
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;
3802 u_char *p;
3803 ngx_int_t overwrite;
3804 ngx_str_t *value, uri, args;
3805 ngx_uint_t i, n;
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] == '=') {
3823 if (i == 1) {
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;
3838 } else {
3839 overwrite = 0;
3842 n = 2;
3844 } else {
3845 overwrite = -1;
3846 n = 1;
3849 uri = value[cf->args->nelts - 1];
3851 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
3853 ccv.cf = cf;
3854 ccv.value = &uri;
3855 ccv.complex_value = &cv;
3857 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
3858 return NGX_CONF_ERROR;
3861 args.len = 0;
3862 args.data = NULL;
3864 if (cv.lengths == NULL && uri.data[0] == '/') {
3865 p = (u_char *) ngx_strchr(uri.data, '?');
3867 if (p) {
3868 cv.value.len = p - uri.data;
3869 cv.value.data = uri.data;
3870 p++;
3871 args.len = (uri.data + uri.len) - p;
3872 args.data = p;
3876 for (i = 1; i < cf->args->nelts - n; i++) {
3877 err = ngx_array_push(clcf->error_pages);
3878 if (err == NULL) {
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",
3893 &value[i]);
3894 return NGX_CONF_ERROR;
3897 if (overwrite >= 0) {
3898 err->overwrite = overwrite;
3900 } else {
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;
3906 break;
3908 default:
3909 err->overwrite = err->status;
3910 break;
3914 err->value = cv;
3915 err->args = args;
3918 return NGX_CONF_OK;
3922 static char *
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;
3927 ngx_str_t *value;
3928 ngx_int_t code;
3929 ngx_uint_t i, n;
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));
3943 if (tf == NULL) {
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] == '/') {
3956 tf[i].test_dir = 1;
3957 tf[i].name.len--;
3958 tf[i].name.data[tf[i].name.len] = '\0';
3961 n = ngx_http_script_variables_count(&tf[i].name);
3963 if (n) {
3964 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
3966 sc.cf = cf;
3967 sc.source = &tf[i].name;
3968 sc.lengths = &tf[i].lengths;
3969 sc.values = &tf[i].values;
3970 sc.variables = n;
3971 sc.complete_lengths = 1;
3972 sc.complete_values = 1;
3974 if (ngx_http_script_compile(&sc) != NGX_OK) {
3975 return NGX_CONF_ERROR;
3978 } else {
3979 /* add trailing '\0' to length */
3980 tf[i].name.len++;
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;
3995 tf[i].code = code;
3998 return NGX_CONF_OK;
4002 static char *
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;
4007 time_t inactive;
4008 ngx_str_t *value, s;
4009 ngx_int_t max;
4010 ngx_uint_t i;
4012 if (clcf->open_file_cache != NGX_CONF_UNSET_PTR) {
4013 return "is duplicate";
4016 value = cf->args->elts;
4018 max = 0;
4019 inactive = 60;
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) {
4027 goto failed;
4030 continue;
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);
4039 if (inactive < 0) {
4040 goto failed;
4043 continue;
4046 if (ngx_strcmp(value[i].data, "off") == 0) {
4048 clcf->open_file_cache = NULL;
4050 continue;
4053 failed:
4055 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4056 "invalid \"open_file_cache\" parameter \"%V\"",
4057 &value[i]);
4058 return NGX_CONF_ERROR;
4061 if (clcf->open_file_cache == NULL) {
4062 return NGX_CONF_OK;
4065 if (max == 0) {
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) {
4073 return NGX_CONF_OK;
4076 return NGX_CONF_ERROR;
4080 static char *
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;
4085 ngx_str_t *value;
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;
4100 return NGX_CONF_OK;
4103 return ngx_log_set_levels(cf, clcf->error_log);
4107 static char *
4108 ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4110 ngx_http_core_loc_conf_t *clcf = conf;
4112 ngx_str_t *value;
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) {
4131 return NGX_CONF_OK;
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";
4144 return NGX_CONF_OK;
4148 static char *
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";
4157 clcf->internal = 1;
4159 return NGX_CONF_OK;
4163 static char *
4164 ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4166 ngx_http_core_loc_conf_t *clcf = conf;
4168 ngx_url_t u;
4169 ngx_str_t *value;
4171 if (clcf->resolver) {
4172 return "is duplicate";
4175 value = cf->args->elts;
4177 ngx_memzero(&u, sizeof(ngx_url_t));
4179 u.host = value[1];
4180 u.port = 53;
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) {
4189 return NGX_OK;
4192 return NGX_CONF_OK;
4196 #if (NGX_HTTP_GZIP)
4198 static char *
4199 ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4201 ngx_http_core_loc_conf_t *clcf = conf;
4203 #if (NGX_PCRE)
4205 ngx_str_t *value;
4206 ngx_uint_t i;
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));
4223 rc.pool = cf->pool;
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;
4231 continue;
4234 re = ngx_array_push(clcf->gzip_disable);
4235 if (re == NULL) {
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;
4251 return NGX_CONF_OK;
4253 #else
4254 ngx_str_t *value;
4256 value = cf->args->elts;
4258 if (cf->args->nelts == 2 && ngx_strcmp(value[1].data, "msie6") == 0) {
4259 clcf->gzip_disable_msie6 = 1;
4260 return NGX_CONF_OK;
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;
4268 #endif
4271 #endif
4274 static char *
4275 ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data)
4277 #if (NGX_FREEBSD)
4278 ssize_t *np = 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)
4290 ssize_t *np = data;
4292 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
4293 "\"send_lowat\" is not supported, ignored");
4295 *np = 0;
4297 #endif
4299 return NGX_CONF_OK;
4303 static char *
4304 ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data)
4306 size_t *sp = 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;
4315 return NGX_CONF_OK;