3 * Copyright (C) Igor Sysoev
7 #include <ngx_config.h>
17 } ngx_http_method_name_t
;
20 #define NGX_HTTP_REQUEST_BODY_FILE_OFF 0
21 #define NGX_HTTP_REQUEST_BODY_FILE_ON 1
22 #define NGX_HTTP_REQUEST_BODY_FILE_CLEAN 2
25 static ngx_int_t
ngx_http_core_find_location(ngx_http_request_t
*r
);
26 static ngx_int_t
ngx_http_core_find_static_location(ngx_http_request_t
*r
,
27 ngx_http_location_tree_node_t
*node
);
28 static ngx_int_t
ngx_http_core_send_continue(ngx_http_request_t
*r
);
30 static ngx_int_t
ngx_http_core_preconfiguration(ngx_conf_t
*cf
);
31 static void *ngx_http_core_create_main_conf(ngx_conf_t
*cf
);
32 static char *ngx_http_core_init_main_conf(ngx_conf_t
*cf
, void *conf
);
33 static void *ngx_http_core_create_srv_conf(ngx_conf_t
*cf
);
34 static char *ngx_http_core_merge_srv_conf(ngx_conf_t
*cf
,
35 void *parent
, void *child
);
36 static void *ngx_http_core_create_loc_conf(ngx_conf_t
*cf
);
37 static char *ngx_http_core_merge_loc_conf(ngx_conf_t
*cf
,
38 void *parent
, void *child
);
40 static char *ngx_http_core_server(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
42 static char *ngx_http_core_location(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
45 static char *ngx_http_core_types(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
47 static char *ngx_http_core_type(ngx_conf_t
*cf
, ngx_command_t
*dummy
,
50 static char *ngx_http_core_listen(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
52 static char *ngx_http_core_server_name(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
54 static char *ngx_http_core_root(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
);
55 static char *ngx_http_core_limit_except(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
57 static char *ngx_http_core_directio(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
59 static char *ngx_http_core_error_page(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
61 static char *ngx_http_core_open_file_cache(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
63 static char *ngx_http_core_error_log(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
65 static char *ngx_http_core_keepalive(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
67 static char *ngx_http_core_internal(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
69 static char *ngx_http_core_resolver(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
72 static char *ngx_http_gzip_disable(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
76 static char *ngx_http_core_lowat_check(ngx_conf_t
*cf
, void *post
, void *data
);
77 static char *ngx_http_core_pool_size(ngx_conf_t
*cf
, void *post
, void *data
);
79 static ngx_conf_post_t ngx_http_core_lowat_post
=
80 { ngx_http_core_lowat_check
};
82 static ngx_conf_post_handler_pt ngx_http_core_pool_size_p
=
83 ngx_http_core_pool_size
;
85 static ngx_conf_deprecated_t ngx_conf_deprecated_optimize_server_names
= {
86 ngx_conf_deprecated
, "optimize_server_names", "server_name_in_redirect"
89 static ngx_conf_deprecated_t ngx_conf_deprecated_open_file_cache_retest
= {
90 ngx_conf_deprecated
, "open_file_cache_retest", "open_file_cache_valid"
93 static ngx_conf_deprecated_t ngx_conf_deprecated_satisfy_any
= {
94 ngx_conf_deprecated
, "satisfy_any", "satisfy"
98 static ngx_conf_enum_t ngx_http_core_request_body_in_file
[] = {
99 { ngx_string("off"), NGX_HTTP_REQUEST_BODY_FILE_OFF
},
100 { ngx_string("on"), NGX_HTTP_REQUEST_BODY_FILE_ON
},
101 { ngx_string("clean"), NGX_HTTP_REQUEST_BODY_FILE_CLEAN
},
102 { ngx_null_string
, 0 }
106 static ngx_conf_enum_t ngx_http_core_satisfy
[] = {
107 { ngx_string("all"), NGX_HTTP_SATISFY_ALL
},
108 { ngx_string("any"), NGX_HTTP_SATISFY_ANY
},
109 { ngx_null_string
, 0 }
115 static ngx_conf_enum_t ngx_http_gzip_http_version
[] = {
116 { ngx_string("1.0"), NGX_HTTP_VERSION_10
},
117 { ngx_string("1.1"), NGX_HTTP_VERSION_11
},
118 { ngx_null_string
, 0 }
122 static ngx_conf_bitmask_t ngx_http_gzip_proxied_mask
[] = {
123 { ngx_string("off"), NGX_HTTP_GZIP_PROXIED_OFF
},
124 { ngx_string("expired"), NGX_HTTP_GZIP_PROXIED_EXPIRED
},
125 { ngx_string("no-cache"), NGX_HTTP_GZIP_PROXIED_NO_CACHE
},
126 { ngx_string("no-store"), NGX_HTTP_GZIP_PROXIED_NO_STORE
},
127 { ngx_string("private"), NGX_HTTP_GZIP_PROXIED_PRIVATE
},
128 { ngx_string("no_last_modified"), NGX_HTTP_GZIP_PROXIED_NO_LM
},
129 { ngx_string("no_etag"), NGX_HTTP_GZIP_PROXIED_NO_ETAG
},
130 { ngx_string("auth"), NGX_HTTP_GZIP_PROXIED_AUTH
},
131 { ngx_string("any"), NGX_HTTP_GZIP_PROXIED_ANY
},
132 { ngx_null_string
, 0 }
136 static ngx_str_t ngx_http_gzip_no_cache
= ngx_string("no-cache");
137 static ngx_str_t ngx_http_gzip_no_store
= ngx_string("no-store");
138 static ngx_str_t ngx_http_gzip_private
= ngx_string("private");
143 static ngx_command_t ngx_http_core_commands
[] = {
145 { ngx_string("variables_hash_max_size"),
146 NGX_HTTP_MAIN_CONF
|NGX_CONF_TAKE1
,
147 ngx_conf_set_num_slot
,
148 NGX_HTTP_MAIN_CONF_OFFSET
,
149 offsetof(ngx_http_core_main_conf_t
, variables_hash_max_size
),
152 { ngx_string("variables_hash_bucket_size"),
153 NGX_HTTP_MAIN_CONF
|NGX_CONF_TAKE1
,
154 ngx_conf_set_num_slot
,
155 NGX_HTTP_MAIN_CONF_OFFSET
,
156 offsetof(ngx_http_core_main_conf_t
, variables_hash_bucket_size
),
159 { ngx_string("server_names_hash_max_size"),
160 NGX_HTTP_MAIN_CONF
|NGX_CONF_TAKE1
,
161 ngx_conf_set_num_slot
,
162 NGX_HTTP_MAIN_CONF_OFFSET
,
163 offsetof(ngx_http_core_main_conf_t
, server_names_hash_max_size
),
166 { ngx_string("server_names_hash_bucket_size"),
167 NGX_HTTP_MAIN_CONF
|NGX_CONF_TAKE1
,
168 ngx_conf_set_num_slot
,
169 NGX_HTTP_MAIN_CONF_OFFSET
,
170 offsetof(ngx_http_core_main_conf_t
, server_names_hash_bucket_size
),
173 { ngx_string("server"),
174 NGX_HTTP_MAIN_CONF
|NGX_CONF_BLOCK
|NGX_CONF_MULTI
|NGX_CONF_NOARGS
,
175 ngx_http_core_server
,
180 { ngx_string("connection_pool_size"),
181 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_TAKE1
,
182 ngx_conf_set_size_slot
,
183 NGX_HTTP_SRV_CONF_OFFSET
,
184 offsetof(ngx_http_core_srv_conf_t
, connection_pool_size
),
185 &ngx_http_core_pool_size_p
},
187 { ngx_string("request_pool_size"),
188 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_TAKE1
,
189 ngx_conf_set_size_slot
,
190 NGX_HTTP_SRV_CONF_OFFSET
,
191 offsetof(ngx_http_core_srv_conf_t
, request_pool_size
),
192 &ngx_http_core_pool_size_p
},
194 { ngx_string("client_header_timeout"),
195 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_TAKE1
,
196 ngx_conf_set_msec_slot
,
197 NGX_HTTP_SRV_CONF_OFFSET
,
198 offsetof(ngx_http_core_srv_conf_t
, client_header_timeout
),
201 { ngx_string("client_header_buffer_size"),
202 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_TAKE1
,
203 ngx_conf_set_size_slot
,
204 NGX_HTTP_SRV_CONF_OFFSET
,
205 offsetof(ngx_http_core_srv_conf_t
, client_header_buffer_size
),
208 { ngx_string("large_client_header_buffers"),
209 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_TAKE2
,
210 ngx_conf_set_bufs_slot
,
211 NGX_HTTP_SRV_CONF_OFFSET
,
212 offsetof(ngx_http_core_srv_conf_t
, large_client_header_buffers
),
215 { ngx_string("optimize_server_names"),
216 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_FLAG
,
217 ngx_conf_set_flag_slot
,
218 NGX_HTTP_LOC_CONF_OFFSET
,
219 offsetof(ngx_http_core_loc_conf_t
, server_name_in_redirect
),
220 &ngx_conf_deprecated_optimize_server_names
},
222 { ngx_string("ignore_invalid_headers"),
223 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_FLAG
,
224 ngx_conf_set_flag_slot
,
225 NGX_HTTP_SRV_CONF_OFFSET
,
226 offsetof(ngx_http_core_srv_conf_t
, ignore_invalid_headers
),
229 { ngx_string("merge_slashes"),
230 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_FLAG
,
231 ngx_conf_set_flag_slot
,
232 NGX_HTTP_SRV_CONF_OFFSET
,
233 offsetof(ngx_http_core_srv_conf_t
, merge_slashes
),
236 { ngx_string("location"),
237 NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_BLOCK
|NGX_CONF_TAKE12
,
238 ngx_http_core_location
,
239 NGX_HTTP_SRV_CONF_OFFSET
,
243 { ngx_string("listen"),
244 NGX_HTTP_SRV_CONF
|NGX_CONF_1MORE
,
245 ngx_http_core_listen
,
246 NGX_HTTP_SRV_CONF_OFFSET
,
250 { ngx_string("server_name"),
251 NGX_HTTP_SRV_CONF
|NGX_CONF_1MORE
,
252 ngx_http_core_server_name
,
253 NGX_HTTP_SRV_CONF_OFFSET
,
257 { ngx_string("types_hash_max_size"),
258 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
259 ngx_conf_set_num_slot
,
260 NGX_HTTP_LOC_CONF_OFFSET
,
261 offsetof(ngx_http_core_loc_conf_t
, types_hash_max_size
),
264 { ngx_string("types_hash_bucket_size"),
265 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
266 ngx_conf_set_num_slot
,
267 NGX_HTTP_LOC_CONF_OFFSET
,
268 offsetof(ngx_http_core_loc_conf_t
, types_hash_bucket_size
),
271 { ngx_string("types"),
272 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
273 |NGX_CONF_BLOCK
|NGX_CONF_NOARGS
,
275 NGX_HTTP_LOC_CONF_OFFSET
,
279 { ngx_string("default_type"),
280 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
281 ngx_conf_set_str_slot
,
282 NGX_HTTP_LOC_CONF_OFFSET
,
283 offsetof(ngx_http_core_loc_conf_t
, default_type
),
286 { ngx_string("root"),
287 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_HTTP_LIF_CONF
290 NGX_HTTP_LOC_CONF_OFFSET
,
294 { ngx_string("alias"),
295 NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
297 NGX_HTTP_LOC_CONF_OFFSET
,
301 { ngx_string("limit_except"),
302 NGX_HTTP_LOC_CONF
|NGX_CONF_BLOCK
|NGX_CONF_1MORE
,
303 ngx_http_core_limit_except
,
304 NGX_HTTP_LOC_CONF_OFFSET
,
308 { ngx_string("client_max_body_size"),
309 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
310 ngx_conf_set_off_slot
,
311 NGX_HTTP_LOC_CONF_OFFSET
,
312 offsetof(ngx_http_core_loc_conf_t
, client_max_body_size
),
315 { ngx_string("client_body_buffer_size"),
316 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
317 ngx_conf_set_size_slot
,
318 NGX_HTTP_LOC_CONF_OFFSET
,
319 offsetof(ngx_http_core_loc_conf_t
, client_body_buffer_size
),
322 { ngx_string("client_body_timeout"),
323 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
324 ngx_conf_set_msec_slot
,
325 NGX_HTTP_LOC_CONF_OFFSET
,
326 offsetof(ngx_http_core_loc_conf_t
, client_body_timeout
),
329 { ngx_string("client_body_temp_path"),
330 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1234
,
331 ngx_conf_set_path_slot
,
332 NGX_HTTP_LOC_CONF_OFFSET
,
333 offsetof(ngx_http_core_loc_conf_t
, client_body_temp_path
),
334 (void *) ngx_garbage_collector_temp_handler
},
336 { ngx_string("client_body_in_file_only"),
337 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
338 ngx_conf_set_enum_slot
,
339 NGX_HTTP_LOC_CONF_OFFSET
,
340 offsetof(ngx_http_core_loc_conf_t
, client_body_in_file_only
),
341 &ngx_http_core_request_body_in_file
},
343 { ngx_string("sendfile"),
344 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_HTTP_LIF_CONF
346 ngx_conf_set_flag_slot
,
347 NGX_HTTP_LOC_CONF_OFFSET
,
348 offsetof(ngx_http_core_loc_conf_t
, sendfile
),
351 { ngx_string("sendfile_max_chunk"),
352 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
353 ngx_conf_set_size_slot
,
354 NGX_HTTP_LOC_CONF_OFFSET
,
355 offsetof(ngx_http_core_loc_conf_t
, sendfile_max_chunk
),
358 { ngx_string("directio"),
359 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
360 ngx_http_core_directio
,
361 NGX_HTTP_LOC_CONF_OFFSET
,
365 { ngx_string("tcp_nopush"),
366 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
367 ngx_conf_set_flag_slot
,
368 NGX_HTTP_LOC_CONF_OFFSET
,
369 offsetof(ngx_http_core_loc_conf_t
, tcp_nopush
),
372 { ngx_string("tcp_nodelay"),
373 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
374 ngx_conf_set_flag_slot
,
375 NGX_HTTP_LOC_CONF_OFFSET
,
376 offsetof(ngx_http_core_loc_conf_t
, tcp_nodelay
),
379 { ngx_string("send_timeout"),
380 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
381 ngx_conf_set_msec_slot
,
382 NGX_HTTP_LOC_CONF_OFFSET
,
383 offsetof(ngx_http_core_loc_conf_t
, send_timeout
),
386 { ngx_string("send_lowat"),
387 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
388 ngx_conf_set_size_slot
,
389 NGX_HTTP_LOC_CONF_OFFSET
,
390 offsetof(ngx_http_core_loc_conf_t
, send_lowat
),
391 &ngx_http_core_lowat_post
},
393 { ngx_string("postpone_output"),
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
, postpone_output
),
400 { ngx_string("limit_rate"),
401 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_HTTP_LIF_CONF
403 ngx_conf_set_size_slot
,
404 NGX_HTTP_LOC_CONF_OFFSET
,
405 offsetof(ngx_http_core_loc_conf_t
, limit_rate
),
408 { ngx_string("keepalive_timeout"),
409 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE12
,
410 ngx_http_core_keepalive
,
411 NGX_HTTP_LOC_CONF_OFFSET
,
415 { ngx_string("satisfy"),
416 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
417 ngx_conf_set_enum_slot
,
418 NGX_HTTP_LOC_CONF_OFFSET
,
419 offsetof(ngx_http_core_loc_conf_t
, satisfy
),
420 &ngx_http_core_satisfy
},
422 { ngx_string("satisfy_any"),
423 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
424 ngx_conf_set_flag_slot
,
425 NGX_HTTP_LOC_CONF_OFFSET
,
426 offsetof(ngx_http_core_loc_conf_t
, satisfy
),
427 &ngx_conf_deprecated_satisfy_any
},
429 { ngx_string("internal"),
430 NGX_HTTP_LOC_CONF
|NGX_CONF_NOARGS
,
431 ngx_http_core_internal
,
432 NGX_HTTP_LOC_CONF_OFFSET
,
436 { ngx_string("lingering_time"),
437 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
438 ngx_conf_set_msec_slot
,
439 NGX_HTTP_LOC_CONF_OFFSET
,
440 offsetof(ngx_http_core_loc_conf_t
, lingering_time
),
443 { ngx_string("lingering_timeout"),
444 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
445 ngx_conf_set_msec_slot
,
446 NGX_HTTP_LOC_CONF_OFFSET
,
447 offsetof(ngx_http_core_loc_conf_t
, lingering_timeout
),
450 { ngx_string("reset_timedout_connection"),
451 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
452 ngx_conf_set_flag_slot
,
453 NGX_HTTP_LOC_CONF_OFFSET
,
454 offsetof(ngx_http_core_loc_conf_t
, reset_timedout_connection
),
457 { ngx_string("server_name_in_redirect"),
458 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
459 ngx_conf_set_flag_slot
,
460 NGX_HTTP_LOC_CONF_OFFSET
,
461 offsetof(ngx_http_core_loc_conf_t
, server_name_in_redirect
),
464 { ngx_string("port_in_redirect"),
465 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
466 ngx_conf_set_flag_slot
,
467 NGX_HTTP_LOC_CONF_OFFSET
,
468 offsetof(ngx_http_core_loc_conf_t
, port_in_redirect
),
471 { ngx_string("msie_padding"),
472 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
473 ngx_conf_set_flag_slot
,
474 NGX_HTTP_LOC_CONF_OFFSET
,
475 offsetof(ngx_http_core_loc_conf_t
, msie_padding
),
478 { ngx_string("msie_refresh"),
479 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
480 ngx_conf_set_flag_slot
,
481 NGX_HTTP_LOC_CONF_OFFSET
,
482 offsetof(ngx_http_core_loc_conf_t
, msie_refresh
),
485 { ngx_string("log_not_found"),
486 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
487 ngx_conf_set_flag_slot
,
488 NGX_HTTP_LOC_CONF_OFFSET
,
489 offsetof(ngx_http_core_loc_conf_t
, log_not_found
),
492 { ngx_string("recursive_error_pages"),
493 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
494 ngx_conf_set_flag_slot
,
495 NGX_HTTP_LOC_CONF_OFFSET
,
496 offsetof(ngx_http_core_loc_conf_t
, recursive_error_pages
),
499 { ngx_string("server_tokens"),
500 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
501 ngx_conf_set_flag_slot
,
502 NGX_HTTP_LOC_CONF_OFFSET
,
503 offsetof(ngx_http_core_loc_conf_t
, server_tokens
),
506 { ngx_string("error_page"),
507 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_HTTP_LIF_CONF
509 ngx_http_core_error_page
,
510 NGX_HTTP_LOC_CONF_OFFSET
,
514 { ngx_string("post_action"),
515 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_HTTP_LIF_CONF
517 ngx_conf_set_str_slot
,
518 NGX_HTTP_LOC_CONF_OFFSET
,
519 offsetof(ngx_http_core_loc_conf_t
, post_action
),
522 { ngx_string("error_log"),
523 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_1MORE
,
524 ngx_http_core_error_log
,
525 NGX_HTTP_LOC_CONF_OFFSET
,
529 { ngx_string("open_file_cache"),
530 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE12
,
531 ngx_http_core_open_file_cache
,
532 NGX_HTTP_LOC_CONF_OFFSET
,
533 offsetof(ngx_http_core_loc_conf_t
, open_file_cache
),
536 { ngx_string("open_file_cache_valid"),
537 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
538 ngx_conf_set_sec_slot
,
539 NGX_HTTP_LOC_CONF_OFFSET
,
540 offsetof(ngx_http_core_loc_conf_t
, open_file_cache_valid
),
543 { ngx_string("open_file_cache_retest"),
544 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
545 ngx_conf_set_sec_slot
,
546 NGX_HTTP_LOC_CONF_OFFSET
,
547 offsetof(ngx_http_core_loc_conf_t
, open_file_cache_valid
),
548 &ngx_conf_deprecated_open_file_cache_retest
},
550 { ngx_string("open_file_cache_min_uses"),
551 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
552 ngx_conf_set_num_slot
,
553 NGX_HTTP_LOC_CONF_OFFSET
,
554 offsetof(ngx_http_core_loc_conf_t
, open_file_cache_min_uses
),
557 { ngx_string("open_file_cache_errors"),
558 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
559 ngx_conf_set_flag_slot
,
560 NGX_HTTP_LOC_CONF_OFFSET
,
561 offsetof(ngx_http_core_loc_conf_t
, open_file_cache_errors
),
564 { ngx_string("open_file_cache_events"),
565 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
566 ngx_conf_set_flag_slot
,
567 NGX_HTTP_LOC_CONF_OFFSET
,
568 offsetof(ngx_http_core_loc_conf_t
, open_file_cache_events
),
571 { ngx_string("resolver"),
572 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
573 ngx_http_core_resolver
,
574 NGX_HTTP_LOC_CONF_OFFSET
,
578 { ngx_string("resolver_timeout"),
579 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
580 ngx_conf_set_msec_slot
,
581 NGX_HTTP_LOC_CONF_OFFSET
,
582 offsetof(ngx_http_core_loc_conf_t
, resolver_timeout
),
587 { ngx_string("gzip_vary"),
588 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
589 ngx_conf_set_flag_slot
,
590 NGX_HTTP_LOC_CONF_OFFSET
,
591 offsetof(ngx_http_core_loc_conf_t
, gzip_vary
),
594 { ngx_string("gzip_http_version"),
595 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
596 ngx_conf_set_enum_slot
,
597 NGX_HTTP_LOC_CONF_OFFSET
,
598 offsetof(ngx_http_core_loc_conf_t
, gzip_http_version
),
599 &ngx_http_gzip_http_version
},
601 { ngx_string("gzip_proxied"),
602 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_1MORE
,
603 ngx_conf_set_bitmask_slot
,
604 NGX_HTTP_LOC_CONF_OFFSET
,
605 offsetof(ngx_http_core_loc_conf_t
, gzip_proxied
),
606 &ngx_http_gzip_proxied_mask
},
608 { ngx_string("gzip_disable"),
609 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_1MORE
,
610 ngx_http_gzip_disable
,
611 NGX_HTTP_LOC_CONF_OFFSET
,
621 static ngx_http_module_t ngx_http_core_module_ctx
= {
622 ngx_http_core_preconfiguration
, /* preconfiguration */
623 NULL
, /* postconfiguration */
625 ngx_http_core_create_main_conf
, /* create main configuration */
626 ngx_http_core_init_main_conf
, /* init main configuration */
628 ngx_http_core_create_srv_conf
, /* create server configuration */
629 ngx_http_core_merge_srv_conf
, /* merge server configuration */
631 ngx_http_core_create_loc_conf
, /* create location configuration */
632 ngx_http_core_merge_loc_conf
/* merge location configuration */
636 ngx_module_t ngx_http_core_module
= {
638 &ngx_http_core_module_ctx
, /* module context */
639 ngx_http_core_commands
, /* module directives */
640 NGX_HTTP_MODULE
, /* module type */
641 NULL
, /* init master */
642 NULL
, /* init module */
643 NULL
, /* init process */
644 NULL
, /* init thread */
645 NULL
, /* exit thread */
646 NULL
, /* exit process */
647 NULL
, /* exit master */
648 NGX_MODULE_V1_PADDING
652 static ngx_str_t ngx_http_core_get_method
= { 3, (u_char
*) "GET " };
656 ngx_http_handler(ngx_http_request_t
*r
)
658 ngx_http_core_main_conf_t
*cmcf
;
660 r
->connection
->log
->action
= NULL
;
662 r
->connection
->unexpected_eof
= 0;
665 switch (r
->headers_in
.connection_type
) {
667 if (r
->http_version
> NGX_HTTP_VERSION_10
) {
674 case NGX_HTTP_CONNECTION_CLOSE
:
678 case NGX_HTTP_CONNECTION_KEEP_ALIVE
:
683 if (r
->keepalive
&& r
->headers_in
.msie
&& r
->method
== NGX_HTTP_POST
) {
686 * MSIE may wait for some time if an response for
687 * a POST request was sent over a keepalive connection
693 if (r
->headers_in
.content_length_n
> 0) {
694 r
->lingering_close
= 1;
697 r
->lingering_close
= 0;
700 r
->phase_handler
= 0;
703 cmcf
= ngx_http_get_module_main_conf(r
, ngx_http_core_module
);
704 r
->phase_handler
= cmcf
->phase_engine
.server_rewrite_index
;
707 if (r
->unparsed_uri
.len
) {
708 r
->valid_unparsed_uri
= 1;
711 r
->valid_location
= 1;
714 r
->write_event_handler
= ngx_http_core_run_phases
;
715 ngx_http_core_run_phases(r
);
720 ngx_http_core_run_phases(ngx_http_request_t
*r
)
723 ngx_http_phase_handler_t
*ph
;
724 ngx_http_core_main_conf_t
*cmcf
;
726 cmcf
= ngx_http_get_module_main_conf(r
, ngx_http_core_module
);
728 ph
= cmcf
->phase_engine
.handlers
;
730 while (ph
[r
->phase_handler
].checker
) {
732 rc
= ph
[r
->phase_handler
].checker(r
, &ph
[r
->phase_handler
]);
742 ngx_http_core_generic_phase(ngx_http_request_t
*r
, ngx_http_phase_handler_t
*ph
)
747 * generic phase checker,
748 * used by the post read, server rewrite, rewrite, and pre-access phases
751 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
752 "generic phase: %ui", r
->phase_handler
);
757 r
->phase_handler
= ph
->next
;
761 if (rc
== NGX_DECLINED
) {
766 if (rc
== NGX_AGAIN
|| rc
== NGX_DONE
) {
770 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
772 ngx_http_finalize_request(r
, rc
);
779 ngx_http_core_find_config_phase(ngx_http_request_t
*r
,
780 ngx_http_phase_handler_t
*ph
)
784 ngx_int_t rc
, expect
;
785 ngx_http_core_loc_conf_t
*clcf
;
787 r
->content_handler
= NULL
;
790 rc
= ngx_http_core_find_location(r
);
792 if (rc
== NGX_HTTP_INTERNAL_SERVER_ERROR
) {
793 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
797 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
799 if (!r
->internal
&& clcf
->internal
) {
800 ngx_http_finalize_request(r
, NGX_HTTP_NOT_FOUND
);
804 ngx_log_debug2(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
805 "using configuration \"%s%V\"",
806 (clcf
->noname
? "*" : (clcf
->exact_match
? "=" : "")),
809 ngx_http_update_location_config(r
);
811 ngx_log_debug2(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
813 r
->headers_in
.content_length_n
, clcf
->client_max_body_size
);
815 if (r
->headers_in
.content_length_n
!= -1
817 && clcf
->client_max_body_size
818 && clcf
->client_max_body_size
< r
->headers_in
.content_length_n
)
820 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
821 "client intended to send too large body: %O bytes",
822 r
->headers_in
.content_length_n
);
824 ngx_http_finalize_request(r
, NGX_HTTP_REQUEST_ENTITY_TOO_LARGE
);
828 if (r
->headers_in
.expect
) {
829 expect
= ngx_http_core_send_continue(r
);
831 if (expect
!= NGX_OK
) {
832 ngx_http_finalize_request(r
, expect
);
837 if (rc
== NGX_DONE
) {
838 r
->headers_out
.location
= ngx_list_push(&r
->headers_out
.headers
);
839 if (r
->headers_out
.location
== NULL
) {
840 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
845 * we do not need to set the r->headers_out.location->hash and
846 * r->headers_out.location->key fields
849 if (r
->args
.len
== 0) {
850 r
->headers_out
.location
->value
= clcf
->name
;
853 len
= clcf
->name
.len
+ 1 + r
->args
.len
;
854 p
= ngx_pnalloc(r
->pool
, len
);
857 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
861 r
->headers_out
.location
->value
.len
= len
;
862 r
->headers_out
.location
->value
.data
= p
;
864 p
= ngx_cpymem(p
, clcf
->name
.data
, clcf
->name
.len
);
866 ngx_memcpy(p
, r
->args
.data
, r
->args
.len
);
869 ngx_http_finalize_request(r
, NGX_HTTP_MOVED_PERMANENTLY
);
879 ngx_http_core_post_rewrite_phase(ngx_http_request_t
*r
,
880 ngx_http_phase_handler_t
*ph
)
882 ngx_http_core_srv_conf_t
*cscf
;
884 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
885 "post rewrite phase: %ui", r
->phase_handler
);
887 if (!r
->uri_changed
) {
892 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
893 "uri changes: %d", r
->uri_changes
);
896 * gcc before 3.3 compiles the broken code for
897 * if (r->uri_changes-- == 0)
898 * if the r->uri_changes is defined as
899 * unsigned uri_changes:4
904 if (r
->uri_changes
== 0) {
905 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
906 "rewrite or internal redirection cycle "
907 "while processing \"%V\"", &r
->uri
);
909 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
913 r
->phase_handler
= ph
->next
;
915 cscf
= ngx_http_get_module_srv_conf(r
, ngx_http_core_module
);
916 r
->loc_conf
= cscf
->ctx
->loc_conf
;
923 ngx_http_core_access_phase(ngx_http_request_t
*r
, ngx_http_phase_handler_t
*ph
)
926 ngx_http_core_loc_conf_t
*clcf
;
929 r
->phase_handler
= ph
->next
;
933 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
934 "access phase: %ui", r
->phase_handler
);
938 if (rc
== NGX_DECLINED
) {
943 if (rc
== NGX_AGAIN
|| rc
== NGX_DONE
) {
947 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
949 if (clcf
->satisfy
== NGX_HTTP_SATISFY_ALL
) {
960 if (r
->headers_out
.www_authenticate
) {
961 r
->headers_out
.www_authenticate
->hash
= 0;
964 r
->phase_handler
= ph
->next
;
968 if (rc
== NGX_HTTP_FORBIDDEN
|| rc
== NGX_HTTP_UNAUTHORIZED
) {
976 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
978 ngx_http_finalize_request(r
, rc
);
984 ngx_http_core_post_access_phase(ngx_http_request_t
*r
,
985 ngx_http_phase_handler_t
*ph
)
987 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
988 "post access phase: %ui", r
->phase_handler
);
990 if (r
->access_code
) {
992 if (r
->access_code
== NGX_HTTP_FORBIDDEN
) {
993 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
994 "access forbidden by rule");
997 ngx_http_finalize_request(r
, r
->access_code
);
1007 ngx_http_core_content_phase(ngx_http_request_t
*r
,
1008 ngx_http_phase_handler_t
*ph
)
1014 if (r
->content_handler
) {
1015 r
->write_event_handler
= ngx_http_request_empty_handler
;
1016 ngx_http_finalize_request(r
, r
->content_handler(r
));
1020 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1021 "content phase: %ui", r
->phase_handler
);
1023 rc
= ph
->handler(r
);
1025 if (rc
== NGX_DONE
) {
1029 if (rc
!= NGX_DECLINED
) {
1030 ngx_http_finalize_request(r
, rc
);
1034 /* rc == NGX_DECLINED */
1043 /* no content handler was found */
1045 if (r
->uri
.data
[r
->uri
.len
- 1] == '/' && !r
->zero_in_uri
) {
1047 if (ngx_http_map_uri_to_path(r
, &path
, &root
, 0) != NULL
) {
1048 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
1049 "directory index of \"%s\" is forbidden", path
.data
);
1052 ngx_http_finalize_request(r
, NGX_HTTP_FORBIDDEN
);
1056 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0, "no handler found");
1058 ngx_http_finalize_request(r
, NGX_HTTP_NOT_FOUND
);
1064 ngx_http_update_location_config(ngx_http_request_t
*r
)
1066 ngx_http_core_loc_conf_t
*clcf
;
1068 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1070 if (r
->method
& clcf
->limit_except
) {
1071 r
->loc_conf
= clcf
->limit_except_loc_conf
;
1072 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1076 r
->connection
->log
->file
= clcf
->err_log
->file
;
1078 if (!(r
->connection
->log
->log_level
& NGX_LOG_DEBUG_CONNECTION
)) {
1079 r
->connection
->log
->log_level
= clcf
->err_log
->log_level
;
1083 if ((ngx_io
.flags
& NGX_IO_SENDFILE
) && clcf
->sendfile
) {
1084 r
->connection
->sendfile
= 1;
1087 r
->connection
->sendfile
= 0;
1090 if (clcf
->client_body_in_file_only
) {
1091 r
->request_body_in_file_only
= 1;
1092 r
->request_body_in_persistent_file
= 1;
1093 r
->request_body_in_clean_file
=
1094 clcf
->client_body_in_file_only
== NGX_HTTP_REQUEST_BODY_FILE_CLEAN
;
1095 r
->request_body_file_log_level
= NGX_LOG_NOTICE
;
1098 r
->request_body_file_log_level
= NGX_LOG_WARN
;
1101 if (r
->keepalive
&& clcf
->keepalive_timeout
== 0) {
1105 if (!clcf
->tcp_nopush
) {
1106 /* disable TCP_NOPUSH/TCP_CORK use */
1107 r
->connection
->tcp_nopush
= NGX_TCP_NOPUSH_DISABLED
;
1110 if (r
->limit_rate
== 0) {
1111 r
->limit_rate
= clcf
->limit_rate
;
1114 if (clcf
->handler
) {
1115 r
->content_handler
= clcf
->handler
;
1121 ngx_http_core_find_location(ngx_http_request_t
*r
)
1124 ngx_http_core_loc_conf_t
*pclcf
;
1126 pclcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1128 rc
= ngx_http_core_find_static_location(r
, pclcf
->static_locations
);
1130 if (rc
== NGX_AGAIN
) {
1131 /* look up nested locations */
1132 rc
= ngx_http_core_find_location(r
);
1135 if (rc
== NGX_OK
|| rc
== NGX_DONE
) {
1139 /* rc == NGX_DECLINED or rc == NGX_AGAIN in nested location */
1144 ngx_http_core_loc_conf_t
*clcf
, **clcfp
;
1146 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1148 if (clcf
->noregex
== 0 && pclcf
->regex_locations
) {
1150 for (clcfp
= pclcf
->regex_locations
; *clcfp
; clcfp
++) {
1152 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1153 "test location: ~ \"%V\"", &(*clcfp
)->name
);
1155 n
= ngx_regex_exec((*clcfp
)->regex
, &r
->uri
, NULL
, 0);
1157 if (n
== NGX_REGEX_NO_MATCHED
) {
1162 ngx_log_error(NGX_LOG_ALERT
, r
->connection
->log
, 0,
1164 " failed: %d on \"%V\" using \"%V\"",
1165 n
, &r
->uri
, &(*clcfp
)->name
);
1166 return NGX_HTTP_INTERNAL_SERVER_ERROR
;
1171 r
->loc_conf
= (*clcfp
)->loc_conf
;
1173 /* look up nested locations */
1175 return ngx_http_core_find_location(r
);
1186 * NGX_OK - exact match
1187 * NGX_DONE - auto redirect
1188 * NGX_AGAIN - inclusive match
1189 * NGX_DECLINED - no match
1193 ngx_http_core_find_static_location(ngx_http_request_t
*r
,
1194 ngx_http_location_tree_node_t
*node
)
1211 ngx_log_debug2(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1212 "test location: \"%*s\"", node
->len
, node
->name
);
1214 n
= (len
<= (size_t) node
->len
) ? len
: node
->len
;
1216 rc
= ngx_filename_cmp(uri
, node
->name
, n
);
1219 node
= (rc
< 0) ? node
->left
: node
->right
;
1224 if (len
> (size_t) node
->len
) {
1226 if (node
->inclusive
) {
1228 r
->loc_conf
= node
->inclusive
->loc_conf
;
1245 if (len
== (size_t) node
->len
) {
1247 r
->loc_conf
= (node
->exact
) ? node
->exact
->loc_conf
:
1248 node
->inclusive
->loc_conf
;
1252 /* len < node->len */
1254 if (len
+ 1 == (size_t) node
->len
&& node
->auto_redirect
) {
1256 r
->loc_conf
= (node
->exact
) ? node
->exact
->loc_conf
:
1257 node
->inclusive
->loc_conf
;
1267 ngx_http_core_send_continue(ngx_http_request_t
*r
)
1272 if (r
->expect_tested
) {
1276 r
->expect_tested
= 1;
1278 expect
= &r
->headers_in
.expect
->value
;
1280 if (expect
->len
!= sizeof("100-continue") - 1
1281 || ngx_strncasecmp(expect
->data
, (u_char
*) "100-continue",
1282 sizeof("100-continue") - 1)
1288 ngx_log_debug0(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1289 "send 100 Continue");
1291 n
= r
->connection
->send(r
->connection
,
1292 (u_char
*) "HTTP/1.1 100 Continue" CRLF CRLF
,
1293 sizeof("HTTP/1.1 100 Continue" CRLF CRLF
) - 1);
1295 if (n
== sizeof("HTTP/1.1 100 Continue" CRLF CRLF
) - 1) {
1299 /* we assume that such small packet should be send successfully */
1301 return NGX_HTTP_INTERNAL_SERVER_ERROR
;
1306 ngx_http_test_content_type(ngx_http_request_t
*r
, ngx_hash_t
*types_hash
)
1311 if (r
->headers_out
.content_type
.len
== 0) {
1315 if (r
->headers_out
.content_type_lowcase
== NULL
) {
1317 p
= ngx_pnalloc(r
->pool
, r
->headers_out
.content_type_len
);
1323 r
->headers_out
.content_type_lowcase
= p
;
1327 for (i
= 0; i
< r
->headers_out
.content_type_len
; i
++) {
1328 c
= ngx_tolower(r
->headers_out
.content_type
.data
[i
]);
1329 hash
= ngx_hash(hash
, c
);
1333 r
->headers_out
.content_type_hash
= hash
;
1336 return ngx_hash_find(types_hash
,
1337 r
->headers_out
.content_type_hash
,
1338 r
->headers_out
.content_type_lowcase
,
1339 r
->headers_out
.content_type_len
);
1344 ngx_http_set_content_type(ngx_http_request_t
*r
)
1349 ngx_http_core_loc_conf_t
*clcf
;
1351 if (r
->headers_out
.content_type
.len
) {
1355 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1361 for (i
= 0; i
< r
->exten
.len
; i
++) {
1362 c
= r
->exten
.data
[i
];
1364 if (c
>= 'A' && c
<= 'Z') {
1366 exten
= ngx_pnalloc(r
->pool
, r
->exten
.len
);
1367 if (exten
== NULL
) {
1368 return NGX_HTTP_INTERNAL_SERVER_ERROR
;
1371 hash
= ngx_hash_strlow(exten
, r
->exten
.data
, r
->exten
.len
);
1373 r
->exten
.data
= exten
;
1378 hash
= ngx_hash(hash
, c
);
1381 type
= ngx_hash_find(&clcf
->types_hash
, hash
,
1382 r
->exten
.data
, r
->exten
.len
);
1385 r
->headers_out
.content_type_len
= type
->len
;
1386 r
->headers_out
.content_type
= *type
;
1392 r
->headers_out
.content_type_len
= clcf
->default_type
.len
;
1393 r
->headers_out
.content_type
= clcf
->default_type
;
1400 ngx_http_set_exten(ngx_http_request_t
*r
)
1405 r
->exten
.data
= NULL
;
1407 for (i
= r
->uri
.len
- 1; i
> 1; i
--) {
1408 if (r
->uri
.data
[i
] == '.' && r
->uri
.data
[i
- 1] != '/') {
1410 r
->exten
.len
= r
->uri
.len
- i
- 1;
1411 r
->exten
.data
= &r
->uri
.data
[i
+ 1];
1415 } else if (r
->uri
.data
[i
] == '/') {
1425 ngx_http_send_header(ngx_http_request_t
*r
)
1427 if (r
->err_status
) {
1428 r
->headers_out
.status
= r
->err_status
;
1429 r
->headers_out
.status_line
.len
= 0;
1432 return ngx_http_top_header_filter(r
);
1437 ngx_http_output_filter(ngx_http_request_t
*r
, ngx_chain_t
*in
)
1441 ngx_log_debug2(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1442 "http output filter \"%V?%V\"", &r
->uri
, &r
->args
);
1444 rc
= ngx_http_top_body_filter(r
, in
);
1446 if (rc
== NGX_ERROR
) {
1447 /* NGX_ERROR may be returned by any filter */
1448 r
->connection
->error
= 1;
1456 ngx_http_map_uri_to_path(ngx_http_request_t
*r
, ngx_str_t
*path
,
1457 size_t *root_length
, size_t reserved
)
1461 ngx_http_core_loc_conf_t
*clcf
;
1463 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1465 alias
= clcf
->alias
? clcf
->name
.len
: 0;
1467 if (alias
&& !r
->valid_location
) {
1468 ngx_log_error(NGX_LOG_ALERT
, r
->connection
->log
, 0,
1469 "\"alias\" could not be used in location \"%V\" "
1470 "where URI was rewritten", &clcf
->name
);
1474 reserved
+= r
->uri
.len
- alias
+ 1;
1476 if (clcf
->root_lengths
== NULL
) {
1478 *root_length
= clcf
->root
.len
;
1480 path
->len
= clcf
->root
.len
+ reserved
;
1482 path
->data
= ngx_pnalloc(r
->pool
, path
->len
);
1483 if (path
->data
== NULL
) {
1487 last
= ngx_copy(path
->data
, clcf
->root
.data
, clcf
->root
.len
);
1490 if (ngx_http_script_run(r
, path
, clcf
->root_lengths
->elts
, reserved
,
1491 clcf
->root_values
->elts
)
1497 if (ngx_conf_full_name((ngx_cycle_t
*) ngx_cycle
, path
, 0)== NGX_ERROR
)
1502 *root_length
= path
->len
- reserved
;
1503 last
= path
->data
+ *root_length
;
1506 last
= ngx_cpystrn(last
, r
->uri
.data
+ alias
, r
->uri
.len
- alias
+ 1);
1513 ngx_http_auth_basic_user(ngx_http_request_t
*r
)
1515 ngx_str_t auth
, encoded
;
1518 if (r
->headers_in
.user
.len
== 0 && r
->headers_in
.user
.data
!= NULL
) {
1519 return NGX_DECLINED
;
1522 if (r
->headers_in
.authorization
== NULL
) {
1523 r
->headers_in
.user
.data
= (u_char
*) "";
1524 return NGX_DECLINED
;
1527 encoded
= r
->headers_in
.authorization
->value
;
1529 if (encoded
.len
< sizeof("Basic ") - 1
1530 || ngx_strncasecmp(encoded
.data
, (u_char
*) "Basic ",
1531 sizeof("Basic ") - 1)
1534 r
->headers_in
.user
.data
= (u_char
*) "";
1535 return NGX_DECLINED
;
1538 encoded
.len
-= sizeof("Basic ") - 1;
1539 encoded
.data
+= sizeof("Basic ") - 1;
1541 while (encoded
.len
&& encoded
.data
[0] == ' ') {
1546 if (encoded
.len
== 0) {
1547 r
->headers_in
.user
.data
= (u_char
*) "";
1548 return NGX_DECLINED
;
1551 auth
.len
= ngx_base64_decoded_length(encoded
.len
);
1552 auth
.data
= ngx_pnalloc(r
->pool
, auth
.len
+ 1);
1553 if (auth
.data
== NULL
) {
1557 if (ngx_decode_base64(&auth
, &encoded
) != NGX_OK
) {
1558 r
->headers_in
.user
.data
= (u_char
*) "";
1559 return NGX_DECLINED
;
1562 auth
.data
[auth
.len
] = '\0';
1564 for (len
= 0; len
< auth
.len
; len
++) {
1565 if (auth
.data
[len
] == ':') {
1570 if (len
== 0 || len
== auth
.len
) {
1571 r
->headers_in
.user
.data
= (u_char
*) "";
1572 return NGX_DECLINED
;
1575 r
->headers_in
.user
.len
= len
;
1576 r
->headers_in
.user
.data
= auth
.data
;
1577 r
->headers_in
.passwd
.len
= auth
.len
- len
- 1;
1578 r
->headers_in
.passwd
.data
= &auth
.data
[len
+ 1];
1585 ngx_http_server_addr(ngx_http_request_t
*r
, ngx_str_t
*s
)
1588 ngx_connection_t
*c
;
1589 struct sockaddr_in sin
;
1595 if (r
->in_addr
== 0) {
1596 len
= sizeof(struct sockaddr_in
);
1597 if (getsockname(c
->fd
, (struct sockaddr
*) &sin
, &len
) == -1) {
1598 ngx_connection_error(c
, ngx_socket_errno
, "getsockname() failed");
1602 r
->in_addr
= sin
.sin_addr
.s_addr
;
1609 s
->len
= ngx_inet_ntop(c
->listening
->family
, &r
->in_addr
,
1610 s
->data
, INET_ADDRSTRLEN
);
1619 ngx_http_gzip_ok(ngx_http_request_t
*r
)
1621 time_t date
, expires
;
1624 ngx_table_elt_t
*e
, *d
;
1625 ngx_http_core_loc_conf_t
*clcf
;
1632 return NGX_DECLINED
;
1638 || r
->headers_in
.accept_encoding
== NULL
1639 || ngx_strcasestrn(r
->headers_in
.accept_encoding
->value
.data
,
1644 * if the URL (without the "http://" prefix) is longer than 253 bytes,
1645 * then MSIE 4.x can not handle the compressed stream - it waits
1646 * too long, hangs up or crashes
1649 || (r
->headers_in
.msie4
&& r
->unparsed_uri
.len
> 200))
1651 return NGX_DECLINED
;
1654 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1656 if (r
->http_version
< clcf
->gzip_http_version
) {
1657 return NGX_DECLINED
;
1660 if (r
->headers_in
.via
== NULL
) {
1664 p
= clcf
->gzip_proxied
;
1666 if (p
& NGX_HTTP_GZIP_PROXIED_OFF
) {
1667 return NGX_DECLINED
;
1670 if (p
& NGX_HTTP_GZIP_PROXIED_ANY
) {
1674 if (r
->headers_in
.authorization
&& (p
& NGX_HTTP_GZIP_PROXIED_AUTH
)) {
1678 e
= r
->headers_out
.expires
;
1682 if (!(p
& NGX_HTTP_GZIP_PROXIED_EXPIRED
)) {
1683 return NGX_DECLINED
;
1686 expires
= ngx_http_parse_time(e
->value
.data
, e
->value
.len
);
1687 if (expires
== NGX_ERROR
) {
1688 return NGX_DECLINED
;
1691 d
= r
->headers_out
.date
;
1694 date
= ngx_http_parse_time(d
->value
.data
, d
->value
.len
);
1695 if (date
== NGX_ERROR
) {
1696 return NGX_DECLINED
;
1703 if (expires
< date
) {
1707 return NGX_DECLINED
;
1710 cc
= &r
->headers_out
.cache_control
;
1714 if ((p
& NGX_HTTP_GZIP_PROXIED_NO_CACHE
)
1715 && ngx_http_parse_multi_header_lines(cc
, &ngx_http_gzip_no_cache
,
1722 if ((p
& NGX_HTTP_GZIP_PROXIED_NO_STORE
)
1723 && ngx_http_parse_multi_header_lines(cc
, &ngx_http_gzip_no_store
,
1730 if ((p
& NGX_HTTP_GZIP_PROXIED_PRIVATE
)
1731 && ngx_http_parse_multi_header_lines(cc
, &ngx_http_gzip_private
,
1738 return NGX_DECLINED
;
1741 if ((p
& NGX_HTTP_GZIP_PROXIED_NO_LM
) && r
->headers_out
.last_modified
) {
1742 return NGX_DECLINED
;
1745 if ((p
& NGX_HTTP_GZIP_PROXIED_NO_ETAG
) && r
->headers_out
.etag
) {
1746 return NGX_DECLINED
;
1753 if (clcf
->gzip_disable
&& r
->headers_in
.user_agent
) {
1755 if (ngx_regex_exec_array(clcf
->gzip_disable
,
1756 &r
->headers_in
.user_agent
->value
,
1760 return NGX_DECLINED
;
1775 ngx_http_subrequest(ngx_http_request_t
*r
,
1776 ngx_str_t
*uri
, ngx_str_t
*args
, ngx_http_request_t
**psr
,
1777 ngx_http_post_subrequest_t
*ps
, ngx_uint_t flags
)
1779 ngx_connection_t
*c
;
1780 ngx_http_request_t
*sr
;
1781 ngx_http_log_ctx_t
*ctx
;
1782 ngx_http_core_srv_conf_t
*cscf
;
1783 ngx_http_postponed_request_t
*pr
, *p
;
1785 r
->main
->subrequests
--;
1787 if (r
->main
->subrequests
== 0) {
1788 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
1789 "subrequests cycle while processing \"%V\"", uri
);
1790 r
->main
->subrequests
= 1;
1794 sr
= ngx_pcalloc(r
->pool
, sizeof(ngx_http_request_t
));
1799 sr
->signature
= NGX_HTTP_MODULE
;
1804 sr
->ctx
= ngx_pcalloc(r
->pool
, sizeof(void *) * ngx_http_max_module
);
1805 if (sr
->ctx
== NULL
) {
1809 if (ngx_list_init(&sr
->headers_out
.headers
, r
->pool
, 20,
1810 sizeof(ngx_table_elt_t
))
1816 cscf
= ngx_http_get_module_srv_conf(r
, ngx_http_core_module
);
1817 sr
->main_conf
= cscf
->ctx
->main_conf
;
1818 sr
->srv_conf
= cscf
->ctx
->srv_conf
;
1819 sr
->loc_conf
= cscf
->ctx
->loc_conf
;
1823 sr
->headers_in
= r
->headers_in
;
1825 ngx_http_clear_content_length(sr
);
1826 ngx_http_clear_accept_ranges(sr
);
1827 ngx_http_clear_last_modified(sr
);
1829 sr
->request_body
= r
->request_body
;
1831 sr
->method
= NGX_HTTP_GET
;
1832 sr
->http_version
= r
->http_version
;
1834 sr
->request_line
= r
->request_line
;
1841 ngx_log_debug2(NGX_LOG_DEBUG_HTTP
, c
->log
, 0,
1842 "http subrequest \"%V?%V\"", uri
, &sr
->args
);
1844 sr
->zero_in_uri
= (flags
& NGX_HTTP_ZERO_IN_URI
) != 0;
1845 sr
->subrequest_in_memory
= (flags
& NGX_HTTP_SUBREQUEST_IN_MEMORY
) != 0;
1847 sr
->unparsed_uri
= r
->unparsed_uri
;
1848 sr
->method_name
= ngx_http_core_get_method
;
1849 sr
->http_protocol
= r
->http_protocol
;
1851 if (ngx_http_set_exten(sr
) != NGX_OK
) {
1857 sr
->post_subrequest
= ps
;
1858 sr
->read_event_handler
= ngx_http_request_empty_handler
;
1859 sr
->write_event_handler
= ngx_http_request_empty_handler
;
1865 sr
->in_addr
= r
->in_addr
;
1867 sr
->port_text
= r
->port_text
;
1869 sr
->variables
= r
->variables
;
1871 sr
->log_handler
= r
->log_handler
;
1873 pr
= ngx_palloc(r
->pool
, sizeof(ngx_http_postponed_request_t
));
1883 for (p
= r
->postponed
; p
->next
; p
= p
->next
) { /* void */ }
1891 ctx
->current_request
= sr
;
1894 sr
->fast_subrequest
= 1;
1896 sr
->discard_body
= r
->discard_body
;
1897 sr
->main_filter_need_in_memory
= r
->main_filter_need_in_memory
;
1899 sr
->uri_changes
= NGX_HTTP_MAX_URI_CHANGES
+ 1;
1901 ngx_http_handler(sr
);
1903 if (!c
->destroyed
) {
1904 ngx_log_debug2(NGX_LOG_DEBUG_HTTP
, c
->log
, 0,
1905 "http subrequest done \"%V?%V\"", uri
, &sr
->args
);
1907 r
->main
->subrequests
++;
1911 if (sr
->fast_subrequest
) {
1912 sr
->fast_subrequest
= 0;
1927 ngx_http_internal_redirect(ngx_http_request_t
*r
,
1928 ngx_str_t
*uri
, ngx_str_t
*args
)
1930 ngx_http_core_srv_conf_t
*cscf
;
1934 if (r
->uri_changes
== 0) {
1935 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
1936 "rewrite or internal redirection cycle "
1937 "while internal redirect to \"%V\"", uri
);
1939 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
1950 r
->args
.data
= NULL
;
1953 ngx_log_debug2(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1954 "internal redirect: \"%V?%V\"", uri
, &r
->args
);
1956 if (ngx_http_set_exten(r
) != NGX_OK
) {
1957 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
1961 /* clear the modules contexts */
1962 ngx_memzero(r
->ctx
, sizeof(void *) * ngx_http_max_module
);
1964 cscf
= ngx_http_get_module_srv_conf(r
, ngx_http_core_module
);
1965 r
->loc_conf
= cscf
->ctx
->loc_conf
;
1967 ngx_http_update_location_config(r
);
1971 ngx_http_handler(r
);
1978 ngx_http_named_location(ngx_http_request_t
*r
, ngx_str_t
*name
)
1980 ngx_http_core_srv_conf_t
*cscf
;
1981 ngx_http_core_loc_conf_t
**clcfp
;
1982 ngx_http_core_main_conf_t
*cmcf
;
1984 cscf
= ngx_http_get_module_srv_conf(r
, ngx_http_core_module
);
1986 for (clcfp
= cscf
->named_locations
; *clcfp
; clcfp
++) {
1988 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1989 "test location: \"%V\"", &(*clcfp
)->name
);
1991 if (name
->len
!= (*clcfp
)->name
.len
1992 || ngx_strncmp(name
->data
, (*clcfp
)->name
.data
, name
->len
) != 0)
1997 ngx_log_debug3(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1998 "using location: %V \"%V?%V\"", name
, &r
->uri
, &r
->args
);
2001 r
->content_handler
= NULL
;
2002 r
->loc_conf
= (*clcfp
)->loc_conf
;
2004 ngx_http_update_location_config(r
);
2006 cmcf
= ngx_http_get_module_main_conf(r
, ngx_http_core_module
);
2008 r
->phase_handler
= cmcf
->phase_engine
.location_rewrite_index
;
2010 ngx_http_core_run_phases(r
);
2015 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
2016 "could not find named location \"%V\"", name
);
2018 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
2024 ngx_http_cleanup_t
*
2025 ngx_http_cleanup_add(ngx_http_request_t
*r
, size_t size
)
2027 ngx_http_cleanup_t
*cln
;
2031 cln
= ngx_palloc(r
->pool
, sizeof(ngx_http_cleanup_t
));
2037 cln
->data
= ngx_palloc(r
->pool
, size
);
2038 if (cln
->data
== NULL
) {
2046 cln
->handler
= NULL
;
2047 cln
->next
= r
->cleanup
;
2051 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
2052 "http cleanup add: %p", cln
);
2059 ngx_http_core_server(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *dummy
)
2065 ngx_http_module_t
*module
;
2066 ngx_http_conf_ctx_t
*ctx
, *http_ctx
;
2067 ngx_http_core_srv_conf_t
*cscf
, **cscfp
;
2068 ngx_http_core_main_conf_t
*cmcf
;
2070 ctx
= ngx_pcalloc(cf
->pool
, sizeof(ngx_http_conf_ctx_t
));
2072 return NGX_CONF_ERROR
;
2076 ctx
->main_conf
= http_ctx
->main_conf
;
2078 /* the server{}'s srv_conf */
2080 ctx
->srv_conf
= ngx_pcalloc(cf
->pool
, sizeof(void *) * ngx_http_max_module
);
2081 if (ctx
->srv_conf
== NULL
) {
2082 return NGX_CONF_ERROR
;
2085 /* the server{}'s loc_conf */
2087 ctx
->loc_conf
= ngx_pcalloc(cf
->pool
, sizeof(void *) * ngx_http_max_module
);
2088 if (ctx
->loc_conf
== NULL
) {
2089 return NGX_CONF_ERROR
;
2092 for (i
= 0; ngx_modules
[i
]; i
++) {
2093 if (ngx_modules
[i
]->type
!= NGX_HTTP_MODULE
) {
2097 module
= ngx_modules
[i
]->ctx
;
2099 if (module
->create_srv_conf
) {
2100 mconf
= module
->create_srv_conf(cf
);
2101 if (mconf
== NULL
) {
2102 return NGX_CONF_ERROR
;
2105 ctx
->srv_conf
[ngx_modules
[i
]->ctx_index
] = mconf
;
2108 if (module
->create_loc_conf
) {
2109 mconf
= module
->create_loc_conf(cf
);
2110 if (mconf
== NULL
) {
2111 return NGX_CONF_ERROR
;
2114 ctx
->loc_conf
[ngx_modules
[i
]->ctx_index
] = mconf
;
2119 /* the server configuration context */
2121 cscf
= ctx
->srv_conf
[ngx_http_core_module
.ctx_index
];
2125 cmcf
= ctx
->main_conf
[ngx_http_core_module
.ctx_index
];
2127 cscfp
= ngx_array_push(&cmcf
->servers
);
2128 if (cscfp
== NULL
) {
2129 return NGX_CONF_ERROR
;
2135 /* parse inside server{} */
2139 cf
->cmd_type
= NGX_HTTP_SRV_CONF
;
2141 rv
= ngx_conf_parse(cf
, NULL
);
2150 ngx_http_core_location(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *dummy
)
2156 ngx_http_module_t
*module
;
2157 ngx_http_conf_ctx_t
*ctx
, *pctx
;
2158 ngx_http_core_loc_conf_t
*clcf
, *pclcf
;
2160 ctx
= ngx_pcalloc(cf
->pool
, sizeof(ngx_http_conf_ctx_t
));
2162 return NGX_CONF_ERROR
;
2166 ctx
->main_conf
= pctx
->main_conf
;
2167 ctx
->srv_conf
= pctx
->srv_conf
;
2169 ctx
->loc_conf
= ngx_pcalloc(cf
->pool
, sizeof(void *) * ngx_http_max_module
);
2170 if (ctx
->loc_conf
== NULL
) {
2171 return NGX_CONF_ERROR
;
2174 for (i
= 0; ngx_modules
[i
]; i
++) {
2175 if (ngx_modules
[i
]->type
!= NGX_HTTP_MODULE
) {
2179 module
= ngx_modules
[i
]->ctx
;
2181 if (module
->create_loc_conf
) {
2182 ctx
->loc_conf
[ngx_modules
[i
]->ctx_index
] =
2183 module
->create_loc_conf(cf
);
2184 if (ctx
->loc_conf
[ngx_modules
[i
]->ctx_index
] == NULL
) {
2185 return NGX_CONF_ERROR
;
2190 clcf
= ctx
->loc_conf
[ngx_http_core_module
.ctx_index
];
2191 clcf
->loc_conf
= ctx
->loc_conf
;
2193 value
= cf
->args
->elts
;
2195 if (cf
->args
->nelts
== 3) {
2196 if (value
[1].len
== 1 && value
[1].data
[0] == '=') {
2197 clcf
->name
= value
[2];
2198 clcf
->exact_match
= 1;
2200 } else if (value
[1].len
== 2
2201 && value
[1].data
[0] == '^'
2202 && value
[1].data
[1] == '~')
2204 clcf
->name
= value
[2];
2207 } else if ((value
[1].len
== 1 && value
[1].data
[0] == '~')
2208 || (value
[1].len
== 2
2209 && value
[1].data
[0] == '~'
2210 && value
[1].data
[1] == '*'))
2214 u_char errstr
[NGX_MAX_CONF_ERRSTR
];
2216 err
.len
= NGX_MAX_CONF_ERRSTR
;
2219 clcf
->regex
= ngx_regex_compile(&value
[2],
2220 value
[1].len
== 2 ? NGX_REGEX_CASELESS
: 0,
2223 if (clcf
->regex
== NULL
) {
2224 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0, "%s", err
.data
);
2225 return NGX_CONF_ERROR
;
2228 clcf
->name
= value
[2];
2230 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
2231 "the using of the regex \"%V\" "
2232 "requires PCRE library", &value
[2]);
2233 return NGX_CONF_ERROR
;
2237 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
2238 "invalid location modifier \"%V\"", &value
[1]);
2239 return NGX_CONF_ERROR
;
2244 clcf
->name
= value
[1];
2246 if (value
[1].data
[0] == '@') {
2251 pclcf
= pctx
->loc_conf
[ngx_http_core_module
.ctx_index
];
2253 if (pclcf
->name
.len
) {
2255 /* nested location */
2258 clcf
->prev_location
= pclcf
;
2261 if (pclcf
->exact_match
) {
2262 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
2263 "location \"%V\" could not be inside "
2264 "the exact location \"%V\"",
2265 &clcf
->name
, &pclcf
->name
);
2266 return NGX_CONF_ERROR
;
2270 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
2271 "location \"%V\" could not be inside "
2272 "the named location \"%V\"",
2273 &clcf
->name
, &pclcf
->name
);
2274 return NGX_CONF_ERROR
;
2278 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
2279 "named location \"%V\" must be "
2280 "on server level only",
2282 return NGX_CONF_ERROR
;
2286 if (clcf
->regex
== NULL
2287 && ngx_strncmp(clcf
->name
.data
, pclcf
->name
.data
, pclcf
->name
.len
)
2290 if (ngx_strncmp(clcf
->name
.data
, pclcf
->name
.data
, pclcf
->name
.len
)
2294 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
2295 "location \"%V\" is outside location \"%V\"",
2296 &clcf
->name
, &pclcf
->name
);
2297 return NGX_CONF_ERROR
;
2301 if (ngx_http_add_location(cf
, &pclcf
->locations
, clcf
) != NGX_OK
) {
2302 return NGX_CONF_ERROR
;
2307 cf
->cmd_type
= NGX_HTTP_LOC_CONF
;
2309 rv
= ngx_conf_parse(cf
, NULL
);
2318 ngx_http_core_types(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
2320 ngx_http_core_loc_conf_t
*lcf
= conf
;
2325 if (lcf
->types
== NULL
) {
2326 lcf
->types
= ngx_array_create(cf
->pool
, 64, sizeof(ngx_hash_key_t
));
2327 if (lcf
->types
== NULL
) {
2328 return NGX_CONF_ERROR
;
2333 cf
->handler
= ngx_http_core_type
;
2334 cf
->handler_conf
= conf
;
2336 rv
= ngx_conf_parse(cf
, NULL
);
2345 ngx_http_core_type(ngx_conf_t
*cf
, ngx_command_t
*dummy
, void *conf
)
2347 ngx_http_core_loc_conf_t
*lcf
= conf
;
2349 ngx_str_t
*value
, *content_type
, *old
, file
;
2350 ngx_uint_t i
, n
, hash
;
2351 ngx_hash_key_t
*type
;
2353 value
= cf
->args
->elts
;
2355 if (ngx_strcmp(value
[0].data
, "include") == 0) {
2358 if (ngx_conf_full_name(cf
->cycle
, &file
, 1) == NGX_ERROR
){
2359 return NGX_CONF_ERROR
;
2362 ngx_log_debug1(NGX_LOG_DEBUG_CORE
, cf
->log
, 0, "include %s", file
.data
);
2364 return ngx_conf_parse(cf
, &file
);
2367 content_type
= ngx_palloc(cf
->pool
, sizeof(ngx_str_t
));
2368 if (content_type
== NULL
) {
2369 return NGX_CONF_ERROR
;
2372 *content_type
= value
[0];
2374 for (i
= 1; i
< cf
->args
->nelts
; i
++) {
2376 hash
= ngx_hash_strlow(value
[i
].data
, value
[i
].data
, value
[i
].len
);
2378 type
= lcf
->types
->elts
;
2379 for (n
= 0; n
< lcf
->types
->nelts
; n
++) {
2380 if (ngx_strcmp(value
[i
].data
, type
[n
].key
.data
) == 0) {
2381 old
= type
[n
].value
;
2382 type
[n
].value
= content_type
;
2384 ngx_conf_log_error(NGX_LOG_WARN
, cf
, 0,
2385 "duplicate extention \"%V\", "
2386 "content type: \"%V\", "
2387 "old content type: \"%V\"",
2388 &value
[i
], content_type
, old
);
2394 type
= ngx_array_push(lcf
->types
);
2396 return NGX_CONF_ERROR
;
2399 type
->key
= value
[i
];
2400 type
->key_hash
= hash
;
2401 type
->value
= content_type
;
2409 ngx_http_core_preconfiguration(ngx_conf_t
*cf
)
2411 return ngx_http_variables_add_core_vars(cf
);
2416 ngx_http_core_create_main_conf(ngx_conf_t
*cf
)
2418 ngx_http_core_main_conf_t
*cmcf
;
2420 cmcf
= ngx_pcalloc(cf
->pool
, sizeof(ngx_http_core_main_conf_t
));
2422 return NGX_CONF_ERROR
;
2425 if (ngx_array_init(&cmcf
->servers
, cf
->pool
, 4,
2426 sizeof(ngx_http_core_srv_conf_t
*))
2429 return NGX_CONF_ERROR
;
2432 cmcf
->server_names_hash_max_size
= NGX_CONF_UNSET_UINT
;
2433 cmcf
->server_names_hash_bucket_size
= NGX_CONF_UNSET_UINT
;
2435 cmcf
->variables_hash_max_size
= NGX_CONF_UNSET_UINT
;
2436 cmcf
->variables_hash_bucket_size
= NGX_CONF_UNSET_UINT
;
2443 ngx_http_core_init_main_conf(ngx_conf_t
*cf
, void *conf
)
2445 ngx_http_core_main_conf_t
*cmcf
= conf
;
2447 if (cmcf
->server_names_hash_max_size
== NGX_CONF_UNSET_UINT
) {
2448 cmcf
->server_names_hash_max_size
= 512;
2451 if (cmcf
->server_names_hash_bucket_size
== NGX_CONF_UNSET_UINT
) {
2452 cmcf
->server_names_hash_bucket_size
= ngx_cacheline_size
;
2455 cmcf
->server_names_hash_bucket_size
=
2456 ngx_align(cmcf
->server_names_hash_bucket_size
, ngx_cacheline_size
);
2459 if (cmcf
->variables_hash_max_size
== NGX_CONF_UNSET_UINT
) {
2460 cmcf
->variables_hash_max_size
= 512;
2463 if (cmcf
->variables_hash_bucket_size
== NGX_CONF_UNSET_UINT
) {
2464 cmcf
->variables_hash_bucket_size
= 64;
2467 cmcf
->variables_hash_bucket_size
=
2468 ngx_align(cmcf
->variables_hash_bucket_size
, ngx_cacheline_size
);
2475 ngx_http_core_create_srv_conf(ngx_conf_t
*cf
)
2477 ngx_http_core_srv_conf_t
*cscf
;
2479 cscf
= ngx_pcalloc(cf
->pool
, sizeof(ngx_http_core_srv_conf_t
));
2481 return NGX_CONF_ERROR
;
2485 * set by ngx_pcalloc():
2487 * conf->client_large_buffers.num = 0;
2490 if (ngx_array_init(&cscf
->listen
, cf
->pool
, 4, sizeof(ngx_http_listen_t
))
2493 return NGX_CONF_ERROR
;
2496 if (ngx_array_init(&cscf
->server_names
, cf
->temp_pool
, 4,
2497 sizeof(ngx_http_server_name_t
))
2500 return NGX_CONF_ERROR
;
2503 cscf
->connection_pool_size
= NGX_CONF_UNSET_SIZE
;
2504 cscf
->request_pool_size
= NGX_CONF_UNSET_SIZE
;
2505 cscf
->client_header_timeout
= NGX_CONF_UNSET_MSEC
;
2506 cscf
->client_header_buffer_size
= NGX_CONF_UNSET_SIZE
;
2507 cscf
->ignore_invalid_headers
= NGX_CONF_UNSET
;
2508 cscf
->merge_slashes
= NGX_CONF_UNSET
;
2515 ngx_http_core_merge_srv_conf(ngx_conf_t
*cf
, void *parent
, void *child
)
2517 ngx_http_core_srv_conf_t
*prev
= parent
;
2518 ngx_http_core_srv_conf_t
*conf
= child
;
2520 ngx_http_listen_t
*ls
;
2521 ngx_http_server_name_t
*sn
;
2523 /* TODO: it does not merge, it inits only */
2525 if (conf
->listen
.nelts
== 0) {
2526 ls
= ngx_array_push(&conf
->listen
);
2528 return NGX_CONF_ERROR
;
2531 ngx_memzero(ls
, sizeof(ngx_http_listen_t
));
2533 ls
->addr
= INADDR_ANY
;
2537 /* STUB: getuid() should be cached */
2538 ls
->port
= (getuid() == 0) ? 80 : 8000;
2540 ls
->family
= AF_INET
;
2542 ls
->conf
.backlog
= NGX_LISTEN_BACKLOG
;
2543 ls
->conf
.rcvbuf
= -1;
2544 ls
->conf
.sndbuf
= -1;
2547 if (conf
->server_name
.data
== NULL
) {
2548 conf
->server_name
= cf
->cycle
->hostname
;
2550 sn
= ngx_array_push(&conf
->server_names
);
2552 return NGX_CONF_ERROR
;
2558 sn
->core_srv_conf
= conf
;
2559 sn
->name
.len
= conf
->server_name
.len
;
2560 sn
->name
.data
= conf
->server_name
.data
;
2563 ngx_conf_merge_size_value(conf
->connection_pool_size
,
2564 prev
->connection_pool_size
, 256);
2565 ngx_conf_merge_size_value(conf
->request_pool_size
,
2566 prev
->request_pool_size
, 4096);
2567 ngx_conf_merge_msec_value(conf
->client_header_timeout
,
2568 prev
->client_header_timeout
, 60000);
2569 ngx_conf_merge_size_value(conf
->client_header_buffer_size
,
2570 prev
->client_header_buffer_size
, 1024);
2571 ngx_conf_merge_bufs_value(conf
->large_client_header_buffers
,
2572 prev
->large_client_header_buffers
,
2575 if (conf
->large_client_header_buffers
.size
< conf
->connection_pool_size
) {
2576 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
2577 "the \"large_client_header_buffers\" size must be "
2578 "equal to or bigger than \"connection_pool_size\"");
2579 return NGX_CONF_ERROR
;
2582 ngx_conf_merge_value(conf
->ignore_invalid_headers
,
2583 prev
->ignore_invalid_headers
, 1);
2585 ngx_conf_merge_value(conf
->merge_slashes
, prev
->merge_slashes
, 1);
2592 ngx_http_core_create_loc_conf(ngx_conf_t
*cf
)
2594 ngx_http_core_loc_conf_t
*lcf
;
2596 lcf
= ngx_pcalloc(cf
->pool
, sizeof(ngx_http_core_loc_conf_t
));
2598 return NGX_CONF_ERROR
;
2602 * set by ngx_pcalloc():
2604 * lcf->root = { 0, NULL };
2605 * lcf->limit_except = 0;
2606 * lcf->post_action = { 0, NULL };
2607 * lcf->types = NULL;
2608 * lcf->default_type = { 0, NULL };
2609 * lcf->err_log = NULL;
2610 * lcf->error_pages = NULL;
2611 * lcf->client_body_path = NULL;
2612 * lcf->regex = NULL;
2613 * lcf->exact_match = 0;
2614 * lcf->auto_redirect = 0;
2616 * lcf->gzip_proxied = 0;
2619 lcf
->client_max_body_size
= NGX_CONF_UNSET
;
2620 lcf
->client_body_buffer_size
= NGX_CONF_UNSET_SIZE
;
2621 lcf
->client_body_timeout
= NGX_CONF_UNSET_MSEC
;
2622 lcf
->satisfy
= NGX_CONF_UNSET_UINT
;
2623 lcf
->internal
= NGX_CONF_UNSET
;
2624 lcf
->client_body_in_file_only
= NGX_CONF_UNSET
;
2625 lcf
->sendfile
= NGX_CONF_UNSET
;
2626 lcf
->sendfile_max_chunk
= NGX_CONF_UNSET_SIZE
;
2627 lcf
->directio
= NGX_CONF_UNSET
;
2628 lcf
->tcp_nopush
= NGX_CONF_UNSET
;
2629 lcf
->tcp_nodelay
= NGX_CONF_UNSET
;
2630 lcf
->send_timeout
= NGX_CONF_UNSET_MSEC
;
2631 lcf
->send_lowat
= NGX_CONF_UNSET_SIZE
;
2632 lcf
->postpone_output
= NGX_CONF_UNSET_SIZE
;
2633 lcf
->limit_rate
= NGX_CONF_UNSET_SIZE
;
2634 lcf
->keepalive_timeout
= NGX_CONF_UNSET_MSEC
;
2635 lcf
->keepalive_header
= NGX_CONF_UNSET
;
2636 lcf
->lingering_time
= NGX_CONF_UNSET_MSEC
;
2637 lcf
->lingering_timeout
= NGX_CONF_UNSET_MSEC
;
2638 lcf
->resolver_timeout
= NGX_CONF_UNSET_MSEC
;
2639 lcf
->reset_timedout_connection
= NGX_CONF_UNSET
;
2640 lcf
->server_name_in_redirect
= NGX_CONF_UNSET
;
2641 lcf
->port_in_redirect
= NGX_CONF_UNSET
;
2642 lcf
->msie_padding
= NGX_CONF_UNSET
;
2643 lcf
->msie_refresh
= NGX_CONF_UNSET
;
2644 lcf
->log_not_found
= NGX_CONF_UNSET
;
2645 lcf
->recursive_error_pages
= NGX_CONF_UNSET
;
2646 lcf
->server_tokens
= NGX_CONF_UNSET
;
2647 lcf
->types_hash_max_size
= NGX_CONF_UNSET_UINT
;
2648 lcf
->types_hash_bucket_size
= NGX_CONF_UNSET_UINT
;
2650 lcf
->open_file_cache
= NGX_CONF_UNSET_PTR
;
2651 lcf
->open_file_cache_valid
= NGX_CONF_UNSET
;
2652 lcf
->open_file_cache_min_uses
= NGX_CONF_UNSET_UINT
;
2653 lcf
->open_file_cache_errors
= NGX_CONF_UNSET
;
2654 lcf
->open_file_cache_events
= NGX_CONF_UNSET
;
2657 lcf
->gzip_vary
= NGX_CONF_UNSET
;
2658 lcf
->gzip_http_version
= NGX_CONF_UNSET_UINT
;
2660 lcf
->gzip_disable
= NGX_CONF_UNSET_PTR
;
2668 static ngx_str_t ngx_http_core_text_html_type
= ngx_string("text/html");
2669 static ngx_str_t ngx_http_core_image_gif_type
= ngx_string("image/gif");
2670 static ngx_str_t ngx_http_core_image_jpeg_type
= ngx_string("image/jpeg");
2672 static ngx_hash_key_t ngx_http_core_default_types
[] = {
2673 { ngx_string("html"), 0, &ngx_http_core_text_html_type
},
2674 { ngx_string("gif"), 0, &ngx_http_core_image_gif_type
},
2675 { ngx_string("jpg"), 0, &ngx_http_core_image_jpeg_type
},
2676 { ngx_null_string
, 0, NULL
}
2681 ngx_http_core_merge_loc_conf(ngx_conf_t
*cf
, void *parent
, void *child
)
2683 ngx_http_core_loc_conf_t
*prev
= parent
;
2684 ngx_http_core_loc_conf_t
*conf
= child
;
2687 ngx_hash_key_t
*type
;
2688 ngx_hash_init_t types_hash
;
2690 if (conf
->root
.data
== NULL
) {
2692 conf
->alias
= prev
->alias
;
2693 conf
->root
= prev
->root
;
2694 conf
->root_lengths
= prev
->root_lengths
;
2695 conf
->root_values
= prev
->root_values
;
2697 if (prev
->root
.data
== NULL
) {
2698 conf
->root
.len
= sizeof("html") - 1;
2699 conf
->root
.data
= (u_char
*) "html";
2701 if (ngx_conf_full_name(cf
->cycle
, &conf
->root
, 0) == NGX_ERROR
) {
2702 return NGX_CONF_ERROR
;
2707 if (conf
->post_action
.data
== NULL
) {
2708 conf
->post_action
= prev
->post_action
;
2711 ngx_conf_merge_uint_value(conf
->types_hash_max_size
,
2712 prev
->types_hash_max_size
, 1024);
2714 ngx_conf_merge_uint_value(conf
->types_hash_bucket_size
,
2715 prev
->types_hash_bucket_size
,
2716 ngx_cacheline_size
);
2718 conf
->types_hash_bucket_size
= ngx_align(conf
->types_hash_bucket_size
,
2719 ngx_cacheline_size
);
2722 * the special handling the "types" directive in the "http" section
2723 * to inherit the http's conf->types_hash to all servers
2726 if (prev
->types
&& prev
->types_hash
.buckets
== NULL
) {
2728 types_hash
.hash
= &prev
->types_hash
;
2729 types_hash
.key
= ngx_hash_key_lc
;
2730 types_hash
.max_size
= conf
->types_hash_max_size
;
2731 types_hash
.bucket_size
= conf
->types_hash_bucket_size
;
2732 types_hash
.name
= "types_hash";
2733 types_hash
.pool
= cf
->pool
;
2734 types_hash
.temp_pool
= NULL
;
2736 if (ngx_hash_init(&types_hash
, prev
->types
->elts
, prev
->types
->nelts
)
2739 return NGX_CONF_ERROR
;
2743 if (conf
->types
== NULL
) {
2744 conf
->types
= prev
->types
;
2745 conf
->types_hash
= prev
->types_hash
;
2748 if (conf
->types
== NULL
) {
2749 conf
->types
= ngx_array_create(cf
->pool
, 4, sizeof(ngx_hash_key_t
));
2750 if (conf
->types
== NULL
) {
2751 return NGX_CONF_ERROR
;
2754 for (i
= 0; ngx_http_core_default_types
[i
].key
.len
; i
++) {
2755 type
= ngx_array_push(conf
->types
);
2757 return NGX_CONF_ERROR
;
2760 type
->key
= ngx_http_core_default_types
[i
].key
;
2762 ngx_hash_key_lc(ngx_http_core_default_types
[i
].key
.data
,
2763 ngx_http_core_default_types
[i
].key
.len
);
2764 type
->value
= ngx_http_core_default_types
[i
].value
;
2768 if (conf
->types_hash
.buckets
== NULL
) {
2770 types_hash
.hash
= &conf
->types_hash
;
2771 types_hash
.key
= ngx_hash_key_lc
;
2772 types_hash
.max_size
= conf
->types_hash_max_size
;
2773 types_hash
.bucket_size
= conf
->types_hash_bucket_size
;
2774 types_hash
.name
= "mime_types_hash";
2775 types_hash
.pool
= cf
->pool
;
2776 types_hash
.temp_pool
= NULL
;
2778 if (ngx_hash_init(&types_hash
, conf
->types
->elts
, conf
->types
->nelts
)
2781 return NGX_CONF_ERROR
;
2785 if (conf
->err_log
== NULL
) {
2786 if (prev
->err_log
) {
2787 conf
->err_log
= prev
->err_log
;
2789 conf
->err_log
= cf
->cycle
->new_log
;
2793 if (conf
->error_pages
== NULL
&& prev
->error_pages
) {
2794 conf
->error_pages
= prev
->error_pages
;
2797 ngx_conf_merge_str_value(conf
->default_type
,
2798 prev
->default_type
, "text/plain");
2800 ngx_conf_merge_off_value(conf
->client_max_body_size
,
2801 prev
->client_max_body_size
, 1 * 1024 * 1024);
2802 ngx_conf_merge_size_value(conf
->client_body_buffer_size
,
2803 prev
->client_body_buffer_size
,
2804 (size_t) 2 * ngx_pagesize
);
2805 ngx_conf_merge_msec_value(conf
->client_body_timeout
,
2806 prev
->client_body_timeout
, 60000);
2808 ngx_conf_merge_uint_value(conf
->satisfy
, prev
->satisfy
,
2809 NGX_HTTP_SATISFY_ALL
);
2810 ngx_conf_merge_value(conf
->internal
, prev
->internal
, 0);
2811 ngx_conf_merge_value(conf
->client_body_in_file_only
,
2812 prev
->client_body_in_file_only
, 0);
2813 ngx_conf_merge_value(conf
->sendfile
, prev
->sendfile
, 0);
2814 ngx_conf_merge_size_value(conf
->sendfile_max_chunk
,
2815 prev
->sendfile_max_chunk
, 0);
2816 ngx_conf_merge_off_value(conf
->directio
, prev
->directio
,
2817 NGX_MAX_OFF_T_VALUE
);
2818 ngx_conf_merge_value(conf
->tcp_nopush
, prev
->tcp_nopush
, 0);
2819 ngx_conf_merge_value(conf
->tcp_nodelay
, prev
->tcp_nodelay
, 1);
2821 ngx_conf_merge_msec_value(conf
->send_timeout
, prev
->send_timeout
, 60000);
2822 ngx_conf_merge_size_value(conf
->send_lowat
, prev
->send_lowat
, 0);
2823 ngx_conf_merge_size_value(conf
->postpone_output
, prev
->postpone_output
,
2825 ngx_conf_merge_size_value(conf
->limit_rate
, prev
->limit_rate
, 0);
2826 ngx_conf_merge_msec_value(conf
->keepalive_timeout
,
2827 prev
->keepalive_timeout
, 75000);
2828 ngx_conf_merge_sec_value(conf
->keepalive_header
,
2829 prev
->keepalive_header
, 0);
2830 ngx_conf_merge_msec_value(conf
->lingering_time
,
2831 prev
->lingering_time
, 30000);
2832 ngx_conf_merge_msec_value(conf
->lingering_timeout
,
2833 prev
->lingering_timeout
, 5000);
2834 ngx_conf_merge_msec_value(conf
->resolver_timeout
,
2835 prev
->resolver_timeout
, 30000);
2837 if (conf
->resolver
== NULL
) {
2839 if (prev
->resolver
== NULL
) {
2842 * create dummy resolver in http {} context
2843 * to inherit it in all servers
2846 prev
->resolver
= ngx_resolver_create(cf
, NULL
);
2847 if (prev
->resolver
== NULL
) {
2848 return NGX_CONF_ERROR
;
2852 conf
->resolver
= prev
->resolver
;
2855 ngx_conf_merge_path_value(conf
->client_body_temp_path
,
2856 prev
->client_body_temp_path
,
2857 NGX_HTTP_CLIENT_TEMP_PATH
, 0, 0, 0,
2858 ngx_garbage_collector_temp_handler
, cf
);
2860 ngx_conf_merge_value(conf
->reset_timedout_connection
,
2861 prev
->reset_timedout_connection
, 0);
2862 ngx_conf_merge_value(conf
->server_name_in_redirect
,
2863 prev
->server_name_in_redirect
, 1);
2864 ngx_conf_merge_value(conf
->port_in_redirect
, prev
->port_in_redirect
, 1);
2865 ngx_conf_merge_value(conf
->msie_padding
, prev
->msie_padding
, 1);
2866 ngx_conf_merge_value(conf
->msie_refresh
, prev
->msie_refresh
, 0);
2867 ngx_conf_merge_value(conf
->log_not_found
, prev
->log_not_found
, 1);
2868 ngx_conf_merge_value(conf
->recursive_error_pages
,
2869 prev
->recursive_error_pages
, 0);
2870 ngx_conf_merge_value(conf
->server_tokens
, prev
->server_tokens
, 1);
2872 ngx_conf_merge_ptr_value(conf
->open_file_cache
,
2873 prev
->open_file_cache
, NULL
);
2875 ngx_conf_merge_sec_value(conf
->open_file_cache_valid
,
2876 prev
->open_file_cache_valid
, 60);
2878 ngx_conf_merge_uint_value(conf
->open_file_cache_min_uses
,
2879 prev
->open_file_cache_min_uses
, 1);
2881 ngx_conf_merge_sec_value(conf
->open_file_cache_errors
,
2882 prev
->open_file_cache_errors
, 0);
2884 ngx_conf_merge_sec_value(conf
->open_file_cache_events
,
2885 prev
->open_file_cache_events
, 0);
2888 ngx_conf_merge_value(conf
->gzip_vary
, prev
->gzip_vary
, 0);
2889 ngx_conf_merge_uint_value(conf
->gzip_http_version
, prev
->gzip_http_version
,
2890 NGX_HTTP_VERSION_11
);
2891 ngx_conf_merge_bitmask_value(conf
->gzip_proxied
, prev
->gzip_proxied
,
2892 (NGX_CONF_BITMASK_SET
|NGX_HTTP_GZIP_PROXIED_OFF
));
2895 ngx_conf_merge_ptr_value(conf
->gzip_disable
, prev
->gzip_disable
, NULL
);
2907 ngx_http_core_listen(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
2909 ngx_http_core_srv_conf_t
*scf
= conf
;
2911 ngx_str_t
*value
, size
;
2914 ngx_http_listen_t
*ls
;
2917 * TODO: check duplicate 'listen' directives,
2918 * add resolved name to server names ???
2921 value
= cf
->args
->elts
;
2923 ngx_memzero(&u
, sizeof(ngx_url_t
));
2927 u
.default_port
= 80;
2929 if (ngx_parse_url(cf
->pool
, &u
) != NGX_OK
) {
2931 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
2932 "%s in \"%V\" of the \"listen\" directive",
2936 return NGX_CONF_ERROR
;
2939 ls
= ngx_array_push(&scf
->listen
);
2941 return NGX_CONF_ERROR
;
2944 ngx_memzero(ls
, sizeof(ngx_http_listen_t
));
2946 ls
->family
= AF_INET
;
2947 ls
->addr
= u
.addr
.in_addr
;
2949 ls
->file_name
= cf
->conf_file
->file
.name
.data
;
2950 ls
->line
= cf
->conf_file
->line
;
2951 ls
->conf
.backlog
= NGX_LISTEN_BACKLOG
;
2952 ls
->conf
.rcvbuf
= -1;
2953 ls
->conf
.sndbuf
= -1;
2955 n
= ngx_inet_ntop(AF_INET
, &ls
->addr
, ls
->conf
.addr
, INET_ADDRSTRLEN
+ 6);
2956 ngx_sprintf(&ls
->conf
.addr
[n
], ":%ui", ls
->port
);
2958 if (cf
->args
->nelts
== 2) {
2962 if (ngx_strcmp(value
[2].data
, "default") == 0) {
2963 ls
->conf
.default_server
= 1;
2970 for ( /* void */ ; n
< cf
->args
->nelts
; n
++) {
2972 if (ls
->conf
.default_server
== 0) {
2973 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
2974 "\"%V\" parameter can be specified for "
2975 "the default \"listen\" directive only",
2977 return NGX_CONF_ERROR
;
2980 if (ngx_strcmp(value
[n
].data
, "bind") == 0) {
2985 if (ngx_strncmp(value
[n
].data
, "backlog=", 8) == 0) {
2986 ls
->conf
.backlog
= ngx_atoi(value
[n
].data
+ 8, value
[n
].len
- 8);
2989 if (ls
->conf
.backlog
== NGX_ERROR
|| ls
->conf
.backlog
== 0) {
2990 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
2991 "invalid backlog \"%V\"", &value
[n
]);
2992 return NGX_CONF_ERROR
;
2998 if (ngx_strncmp(value
[n
].data
, "rcvbuf=", 7) == 0) {
2999 size
.len
= value
[n
].len
- 7;
3000 size
.data
= value
[n
].data
+ 7;
3002 ls
->conf
.rcvbuf
= ngx_parse_size(&size
);
3005 if (ls
->conf
.rcvbuf
== NGX_ERROR
) {
3006 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3007 "invalid rcvbuf \"%V\"", &value
[n
]);
3008 return NGX_CONF_ERROR
;
3014 if (ngx_strncmp(value
[n
].data
, "sndbuf=", 7) == 0) {
3015 size
.len
= value
[n
].len
- 7;
3016 size
.data
= value
[n
].data
+ 7;
3018 ls
->conf
.sndbuf
= ngx_parse_size(&size
);
3021 if (ls
->conf
.sndbuf
== NGX_ERROR
) {
3022 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3023 "invalid sndbuf \"%V\"", &value
[n
]);
3024 return NGX_CONF_ERROR
;
3030 if (ngx_strncmp(value
[n
].data
, "accept_filter=", 14) == 0) {
3031 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
3032 ls
->conf
.accept_filter
= (char *) &value
[n
].data
[14];
3035 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3036 "accept filters \"%V\" are not supported "
3037 "on this platform, ignored",
3043 if (ngx_strcmp(value
[n
].data
, "deferred") == 0) {
3044 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
3045 ls
->conf
.deferred_accept
= 1;
3048 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3049 "the deferred accept is not supported "
3050 "on this platform, ignored");
3055 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3056 "the invalid \"%V\" parameter", &value
[n
]);
3057 return NGX_CONF_ERROR
;
3065 ngx_http_core_server_name(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
3067 ngx_http_core_srv_conf_t
*cscf
= conf
;
3070 ngx_str_t
*value
, name
;
3072 ngx_http_server_name_t
*sn
;
3074 value
= cf
->args
->elts
;
3076 ch
= value
[1].data
[0];
3078 if (cscf
->server_name
.data
== NULL
&& value
[1].len
) {
3086 cscf
->server_name
.len
= name
.len
;
3087 cscf
->server_name
.data
= ngx_pstrdup(cf
->pool
, &name
);
3088 if (cscf
->server_name
.data
== NULL
) {
3089 return NGX_CONF_ERROR
;
3093 for (i
= 1; i
< cf
->args
->nelts
; i
++) {
3095 ch
= value
[i
].data
[0];
3097 if (value
[i
].len
== 0
3098 || (ch
== '*' && (value
[i
].len
< 3 || value
[i
].data
[1] != '.'))
3099 || (ch
== '.' && value
[i
].len
< 2))
3101 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3102 "server name \"%V\" is invalid", &value
[i
]);
3103 return NGX_CONF_ERROR
;
3106 if (ngx_strchr(value
[i
].data
, '/')) {
3107 ngx_conf_log_error(NGX_LOG_WARN
, cf
, 0,
3108 "server name \"%V\" has strange symbols",
3112 if (value
[i
].len
== 1 && ch
== '*') {
3113 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3114 "\"server_name *\" is unsupported, use "
3115 "\"server_name_in_redirect off\" instead");
3116 return NGX_CONF_ERROR
;
3119 sn
= ngx_array_push(&cscf
->server_names
);
3121 return NGX_CONF_ERROR
;
3127 sn
->core_srv_conf
= cscf
;
3128 sn
->name
= value
[i
];
3130 if (value
[i
].data
[0] != '~') {
3137 u_char errstr
[NGX_MAX_CONF_ERRSTR
];
3139 err
.len
= NGX_MAX_CONF_ERRSTR
;
3145 sn
->regex
= ngx_regex_compile(&value
[i
], 0, cf
->pool
, &err
);
3147 if (sn
->regex
== NULL
) {
3148 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0, "%s", err
.data
);
3149 return NGX_CONF_ERROR
;
3152 sn
->name
= value
[i
];
3155 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3156 "the using of the regex \"%V\" "
3157 "requires PCRE library", &value
[i
]);
3159 return NGX_CONF_ERROR
;
3168 ngx_http_core_root(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
3170 ngx_http_core_loc_conf_t
*lcf
= conf
;
3173 ngx_uint_t alias
, n
;
3174 ngx_http_script_compile_t sc
;
3176 alias
= (cmd
->name
.len
== sizeof("alias") - 1) ? 1 : 0;
3178 if (lcf
->root
.data
) {
3180 /* the (ngx_uint_t) cast is required by gcc 2.7.2.3 */
3182 if ((ngx_uint_t
) lcf
->alias
== alias
) {
3183 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3184 "\"%V\" directive is duplicate",
3187 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3188 "\"%V\" directive is duplicate, "
3189 "\"%s\" directive is specified before",
3190 &cmd
->name
, lcf
->alias
? "alias" : "root");
3193 return NGX_CONF_ERROR
;
3196 if (lcf
->named
&& alias
) {
3197 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3198 "the \"alias\" directive may not be used "
3199 "inside named location");
3201 return NGX_CONF_ERROR
;
3206 if (lcf
->regex
&& alias
) {
3207 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3208 "the \"alias\" directive may not be used "
3209 "inside location given by regular expression");
3211 return NGX_CONF_ERROR
;
3216 value
= cf
->args
->elts
;
3218 if (ngx_strstr(value
[1].data
, "$document_root")
3219 || ngx_strstr(value
[1].data
, "${document_root}"))
3221 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3222 "the $document_root variable may not be used "
3223 "in the \"%V\" directive",
3226 return NGX_CONF_ERROR
;
3230 lcf
->root
= value
[1];
3232 if (!alias
&& lcf
->root
.data
[lcf
->root
.len
- 1] == '/') {
3236 if (lcf
->root
.data
[0] != '$') {
3237 if (ngx_conf_full_name(cf
->cycle
, &lcf
->root
, 0) == NGX_ERROR
) {
3238 return NGX_CONF_ERROR
;
3242 n
= ngx_http_script_variables_count(&lcf
->root
);
3248 ngx_memzero(&sc
, sizeof(ngx_http_script_compile_t
));
3251 sc
.source
= &lcf
->root
;
3252 sc
.lengths
= &lcf
->root_lengths
;
3253 sc
.values
= &lcf
->root_values
;
3255 sc
.complete_lengths
= 1;
3256 sc
.complete_values
= 1;
3258 if (ngx_http_script_compile(&sc
) != NGX_OK
) {
3259 return NGX_CONF_ERROR
;
3266 static ngx_http_method_name_t ngx_methods_names
[] = {
3267 { (u_char
*) "GET", (uint32_t) ~NGX_HTTP_GET
},
3268 { (u_char
*) "HEAD", (uint32_t) ~NGX_HTTP_HEAD
},
3269 { (u_char
*) "POST", (uint32_t) ~NGX_HTTP_POST
},
3270 { (u_char
*) "PUT", (uint32_t) ~NGX_HTTP_PUT
},
3271 { (u_char
*) "DELETE", (uint32_t) ~NGX_HTTP_DELETE
},
3272 { (u_char
*) "MKCOL", (uint32_t) ~NGX_HTTP_MKCOL
},
3273 { (u_char
*) "COPY", (uint32_t) ~NGX_HTTP_COPY
},
3274 { (u_char
*) "MOVE", (uint32_t) ~NGX_HTTP_MOVE
},
3275 { (u_char
*) "OPTIONS", (uint32_t) ~NGX_HTTP_OPTIONS
},
3276 { (u_char
*) "PROPFIND" , (uint32_t) ~NGX_HTTP_PROPFIND
},
3277 { (u_char
*) "PROPPATCH", (uint32_t) ~NGX_HTTP_PROPPATCH
},
3278 { (u_char
*) "LOCK", (uint32_t) ~NGX_HTTP_LOCK
},
3279 { (u_char
*) "UNLOCK", (uint32_t) ~NGX_HTTP_UNLOCK
},
3285 ngx_http_core_limit_except(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
3287 ngx_http_core_loc_conf_t
*pclcf
= conf
;
3294 ngx_http_module_t
*module
;
3295 ngx_http_conf_ctx_t
*ctx
, *pctx
;
3296 ngx_http_method_name_t
*name
;
3297 ngx_http_core_loc_conf_t
*clcf
;
3299 if (pclcf
->limit_except
) {
3303 pclcf
->limit_except
= 0xffffffff;
3305 value
= cf
->args
->elts
;
3307 for (i
= 1; i
< cf
->args
->nelts
; i
++) {
3308 for (name
= ngx_methods_names
; name
->name
; name
++) {
3310 if (ngx_strcasecmp(value
[i
].data
, name
->name
) == 0) {
3311 pclcf
->limit_except
&= name
->method
;
3316 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3317 "invalid method \"%V\"", &value
[i
]);
3318 return NGX_CONF_ERROR
;
3324 if (!(pclcf
->limit_except
& NGX_HTTP_GET
)) {
3325 pclcf
->limit_except
&= (uint32_t) ~NGX_HTTP_HEAD
;
3328 ctx
= ngx_pcalloc(cf
->pool
, sizeof(ngx_http_conf_ctx_t
));
3330 return NGX_CONF_ERROR
;
3334 ctx
->main_conf
= pctx
->main_conf
;
3335 ctx
->srv_conf
= pctx
->srv_conf
;
3337 ctx
->loc_conf
= ngx_pcalloc(cf
->pool
, sizeof(void *) * ngx_http_max_module
);
3338 if (ctx
->loc_conf
== NULL
) {
3339 return NGX_CONF_ERROR
;
3342 for (i
= 0; ngx_modules
[i
]; i
++) {
3343 if (ngx_modules
[i
]->type
!= NGX_HTTP_MODULE
) {
3347 module
= ngx_modules
[i
]->ctx
;
3349 if (module
->create_loc_conf
) {
3351 mconf
= module
->create_loc_conf(cf
);
3352 if (mconf
== NULL
) {
3353 return NGX_CONF_ERROR
;
3356 ctx
->loc_conf
[ngx_modules
[i
]->ctx_index
] = mconf
;
3361 clcf
= ctx
->loc_conf
[ngx_http_core_module
.ctx_index
];
3362 pclcf
->limit_except_loc_conf
= ctx
->loc_conf
;
3363 clcf
->loc_conf
= ctx
->loc_conf
;
3364 clcf
->name
= pclcf
->name
;
3367 if (ngx_http_add_location(cf
, &pclcf
->locations
, clcf
) != NGX_OK
) {
3368 return NGX_CONF_ERROR
;
3373 cf
->cmd_type
= NGX_HTTP_LMT_CONF
;
3375 rv
= ngx_conf_parse(cf
, NULL
);
3384 ngx_http_core_directio(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
3386 ngx_http_core_loc_conf_t
*clcf
= conf
;
3390 if (clcf
->directio
!= NGX_CONF_UNSET
) {
3391 return "is duplicate";
3394 value
= cf
->args
->elts
;
3396 if (ngx_strcmp(value
[1].data
, "off") == 0) {
3397 clcf
->directio
= NGX_MAX_OFF_T_VALUE
;
3401 clcf
->directio
= ngx_parse_offset(&value
[1]);
3402 if (clcf
->directio
== (off_t
) NGX_ERROR
) {
3403 return "invalid value";
3411 ngx_http_core_error_page(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
3413 ngx_http_core_loc_conf_t
*lcf
= conf
;
3416 ngx_int_t overwrite
;
3417 ngx_str_t
*value
, uri
;
3418 ngx_uint_t i
, n
, nvar
;
3419 ngx_array_t
*uri_lengths
, *uri_values
;
3420 ngx_http_err_page_t
*err
;
3421 ngx_http_script_compile_t sc
;
3423 if (lcf
->error_pages
== NULL
) {
3424 lcf
->error_pages
= ngx_array_create(cf
->pool
, 4,
3425 sizeof(ngx_http_err_page_t
));
3426 if (lcf
->error_pages
== NULL
) {
3427 return NGX_CONF_ERROR
;
3431 value
= cf
->args
->elts
;
3433 i
= cf
->args
->nelts
- 2;
3435 if (value
[i
].data
[0] == '=') {
3437 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3438 "invalid value \"%V\"", &value
[i
]);
3439 return NGX_CONF_ERROR
;
3442 if (value
[i
].len
> 1) {
3443 overwrite
= ngx_atoi(&value
[i
].data
[1], value
[i
].len
- 1);
3445 if (overwrite
== NGX_ERROR
) {
3446 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3447 "invalid value \"%V\"", &value
[i
]);
3448 return NGX_CONF_ERROR
;
3462 uri
= value
[cf
->args
->nelts
- 1];
3466 nvar
= ngx_http_script_variables_count(&uri
);
3469 ngx_memzero(&sc
, sizeof(ngx_http_script_compile_t
));
3473 sc
.lengths
= &uri_lengths
;
3474 sc
.values
= &uri_values
;
3475 sc
.variables
= nvar
;
3476 sc
.complete_lengths
= 1;
3477 sc
.complete_values
= 1;
3479 if (ngx_http_script_compile(&sc
) != NGX_OK
) {
3480 return NGX_CONF_ERROR
;
3484 args
= (u_char
*) ngx_strchr(uri
.data
, '?');
3486 for (i
= 1; i
< cf
->args
->nelts
- n
; i
++) {
3487 err
= ngx_array_push(lcf
->error_pages
);
3489 return NGX_CONF_ERROR
;
3492 err
->status
= ngx_atoi(value
[i
].data
, value
[i
].len
);
3494 if (err
->status
== NGX_ERROR
|| err
->status
== 499) {
3495 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3496 "invalid value \"%V\"", &value
[i
]);
3497 return NGX_CONF_ERROR
;
3500 if (err
->status
< 400 || err
->status
> 599) {
3501 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3502 "value \"%V\" must be between 400 and 599",
3504 return NGX_CONF_ERROR
;
3507 if (overwrite
>= 0) {
3508 err
->overwrite
= overwrite
;
3511 switch (err
->status
) {
3512 case NGX_HTTP_TO_HTTPS
:
3513 case NGX_HTTPS_CERT_ERROR
:
3514 case NGX_HTTPS_NO_CERT
:
3515 err
->overwrite
= NGX_HTTP_BAD_REQUEST
;
3519 err
->overwrite
= err
->status
;
3525 err
->uri
.len
= args
- uri
.data
;
3526 err
->uri
.data
= uri
.data
;
3528 err
->args
.len
= (uri
.data
+ uri
.len
) - args
;
3529 err
->args
.data
= args
;
3534 err
->args
.data
= NULL
;
3537 err
->uri_lengths
= uri_lengths
;
3538 err
->uri_values
= uri_values
;
3546 ngx_http_core_open_file_cache(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
3548 ngx_http_core_loc_conf_t
*lcf
= conf
;
3551 ngx_str_t
*value
, s
;
3555 if (lcf
->open_file_cache
!= NGX_CONF_UNSET_PTR
) {
3556 return "is duplicate";
3559 value
= cf
->args
->elts
;
3564 for (i
= 1; i
< cf
->args
->nelts
; i
++) {
3566 if (ngx_strncmp(value
[i
].data
, "max=", 4) == 0) {
3568 max
= ngx_atoi(value
[i
].data
+ 4, value
[i
].len
- 4);
3569 if (max
== NGX_ERROR
) {
3576 if (ngx_strncmp(value
[i
].data
, "inactive=", 9) == 0) {
3578 s
.len
= value
[i
].len
- 9;
3579 s
.data
= value
[i
].data
+ 9;
3581 inactive
= ngx_parse_time(&s
, 1);
3589 if (ngx_strcmp(value
[i
].data
, "off") == 0) {
3591 lcf
->open_file_cache
= NULL
;
3598 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3599 "invalid \"open_file_cache\" parameter \"%V\"",
3601 return NGX_CONF_ERROR
;
3604 if (lcf
->open_file_cache
== NULL
) {
3609 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3610 "\"open_file_cache\" must have \"max\" parameter");
3611 return NGX_CONF_ERROR
;
3614 lcf
->open_file_cache
= ngx_open_file_cache_init(cf
->pool
, max
, inactive
);
3615 if (lcf
->open_file_cache
) {
3619 return NGX_CONF_ERROR
;
3624 ngx_http_core_error_log(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
3626 ngx_http_core_loc_conf_t
*lcf
= conf
;
3628 lcf
->err_log
= ngx_log_create_errlog(cf
->cycle
, cf
->args
);
3629 if (lcf
->err_log
== NULL
) {
3630 return NGX_CONF_ERROR
;
3633 return ngx_set_error_log_levels(cf
, lcf
->err_log
);
3638 ngx_http_core_keepalive(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
3640 ngx_http_core_loc_conf_t
*lcf
= conf
;
3644 if (lcf
->keepalive_timeout
!= NGX_CONF_UNSET_MSEC
) {
3645 return "is duplicate";
3648 value
= cf
->args
->elts
;
3650 lcf
->keepalive_timeout
= ngx_parse_time(&value
[1], 0);
3652 if (lcf
->keepalive_timeout
== (ngx_msec_t
) NGX_ERROR
) {
3653 return "invalid value";
3656 if (lcf
->keepalive_timeout
== (ngx_msec_t
) NGX_PARSE_LARGE_TIME
) {
3657 return "value must be less than 597 hours";
3660 if (cf
->args
->nelts
== 2) {
3664 lcf
->keepalive_header
= ngx_parse_time(&value
[2], 1);
3666 if (lcf
->keepalive_header
== NGX_ERROR
) {
3667 return "invalid value";
3670 if (lcf
->keepalive_header
== NGX_PARSE_LARGE_TIME
) {
3671 return "value must be less than 68 years";
3679 ngx_http_core_internal(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
3681 ngx_http_core_loc_conf_t
*lcf
= conf
;
3683 if (lcf
->internal
!= NGX_CONF_UNSET
) {
3684 return "is duplicate";
3694 ngx_http_core_resolver(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
3696 ngx_http_core_loc_conf_t
*clcf
= conf
;
3701 if (clcf
->resolver
) {
3702 return "is duplicate";
3705 value
= cf
->args
->elts
;
3707 ngx_memzero(&u
, sizeof(ngx_url_t
));
3712 if (ngx_inet_resolve_host(cf
->pool
, &u
) != NGX_OK
) {
3713 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0, "%V: %s", &u
.host
, u
.err
);
3714 return NGX_CONF_ERROR
;
3717 clcf
->resolver
= ngx_resolver_create(cf
, &u
.addrs
[0]);
3718 if (clcf
->resolver
== NULL
) {
3729 ngx_http_gzip_disable(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
3732 ngx_http_core_loc_conf_t
*clcf
= conf
;
3734 ngx_str_t err
, *value
;
3736 ngx_regex_elt_t
*re
;
3737 u_char errstr
[NGX_MAX_CONF_ERRSTR
];
3739 if (clcf
->gzip_disable
== NGX_CONF_UNSET_PTR
) {
3740 clcf
->gzip_disable
= ngx_array_create(cf
->pool
, 2,
3741 sizeof(ngx_regex_elt_t
));
3742 if (clcf
->gzip_disable
== NULL
) {
3743 return NGX_CONF_ERROR
;
3747 value
= cf
->args
->elts
;
3749 err
.len
= NGX_MAX_CONF_ERRSTR
;
3752 for (i
= 1; i
< cf
->args
->nelts
; i
++) {
3754 re
= ngx_array_push(clcf
->gzip_disable
);
3756 return NGX_CONF_ERROR
;
3759 re
->regex
= ngx_regex_compile(&value
[i
], NGX_REGEX_CASELESS
, cf
->pool
,
3762 if (re
->regex
== NULL
) {
3763 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0, "%s", err
.data
);
3764 return NGX_CONF_ERROR
;
3767 re
->name
= value
[i
].data
;
3773 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3774 "\"gzip_disable\" requires PCRE library");
3776 return NGX_CONF_ERROR
;
3784 ngx_http_core_lowat_check(ngx_conf_t
*cf
, void *post
, void *data
)
3789 if ((u_long
) *np
>= ngx_freebsd_net_inet_tcp_sendspace
) {
3790 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3791 "\"send_lowat\" must be less than %d "
3792 "(sysctl net.inet.tcp.sendspace)",
3793 ngx_freebsd_net_inet_tcp_sendspace
);
3795 return NGX_CONF_ERROR
;
3798 #elif !(NGX_HAVE_SO_SNDLOWAT)
3801 ngx_conf_log_error(NGX_LOG_WARN
, cf
, 0,
3802 "\"send_lowat\" is not supported, ignored");
3813 ngx_http_core_pool_size(ngx_conf_t
*cf
, void *post
, void *data
)
3817 if (*sp
< NGX_MIN_POOL_SIZE
) {
3818 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3819 "pool must be no less than %uz", NGX_MIN_POOL_SIZE
);
3821 return NGX_CONF_ERROR
;