3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Nginx, Inc.
8 #include <ngx_config.h>
16 } ngx_http_method_name_t
;
19 #define NGX_HTTP_REQUEST_BODY_FILE_OFF 0
20 #define NGX_HTTP_REQUEST_BODY_FILE_ON 1
21 #define NGX_HTTP_REQUEST_BODY_FILE_CLEAN 2
24 static ngx_int_t
ngx_http_core_find_location(ngx_http_request_t
*r
);
25 static ngx_int_t
ngx_http_core_find_static_location(ngx_http_request_t
*r
,
26 ngx_http_location_tree_node_t
*node
);
28 static ngx_int_t
ngx_http_core_preconfiguration(ngx_conf_t
*cf
);
29 static void *ngx_http_core_create_main_conf(ngx_conf_t
*cf
);
30 static char *ngx_http_core_init_main_conf(ngx_conf_t
*cf
, void *conf
);
31 static void *ngx_http_core_create_srv_conf(ngx_conf_t
*cf
);
32 static char *ngx_http_core_merge_srv_conf(ngx_conf_t
*cf
,
33 void *parent
, void *child
);
34 static void *ngx_http_core_create_loc_conf(ngx_conf_t
*cf
);
35 static char *ngx_http_core_merge_loc_conf(ngx_conf_t
*cf
,
36 void *parent
, void *child
);
38 static char *ngx_http_core_server(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
40 static char *ngx_http_core_location(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
42 static ngx_int_t
ngx_http_core_regex_location(ngx_conf_t
*cf
,
43 ngx_http_core_loc_conf_t
*clcf
, ngx_str_t
*regex
, ngx_uint_t caseless
);
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_try_files(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
63 static char *ngx_http_core_open_file_cache(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
65 static char *ngx_http_core_error_log(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
67 static char *ngx_http_core_keepalive(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
69 static char *ngx_http_core_internal(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
71 static char *ngx_http_core_resolver(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
74 static ngx_int_t
ngx_http_gzip_accept_encoding(ngx_str_t
*ae
);
75 static ngx_uint_t
ngx_http_gzip_quantity(u_char
*p
, u_char
*last
);
76 static char *ngx_http_gzip_disable(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
79 static ngx_int_t
ngx_http_get_forwarded_addr_internal(ngx_http_request_t
*r
,
80 ngx_addr_t
*addr
, u_char
*xff
, size_t xfflen
, ngx_array_t
*proxies
,
83 static char *ngx_http_disable_symlinks(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
87 static char *ngx_http_core_lowat_check(ngx_conf_t
*cf
, void *post
, void *data
);
88 static char *ngx_http_core_pool_size(ngx_conf_t
*cf
, void *post
, void *data
);
90 static ngx_conf_post_t ngx_http_core_lowat_post
=
91 { ngx_http_core_lowat_check
};
93 static ngx_conf_post_handler_pt ngx_http_core_pool_size_p
=
94 ngx_http_core_pool_size
;
96 static ngx_conf_deprecated_t ngx_conf_deprecated_optimize_server_names
= {
97 ngx_conf_deprecated
, "optimize_server_names", "server_name_in_redirect"
100 static ngx_conf_deprecated_t ngx_conf_deprecated_open_file_cache_retest
= {
101 ngx_conf_deprecated
, "open_file_cache_retest", "open_file_cache_valid"
104 static ngx_conf_deprecated_t ngx_conf_deprecated_satisfy_any
= {
105 ngx_conf_deprecated
, "satisfy_any", "satisfy"
109 static ngx_conf_enum_t ngx_http_core_request_body_in_file
[] = {
110 { ngx_string("off"), NGX_HTTP_REQUEST_BODY_FILE_OFF
},
111 { ngx_string("on"), NGX_HTTP_REQUEST_BODY_FILE_ON
},
112 { ngx_string("clean"), NGX_HTTP_REQUEST_BODY_FILE_CLEAN
},
113 { ngx_null_string
, 0 }
117 #if (NGX_HAVE_FILE_AIO)
119 static ngx_conf_enum_t ngx_http_core_aio
[] = {
120 { ngx_string("off"), NGX_HTTP_AIO_OFF
},
121 { ngx_string("on"), NGX_HTTP_AIO_ON
},
122 #if (NGX_HAVE_AIO_SENDFILE)
123 { ngx_string("sendfile"), NGX_HTTP_AIO_SENDFILE
},
125 { ngx_null_string
, 0 }
131 static ngx_conf_enum_t ngx_http_core_satisfy
[] = {
132 { ngx_string("all"), NGX_HTTP_SATISFY_ALL
},
133 { ngx_string("any"), NGX_HTTP_SATISFY_ANY
},
134 { ngx_null_string
, 0 }
138 static ngx_conf_enum_t ngx_http_core_lingering_close
[] = {
139 { ngx_string("off"), NGX_HTTP_LINGERING_OFF
},
140 { ngx_string("on"), NGX_HTTP_LINGERING_ON
},
141 { ngx_string("always"), NGX_HTTP_LINGERING_ALWAYS
},
142 { ngx_null_string
, 0 }
146 static ngx_conf_enum_t ngx_http_core_if_modified_since
[] = {
147 { ngx_string("off"), NGX_HTTP_IMS_OFF
},
148 { ngx_string("exact"), NGX_HTTP_IMS_EXACT
},
149 { ngx_string("before"), NGX_HTTP_IMS_BEFORE
},
150 { ngx_null_string
, 0 }
154 static ngx_conf_bitmask_t ngx_http_core_keepalive_disable
[] = {
155 { ngx_string("none"), NGX_HTTP_KEEPALIVE_DISABLE_NONE
},
156 { ngx_string("msie6"), NGX_HTTP_KEEPALIVE_DISABLE_MSIE6
},
157 { ngx_string("safari"), NGX_HTTP_KEEPALIVE_DISABLE_SAFARI
},
158 { ngx_null_string
, 0 }
162 static ngx_path_init_t ngx_http_client_temp_path
= {
163 ngx_string(NGX_HTTP_CLIENT_TEMP_PATH
), { 0, 0, 0 }
169 static ngx_conf_enum_t ngx_http_gzip_http_version
[] = {
170 { ngx_string("1.0"), NGX_HTTP_VERSION_10
},
171 { ngx_string("1.1"), NGX_HTTP_VERSION_11
},
172 { ngx_null_string
, 0 }
176 static ngx_conf_bitmask_t ngx_http_gzip_proxied_mask
[] = {
177 { ngx_string("off"), NGX_HTTP_GZIP_PROXIED_OFF
},
178 { ngx_string("expired"), NGX_HTTP_GZIP_PROXIED_EXPIRED
},
179 { ngx_string("no-cache"), NGX_HTTP_GZIP_PROXIED_NO_CACHE
},
180 { ngx_string("no-store"), NGX_HTTP_GZIP_PROXIED_NO_STORE
},
181 { ngx_string("private"), NGX_HTTP_GZIP_PROXIED_PRIVATE
},
182 { ngx_string("no_last_modified"), NGX_HTTP_GZIP_PROXIED_NO_LM
},
183 { ngx_string("no_etag"), NGX_HTTP_GZIP_PROXIED_NO_ETAG
},
184 { ngx_string("auth"), NGX_HTTP_GZIP_PROXIED_AUTH
},
185 { ngx_string("any"), NGX_HTTP_GZIP_PROXIED_ANY
},
186 { ngx_null_string
, 0 }
190 static ngx_str_t ngx_http_gzip_no_cache
= ngx_string("no-cache");
191 static ngx_str_t ngx_http_gzip_no_store
= ngx_string("no-store");
192 static ngx_str_t ngx_http_gzip_private
= ngx_string("private");
197 static ngx_command_t ngx_http_core_commands
[] = {
199 { ngx_string("variables_hash_max_size"),
200 NGX_HTTP_MAIN_CONF
|NGX_CONF_TAKE1
,
201 ngx_conf_set_num_slot
,
202 NGX_HTTP_MAIN_CONF_OFFSET
,
203 offsetof(ngx_http_core_main_conf_t
, variables_hash_max_size
),
206 { ngx_string("variables_hash_bucket_size"),
207 NGX_HTTP_MAIN_CONF
|NGX_CONF_TAKE1
,
208 ngx_conf_set_num_slot
,
209 NGX_HTTP_MAIN_CONF_OFFSET
,
210 offsetof(ngx_http_core_main_conf_t
, variables_hash_bucket_size
),
213 { ngx_string("server_names_hash_max_size"),
214 NGX_HTTP_MAIN_CONF
|NGX_CONF_TAKE1
,
215 ngx_conf_set_num_slot
,
216 NGX_HTTP_MAIN_CONF_OFFSET
,
217 offsetof(ngx_http_core_main_conf_t
, server_names_hash_max_size
),
220 { ngx_string("server_names_hash_bucket_size"),
221 NGX_HTTP_MAIN_CONF
|NGX_CONF_TAKE1
,
222 ngx_conf_set_num_slot
,
223 NGX_HTTP_MAIN_CONF_OFFSET
,
224 offsetof(ngx_http_core_main_conf_t
, server_names_hash_bucket_size
),
227 { ngx_string("server"),
228 NGX_HTTP_MAIN_CONF
|NGX_CONF_BLOCK
|NGX_CONF_NOARGS
,
229 ngx_http_core_server
,
234 { ngx_string("connection_pool_size"),
235 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_TAKE1
,
236 ngx_conf_set_size_slot
,
237 NGX_HTTP_SRV_CONF_OFFSET
,
238 offsetof(ngx_http_core_srv_conf_t
, connection_pool_size
),
239 &ngx_http_core_pool_size_p
},
241 { ngx_string("request_pool_size"),
242 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_TAKE1
,
243 ngx_conf_set_size_slot
,
244 NGX_HTTP_SRV_CONF_OFFSET
,
245 offsetof(ngx_http_core_srv_conf_t
, request_pool_size
),
246 &ngx_http_core_pool_size_p
},
248 { ngx_string("client_header_timeout"),
249 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_TAKE1
,
250 ngx_conf_set_msec_slot
,
251 NGX_HTTP_SRV_CONF_OFFSET
,
252 offsetof(ngx_http_core_srv_conf_t
, client_header_timeout
),
255 { ngx_string("client_header_buffer_size"),
256 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_TAKE1
,
257 ngx_conf_set_size_slot
,
258 NGX_HTTP_SRV_CONF_OFFSET
,
259 offsetof(ngx_http_core_srv_conf_t
, client_header_buffer_size
),
262 { ngx_string("large_client_header_buffers"),
263 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_TAKE2
,
264 ngx_conf_set_bufs_slot
,
265 NGX_HTTP_SRV_CONF_OFFSET
,
266 offsetof(ngx_http_core_srv_conf_t
, large_client_header_buffers
),
269 { ngx_string("optimize_server_names"),
270 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_FLAG
,
271 ngx_conf_set_flag_slot
,
272 NGX_HTTP_LOC_CONF_OFFSET
,
273 offsetof(ngx_http_core_loc_conf_t
, server_name_in_redirect
),
274 &ngx_conf_deprecated_optimize_server_names
},
276 { ngx_string("ignore_invalid_headers"),
277 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_FLAG
,
278 ngx_conf_set_flag_slot
,
279 NGX_HTTP_SRV_CONF_OFFSET
,
280 offsetof(ngx_http_core_srv_conf_t
, ignore_invalid_headers
),
283 { ngx_string("merge_slashes"),
284 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_FLAG
,
285 ngx_conf_set_flag_slot
,
286 NGX_HTTP_SRV_CONF_OFFSET
,
287 offsetof(ngx_http_core_srv_conf_t
, merge_slashes
),
290 { ngx_string("underscores_in_headers"),
291 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_CONF_FLAG
,
292 ngx_conf_set_flag_slot
,
293 NGX_HTTP_SRV_CONF_OFFSET
,
294 offsetof(ngx_http_core_srv_conf_t
, underscores_in_headers
),
297 { ngx_string("location"),
298 NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_BLOCK
|NGX_CONF_TAKE12
,
299 ngx_http_core_location
,
300 NGX_HTTP_SRV_CONF_OFFSET
,
304 { ngx_string("listen"),
305 NGX_HTTP_SRV_CONF
|NGX_CONF_1MORE
,
306 ngx_http_core_listen
,
307 NGX_HTTP_SRV_CONF_OFFSET
,
311 { ngx_string("server_name"),
312 NGX_HTTP_SRV_CONF
|NGX_CONF_1MORE
,
313 ngx_http_core_server_name
,
314 NGX_HTTP_SRV_CONF_OFFSET
,
318 { ngx_string("types_hash_max_size"),
319 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
320 ngx_conf_set_num_slot
,
321 NGX_HTTP_LOC_CONF_OFFSET
,
322 offsetof(ngx_http_core_loc_conf_t
, types_hash_max_size
),
325 { ngx_string("types_hash_bucket_size"),
326 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
327 ngx_conf_set_num_slot
,
328 NGX_HTTP_LOC_CONF_OFFSET
,
329 offsetof(ngx_http_core_loc_conf_t
, types_hash_bucket_size
),
332 { ngx_string("types"),
333 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
334 |NGX_CONF_BLOCK
|NGX_CONF_NOARGS
,
336 NGX_HTTP_LOC_CONF_OFFSET
,
340 { ngx_string("default_type"),
341 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
342 ngx_conf_set_str_slot
,
343 NGX_HTTP_LOC_CONF_OFFSET
,
344 offsetof(ngx_http_core_loc_conf_t
, default_type
),
347 { ngx_string("root"),
348 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_HTTP_LIF_CONF
351 NGX_HTTP_LOC_CONF_OFFSET
,
355 { ngx_string("alias"),
356 NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
358 NGX_HTTP_LOC_CONF_OFFSET
,
362 { ngx_string("limit_except"),
363 NGX_HTTP_LOC_CONF
|NGX_CONF_BLOCK
|NGX_CONF_1MORE
,
364 ngx_http_core_limit_except
,
365 NGX_HTTP_LOC_CONF_OFFSET
,
369 { ngx_string("client_max_body_size"),
370 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
371 ngx_conf_set_off_slot
,
372 NGX_HTTP_LOC_CONF_OFFSET
,
373 offsetof(ngx_http_core_loc_conf_t
, client_max_body_size
),
376 { ngx_string("client_body_buffer_size"),
377 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
378 ngx_conf_set_size_slot
,
379 NGX_HTTP_LOC_CONF_OFFSET
,
380 offsetof(ngx_http_core_loc_conf_t
, client_body_buffer_size
),
383 { ngx_string("client_body_timeout"),
384 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
385 ngx_conf_set_msec_slot
,
386 NGX_HTTP_LOC_CONF_OFFSET
,
387 offsetof(ngx_http_core_loc_conf_t
, client_body_timeout
),
390 { ngx_string("client_body_temp_path"),
391 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1234
,
392 ngx_conf_set_path_slot
,
393 NGX_HTTP_LOC_CONF_OFFSET
,
394 offsetof(ngx_http_core_loc_conf_t
, client_body_temp_path
),
397 { ngx_string("client_body_in_file_only"),
398 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
399 ngx_conf_set_enum_slot
,
400 NGX_HTTP_LOC_CONF_OFFSET
,
401 offsetof(ngx_http_core_loc_conf_t
, client_body_in_file_only
),
402 &ngx_http_core_request_body_in_file
},
404 { ngx_string("client_body_in_single_buffer"),
405 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
406 ngx_conf_set_flag_slot
,
407 NGX_HTTP_LOC_CONF_OFFSET
,
408 offsetof(ngx_http_core_loc_conf_t
, client_body_in_single_buffer
),
411 { ngx_string("sendfile"),
412 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_HTTP_LIF_CONF
414 ngx_conf_set_flag_slot
,
415 NGX_HTTP_LOC_CONF_OFFSET
,
416 offsetof(ngx_http_core_loc_conf_t
, sendfile
),
419 { ngx_string("sendfile_max_chunk"),
420 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
421 ngx_conf_set_size_slot
,
422 NGX_HTTP_LOC_CONF_OFFSET
,
423 offsetof(ngx_http_core_loc_conf_t
, sendfile_max_chunk
),
426 #if (NGX_HAVE_FILE_AIO)
429 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
430 ngx_conf_set_enum_slot
,
431 NGX_HTTP_LOC_CONF_OFFSET
,
432 offsetof(ngx_http_core_loc_conf_t
, aio
),
433 &ngx_http_core_aio
},
437 { ngx_string("read_ahead"),
438 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
439 ngx_conf_set_size_slot
,
440 NGX_HTTP_LOC_CONF_OFFSET
,
441 offsetof(ngx_http_core_loc_conf_t
, read_ahead
),
444 { ngx_string("directio"),
445 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
446 ngx_http_core_directio
,
447 NGX_HTTP_LOC_CONF_OFFSET
,
451 { ngx_string("directio_alignment"),
452 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
453 ngx_conf_set_off_slot
,
454 NGX_HTTP_LOC_CONF_OFFSET
,
455 offsetof(ngx_http_core_loc_conf_t
, directio_alignment
),
458 { ngx_string("tcp_nopush"),
459 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
460 ngx_conf_set_flag_slot
,
461 NGX_HTTP_LOC_CONF_OFFSET
,
462 offsetof(ngx_http_core_loc_conf_t
, tcp_nopush
),
465 { ngx_string("tcp_nodelay"),
466 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
467 ngx_conf_set_flag_slot
,
468 NGX_HTTP_LOC_CONF_OFFSET
,
469 offsetof(ngx_http_core_loc_conf_t
, tcp_nodelay
),
472 { ngx_string("send_timeout"),
473 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
474 ngx_conf_set_msec_slot
,
475 NGX_HTTP_LOC_CONF_OFFSET
,
476 offsetof(ngx_http_core_loc_conf_t
, send_timeout
),
479 { ngx_string("send_lowat"),
480 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
481 ngx_conf_set_size_slot
,
482 NGX_HTTP_LOC_CONF_OFFSET
,
483 offsetof(ngx_http_core_loc_conf_t
, send_lowat
),
484 &ngx_http_core_lowat_post
},
486 { ngx_string("postpone_output"),
487 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
488 ngx_conf_set_size_slot
,
489 NGX_HTTP_LOC_CONF_OFFSET
,
490 offsetof(ngx_http_core_loc_conf_t
, postpone_output
),
493 { ngx_string("limit_rate"),
494 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_HTTP_LIF_CONF
496 ngx_conf_set_size_slot
,
497 NGX_HTTP_LOC_CONF_OFFSET
,
498 offsetof(ngx_http_core_loc_conf_t
, limit_rate
),
501 { ngx_string("limit_rate_after"),
502 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_HTTP_LIF_CONF
504 ngx_conf_set_size_slot
,
505 NGX_HTTP_LOC_CONF_OFFSET
,
506 offsetof(ngx_http_core_loc_conf_t
, limit_rate_after
),
509 { ngx_string("keepalive_timeout"),
510 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE12
,
511 ngx_http_core_keepalive
,
512 NGX_HTTP_LOC_CONF_OFFSET
,
516 { ngx_string("keepalive_requests"),
517 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
518 ngx_conf_set_num_slot
,
519 NGX_HTTP_LOC_CONF_OFFSET
,
520 offsetof(ngx_http_core_loc_conf_t
, keepalive_requests
),
523 { ngx_string("keepalive_disable"),
524 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE12
,
525 ngx_conf_set_bitmask_slot
,
526 NGX_HTTP_LOC_CONF_OFFSET
,
527 offsetof(ngx_http_core_loc_conf_t
, keepalive_disable
),
528 &ngx_http_core_keepalive_disable
},
530 { ngx_string("satisfy"),
531 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
532 ngx_conf_set_enum_slot
,
533 NGX_HTTP_LOC_CONF_OFFSET
,
534 offsetof(ngx_http_core_loc_conf_t
, satisfy
),
535 &ngx_http_core_satisfy
},
537 { ngx_string("satisfy_any"),
538 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
539 ngx_conf_set_flag_slot
,
540 NGX_HTTP_LOC_CONF_OFFSET
,
541 offsetof(ngx_http_core_loc_conf_t
, satisfy
),
542 &ngx_conf_deprecated_satisfy_any
},
544 { ngx_string("internal"),
545 NGX_HTTP_LOC_CONF
|NGX_CONF_NOARGS
,
546 ngx_http_core_internal
,
547 NGX_HTTP_LOC_CONF_OFFSET
,
551 { ngx_string("lingering_close"),
552 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
553 ngx_conf_set_enum_slot
,
554 NGX_HTTP_LOC_CONF_OFFSET
,
555 offsetof(ngx_http_core_loc_conf_t
, lingering_close
),
556 &ngx_http_core_lingering_close
},
558 { ngx_string("lingering_time"),
559 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
560 ngx_conf_set_msec_slot
,
561 NGX_HTTP_LOC_CONF_OFFSET
,
562 offsetof(ngx_http_core_loc_conf_t
, lingering_time
),
565 { ngx_string("lingering_timeout"),
566 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
567 ngx_conf_set_msec_slot
,
568 NGX_HTTP_LOC_CONF_OFFSET
,
569 offsetof(ngx_http_core_loc_conf_t
, lingering_timeout
),
572 { ngx_string("reset_timedout_connection"),
573 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
574 ngx_conf_set_flag_slot
,
575 NGX_HTTP_LOC_CONF_OFFSET
,
576 offsetof(ngx_http_core_loc_conf_t
, reset_timedout_connection
),
579 { ngx_string("server_name_in_redirect"),
580 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
581 ngx_conf_set_flag_slot
,
582 NGX_HTTP_LOC_CONF_OFFSET
,
583 offsetof(ngx_http_core_loc_conf_t
, server_name_in_redirect
),
586 { ngx_string("port_in_redirect"),
587 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
588 ngx_conf_set_flag_slot
,
589 NGX_HTTP_LOC_CONF_OFFSET
,
590 offsetof(ngx_http_core_loc_conf_t
, port_in_redirect
),
593 { ngx_string("msie_padding"),
594 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
595 ngx_conf_set_flag_slot
,
596 NGX_HTTP_LOC_CONF_OFFSET
,
597 offsetof(ngx_http_core_loc_conf_t
, msie_padding
),
600 { ngx_string("msie_refresh"),
601 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
602 ngx_conf_set_flag_slot
,
603 NGX_HTTP_LOC_CONF_OFFSET
,
604 offsetof(ngx_http_core_loc_conf_t
, msie_refresh
),
607 { ngx_string("log_not_found"),
608 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
609 ngx_conf_set_flag_slot
,
610 NGX_HTTP_LOC_CONF_OFFSET
,
611 offsetof(ngx_http_core_loc_conf_t
, log_not_found
),
614 { ngx_string("log_subrequest"),
615 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
616 ngx_conf_set_flag_slot
,
617 NGX_HTTP_LOC_CONF_OFFSET
,
618 offsetof(ngx_http_core_loc_conf_t
, log_subrequest
),
621 { ngx_string("recursive_error_pages"),
622 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
623 ngx_conf_set_flag_slot
,
624 NGX_HTTP_LOC_CONF_OFFSET
,
625 offsetof(ngx_http_core_loc_conf_t
, recursive_error_pages
),
628 { ngx_string("server_tokens"),
629 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
630 ngx_conf_set_flag_slot
,
631 NGX_HTTP_LOC_CONF_OFFSET
,
632 offsetof(ngx_http_core_loc_conf_t
, server_tokens
),
635 { ngx_string("if_modified_since"),
636 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
637 ngx_conf_set_enum_slot
,
638 NGX_HTTP_LOC_CONF_OFFSET
,
639 offsetof(ngx_http_core_loc_conf_t
, if_modified_since
),
640 &ngx_http_core_if_modified_since
},
642 { ngx_string("max_ranges"),
643 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
644 ngx_conf_set_num_slot
,
645 NGX_HTTP_LOC_CONF_OFFSET
,
646 offsetof(ngx_http_core_loc_conf_t
, max_ranges
),
649 { ngx_string("chunked_transfer_encoding"),
650 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
651 ngx_conf_set_flag_slot
,
652 NGX_HTTP_LOC_CONF_OFFSET
,
653 offsetof(ngx_http_core_loc_conf_t
, chunked_transfer_encoding
),
656 { ngx_string("etag"),
657 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
658 ngx_conf_set_flag_slot
,
659 NGX_HTTP_LOC_CONF_OFFSET
,
660 offsetof(ngx_http_core_loc_conf_t
, etag
),
663 { ngx_string("error_page"),
664 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_HTTP_LIF_CONF
666 ngx_http_core_error_page
,
667 NGX_HTTP_LOC_CONF_OFFSET
,
671 { ngx_string("try_files"),
672 NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_2MORE
,
673 ngx_http_core_try_files
,
674 NGX_HTTP_LOC_CONF_OFFSET
,
678 { ngx_string("post_action"),
679 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_HTTP_LIF_CONF
681 ngx_conf_set_str_slot
,
682 NGX_HTTP_LOC_CONF_OFFSET
,
683 offsetof(ngx_http_core_loc_conf_t
, post_action
),
686 { ngx_string("error_log"),
687 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_1MORE
,
688 ngx_http_core_error_log
,
689 NGX_HTTP_LOC_CONF_OFFSET
,
693 { ngx_string("open_file_cache"),
694 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE12
,
695 ngx_http_core_open_file_cache
,
696 NGX_HTTP_LOC_CONF_OFFSET
,
697 offsetof(ngx_http_core_loc_conf_t
, open_file_cache
),
700 { ngx_string("open_file_cache_valid"),
701 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
702 ngx_conf_set_sec_slot
,
703 NGX_HTTP_LOC_CONF_OFFSET
,
704 offsetof(ngx_http_core_loc_conf_t
, open_file_cache_valid
),
707 { ngx_string("open_file_cache_retest"),
708 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
709 ngx_conf_set_sec_slot
,
710 NGX_HTTP_LOC_CONF_OFFSET
,
711 offsetof(ngx_http_core_loc_conf_t
, open_file_cache_valid
),
712 &ngx_conf_deprecated_open_file_cache_retest
},
714 { ngx_string("open_file_cache_min_uses"),
715 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
716 ngx_conf_set_num_slot
,
717 NGX_HTTP_LOC_CONF_OFFSET
,
718 offsetof(ngx_http_core_loc_conf_t
, open_file_cache_min_uses
),
721 { ngx_string("open_file_cache_errors"),
722 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
723 ngx_conf_set_flag_slot
,
724 NGX_HTTP_LOC_CONF_OFFSET
,
725 offsetof(ngx_http_core_loc_conf_t
, open_file_cache_errors
),
728 { ngx_string("open_file_cache_events"),
729 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
730 ngx_conf_set_flag_slot
,
731 NGX_HTTP_LOC_CONF_OFFSET
,
732 offsetof(ngx_http_core_loc_conf_t
, open_file_cache_events
),
735 { ngx_string("resolver"),
736 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_1MORE
,
737 ngx_http_core_resolver
,
738 NGX_HTTP_LOC_CONF_OFFSET
,
742 { ngx_string("resolver_timeout"),
743 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
744 ngx_conf_set_msec_slot
,
745 NGX_HTTP_LOC_CONF_OFFSET
,
746 offsetof(ngx_http_core_loc_conf_t
, resolver_timeout
),
751 { ngx_string("gzip_vary"),
752 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_FLAG
,
753 ngx_conf_set_flag_slot
,
754 NGX_HTTP_LOC_CONF_OFFSET
,
755 offsetof(ngx_http_core_loc_conf_t
, gzip_vary
),
758 { ngx_string("gzip_http_version"),
759 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE1
,
760 ngx_conf_set_enum_slot
,
761 NGX_HTTP_LOC_CONF_OFFSET
,
762 offsetof(ngx_http_core_loc_conf_t
, gzip_http_version
),
763 &ngx_http_gzip_http_version
},
765 { ngx_string("gzip_proxied"),
766 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_1MORE
,
767 ngx_conf_set_bitmask_slot
,
768 NGX_HTTP_LOC_CONF_OFFSET
,
769 offsetof(ngx_http_core_loc_conf_t
, gzip_proxied
),
770 &ngx_http_gzip_proxied_mask
},
772 { ngx_string("gzip_disable"),
773 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_1MORE
,
774 ngx_http_gzip_disable
,
775 NGX_HTTP_LOC_CONF_OFFSET
,
781 #if (NGX_HAVE_OPENAT)
783 { ngx_string("disable_symlinks"),
784 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE12
,
785 ngx_http_disable_symlinks
,
786 NGX_HTTP_LOC_CONF_OFFSET
,
796 static ngx_http_module_t ngx_http_core_module_ctx
= {
797 ngx_http_core_preconfiguration
, /* preconfiguration */
798 NULL
, /* postconfiguration */
800 ngx_http_core_create_main_conf
, /* create main configuration */
801 ngx_http_core_init_main_conf
, /* init main configuration */
803 ngx_http_core_create_srv_conf
, /* create server configuration */
804 ngx_http_core_merge_srv_conf
, /* merge server configuration */
806 ngx_http_core_create_loc_conf
, /* create location configuration */
807 ngx_http_core_merge_loc_conf
/* merge location configuration */
811 ngx_module_t ngx_http_core_module
= {
813 &ngx_http_core_module_ctx
, /* module context */
814 ngx_http_core_commands
, /* module directives */
815 NGX_HTTP_MODULE
, /* module type */
816 NULL
, /* init master */
817 NULL
, /* init module */
818 NULL
, /* init process */
819 NULL
, /* init thread */
820 NULL
, /* exit thread */
821 NULL
, /* exit process */
822 NULL
, /* exit master */
823 NGX_MODULE_V1_PADDING
827 ngx_str_t ngx_http_core_get_method
= { 3, (u_char
*) "GET " };
831 ngx_http_handler(ngx_http_request_t
*r
)
833 ngx_http_core_main_conf_t
*cmcf
;
835 r
->connection
->log
->action
= NULL
;
837 r
->connection
->unexpected_eof
= 0;
840 switch (r
->headers_in
.connection_type
) {
842 r
->keepalive
= (r
->http_version
> NGX_HTTP_VERSION_10
);
845 case NGX_HTTP_CONNECTION_CLOSE
:
849 case NGX_HTTP_CONNECTION_KEEP_ALIVE
:
854 r
->lingering_close
= (r
->headers_in
.content_length_n
> 0
855 || r
->headers_in
.chunked
);
856 r
->phase_handler
= 0;
859 cmcf
= ngx_http_get_module_main_conf(r
, ngx_http_core_module
);
860 r
->phase_handler
= cmcf
->phase_engine
.server_rewrite_index
;
863 r
->valid_location
= 1;
870 r
->write_event_handler
= ngx_http_core_run_phases
;
871 ngx_http_core_run_phases(r
);
876 ngx_http_core_run_phases(ngx_http_request_t
*r
)
879 ngx_http_phase_handler_t
*ph
;
880 ngx_http_core_main_conf_t
*cmcf
;
882 cmcf
= ngx_http_get_module_main_conf(r
, ngx_http_core_module
);
884 ph
= cmcf
->phase_engine
.handlers
;
886 while (ph
[r
->phase_handler
].checker
) {
888 rc
= ph
[r
->phase_handler
].checker(r
, &ph
[r
->phase_handler
]);
898 ngx_http_core_generic_phase(ngx_http_request_t
*r
, ngx_http_phase_handler_t
*ph
)
903 * generic phase checker,
904 * used by the post read and pre-access phases
907 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
908 "generic phase: %ui", r
->phase_handler
);
913 r
->phase_handler
= ph
->next
;
917 if (rc
== NGX_DECLINED
) {
922 if (rc
== NGX_AGAIN
|| rc
== NGX_DONE
) {
926 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
928 ngx_http_finalize_request(r
, rc
);
935 ngx_http_core_rewrite_phase(ngx_http_request_t
*r
, ngx_http_phase_handler_t
*ph
)
939 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
940 "rewrite phase: %ui", r
->phase_handler
);
944 if (rc
== NGX_DECLINED
) {
949 if (rc
== NGX_DONE
) {
953 /* NGX_OK, NGX_AGAIN, NGX_ERROR, NGX_HTTP_... */
955 ngx_http_finalize_request(r
, rc
);
962 ngx_http_core_find_config_phase(ngx_http_request_t
*r
,
963 ngx_http_phase_handler_t
*ph
)
968 ngx_http_core_loc_conf_t
*clcf
;
970 r
->content_handler
= NULL
;
973 rc
= ngx_http_core_find_location(r
);
975 if (rc
== NGX_ERROR
) {
976 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
980 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
982 if (!r
->internal
&& clcf
->internal
) {
983 ngx_http_finalize_request(r
, NGX_HTTP_NOT_FOUND
);
987 ngx_log_debug2(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
988 "using configuration \"%s%V\"",
989 (clcf
->noname
? "*" : (clcf
->exact_match
? "=" : "")),
992 ngx_http_update_location_config(r
);
994 ngx_log_debug2(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
996 r
->headers_in
.content_length_n
, clcf
->client_max_body_size
);
998 if (r
->headers_in
.content_length_n
!= -1
1000 && clcf
->client_max_body_size
1001 && clcf
->client_max_body_size
< r
->headers_in
.content_length_n
)
1003 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
1004 "client intended to send too large body: %O bytes",
1005 r
->headers_in
.content_length_n
);
1007 r
->expect_tested
= 1;
1008 (void) ngx_http_discard_request_body(r
);
1009 ngx_http_finalize_request(r
, NGX_HTTP_REQUEST_ENTITY_TOO_LARGE
);
1013 if (rc
== NGX_DONE
) {
1014 ngx_http_clear_location(r
);
1016 r
->headers_out
.location
= ngx_list_push(&r
->headers_out
.headers
);
1017 if (r
->headers_out
.location
== NULL
) {
1018 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
1023 * we do not need to set the r->headers_out.location->hash and
1024 * r->headers_out.location->key fields
1027 if (r
->args
.len
== 0) {
1028 r
->headers_out
.location
->value
= clcf
->name
;
1031 len
= clcf
->name
.len
+ 1 + r
->args
.len
;
1032 p
= ngx_pnalloc(r
->pool
, len
);
1035 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
1039 r
->headers_out
.location
->value
.len
= len
;
1040 r
->headers_out
.location
->value
.data
= p
;
1042 p
= ngx_cpymem(p
, clcf
->name
.data
, clcf
->name
.len
);
1044 ngx_memcpy(p
, r
->args
.data
, r
->args
.len
);
1047 ngx_http_finalize_request(r
, NGX_HTTP_MOVED_PERMANENTLY
);
1057 ngx_http_core_post_rewrite_phase(ngx_http_request_t
*r
,
1058 ngx_http_phase_handler_t
*ph
)
1060 ngx_http_core_srv_conf_t
*cscf
;
1062 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1063 "post rewrite phase: %ui", r
->phase_handler
);
1065 if (!r
->uri_changed
) {
1070 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1071 "uri changes: %d", r
->uri_changes
);
1074 * gcc before 3.3 compiles the broken code for
1075 * if (r->uri_changes-- == 0)
1076 * if the r->uri_changes is defined as
1077 * unsigned uri_changes:4
1082 if (r
->uri_changes
== 0) {
1083 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
1084 "rewrite or internal redirection cycle "
1085 "while processing \"%V\"", &r
->uri
);
1087 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
1091 r
->phase_handler
= ph
->next
;
1093 cscf
= ngx_http_get_module_srv_conf(r
, ngx_http_core_module
);
1094 r
->loc_conf
= cscf
->ctx
->loc_conf
;
1101 ngx_http_core_access_phase(ngx_http_request_t
*r
, ngx_http_phase_handler_t
*ph
)
1104 ngx_http_core_loc_conf_t
*clcf
;
1107 r
->phase_handler
= ph
->next
;
1111 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1112 "access phase: %ui", r
->phase_handler
);
1114 rc
= ph
->handler(r
);
1116 if (rc
== NGX_DECLINED
) {
1121 if (rc
== NGX_AGAIN
|| rc
== NGX_DONE
) {
1125 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1127 if (clcf
->satisfy
== NGX_HTTP_SATISFY_ALL
) {
1138 if (r
->headers_out
.www_authenticate
) {
1139 r
->headers_out
.www_authenticate
->hash
= 0;
1142 r
->phase_handler
= ph
->next
;
1146 if (rc
== NGX_HTTP_FORBIDDEN
|| rc
== NGX_HTTP_UNAUTHORIZED
) {
1147 r
->access_code
= rc
;
1154 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
1156 ngx_http_finalize_request(r
, rc
);
1162 ngx_http_core_post_access_phase(ngx_http_request_t
*r
,
1163 ngx_http_phase_handler_t
*ph
)
1165 ngx_int_t access_code
;
1167 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1168 "post access phase: %ui", r
->phase_handler
);
1170 access_code
= r
->access_code
;
1173 if (access_code
== NGX_HTTP_FORBIDDEN
) {
1174 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
1175 "access forbidden by rule");
1179 ngx_http_finalize_request(r
, access_code
);
1189 ngx_http_core_try_files_phase(ngx_http_request_t
*r
,
1190 ngx_http_phase_handler_t
*ph
)
1192 size_t len
, root
, alias
, reserve
, allocated
;
1194 ngx_str_t path
, args
;
1195 ngx_uint_t test_dir
;
1196 ngx_http_try_file_t
*tf
;
1197 ngx_open_file_info_t of
;
1198 ngx_http_script_code_pt code
;
1199 ngx_http_script_engine_t e
;
1200 ngx_http_core_loc_conf_t
*clcf
;
1201 ngx_http_script_len_code_pt lcode
;
1203 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1204 "try files phase: %ui", r
->phase_handler
);
1206 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1208 if (clcf
->try_files
== NULL
) {
1216 /* suppress MSVC warning */
1219 tf
= clcf
->try_files
;
1221 alias
= clcf
->alias
;
1226 ngx_memzero(&e
, sizeof(ngx_http_script_engine_t
));
1228 e
.ip
= tf
->lengths
->elts
;
1231 /* 1 is for terminating '\0' as in static names */
1234 while (*(uintptr_t *) e
.ip
) {
1235 lcode
= *(ngx_http_script_len_code_pt
*) e
.ip
;
1244 reserve
= len
> r
->uri
.len
? len
- r
->uri
.len
: 0;
1247 } else if (clcf
->regex
) {
1252 reserve
= len
> r
->uri
.len
- alias
? len
- (r
->uri
.len
- alias
) : 0;
1255 if (reserve
> allocated
|| !allocated
) {
1257 /* 16 bytes are preallocation */
1258 allocated
= reserve
+ 16;
1260 if (ngx_http_map_uri_to_path(r
, &path
, &root
, allocated
) == NULL
) {
1261 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
1265 name
= path
.data
+ root
;
1268 if (tf
->values
== NULL
) {
1270 /* tf->name.len includes the terminating '\0' */
1272 ngx_memcpy(name
, tf
->name
.data
, tf
->name
.len
);
1274 path
.len
= (name
+ tf
->name
.len
- 1) - path
.data
;
1277 e
.ip
= tf
->values
->elts
;
1281 while (*(uintptr_t *) e
.ip
) {
1282 code
= *(ngx_http_script_code_pt
*) e
.ip
;
1283 code((ngx_http_script_engine_t
*) &e
);
1286 path
.len
= e
.pos
- path
.data
;
1290 if (alias
&& ngx_strncmp(name
, clcf
->name
.data
, alias
) == 0) {
1291 ngx_memmove(name
, name
+ alias
, len
- alias
);
1296 test_dir
= tf
->test_dir
;
1300 ngx_log_debug3(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1301 "trying to use %s: \"%s\" \"%s\"",
1302 test_dir
? "dir" : "file", name
, path
.data
);
1304 if (tf
->lengths
== NULL
&& tf
->name
.len
== 0) {
1307 ngx_http_finalize_request(r
, tf
->code
);
1314 if (path
.data
[0] == '@') {
1315 (void) ngx_http_named_location(r
, &path
);
1318 ngx_http_split_args(r
, &path
, &args
);
1320 (void) ngx_http_internal_redirect(r
, &path
, &args
);
1323 ngx_http_finalize_request(r
, NGX_DONE
);
1327 ngx_memzero(&of
, sizeof(ngx_open_file_info_t
));
1329 of
.read_ahead
= clcf
->read_ahead
;
1330 of
.directio
= clcf
->directio
;
1331 of
.valid
= clcf
->open_file_cache_valid
;
1332 of
.min_uses
= clcf
->open_file_cache_min_uses
;
1334 of
.errors
= clcf
->open_file_cache_errors
;
1335 of
.events
= clcf
->open_file_cache_events
;
1337 if (ngx_http_set_disable_symlinks(r
, clcf
, &path
, &of
) != NGX_OK
) {
1338 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
1342 if (ngx_open_cached_file(clcf
->open_file_cache
, &path
, &of
, r
->pool
)
1345 if (of
.err
!= NGX_ENOENT
1346 && of
.err
!= NGX_ENOTDIR
1347 && of
.err
!= NGX_ENAMETOOLONG
)
1349 ngx_log_error(NGX_LOG_CRIT
, r
->connection
->log
, of
.err
,
1350 "%s \"%s\" failed", of
.failed
, path
.data
);
1356 if (of
.is_dir
&& !test_dir
) {
1367 } else if (clcf
->regex
) {
1370 r
->add_uri_to_alias
= 1;
1374 r
->uri
.len
= alias
+ path
.len
;
1375 r
->uri
.data
= ngx_pnalloc(r
->pool
, r
->uri
.len
);
1376 if (r
->uri
.data
== NULL
) {
1377 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
1381 p
= ngx_copy(r
->uri
.data
, clcf
->name
.data
, alias
);
1382 ngx_memcpy(p
, name
, path
.len
);
1385 ngx_http_set_exten(r
);
1387 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1388 "try file uri: \"%V\"", &r
->uri
);
1399 ngx_http_core_content_phase(ngx_http_request_t
*r
,
1400 ngx_http_phase_handler_t
*ph
)
1406 if (r
->content_handler
) {
1407 r
->write_event_handler
= ngx_http_request_empty_handler
;
1408 ngx_http_finalize_request(r
, r
->content_handler(r
));
1412 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1413 "content phase: %ui", r
->phase_handler
);
1415 rc
= ph
->handler(r
);
1417 if (rc
!= NGX_DECLINED
) {
1418 ngx_http_finalize_request(r
, rc
);
1422 /* rc == NGX_DECLINED */
1431 /* no content handler was found */
1433 if (r
->uri
.data
[r
->uri
.len
- 1] == '/') {
1435 if (ngx_http_map_uri_to_path(r
, &path
, &root
, 0) != NULL
) {
1436 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
1437 "directory index of \"%s\" is forbidden", path
.data
);
1440 ngx_http_finalize_request(r
, NGX_HTTP_FORBIDDEN
);
1444 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0, "no handler found");
1446 ngx_http_finalize_request(r
, NGX_HTTP_NOT_FOUND
);
1452 ngx_http_update_location_config(ngx_http_request_t
*r
)
1454 ngx_http_core_loc_conf_t
*clcf
;
1456 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1458 if (r
->method
& clcf
->limit_except
) {
1459 r
->loc_conf
= clcf
->limit_except_loc_conf
;
1460 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1464 ngx_http_set_connection_log(r
->connection
, clcf
->error_log
);
1467 if ((ngx_io
.flags
& NGX_IO_SENDFILE
) && clcf
->sendfile
) {
1468 r
->connection
->sendfile
= 1;
1471 r
->connection
->sendfile
= 0;
1474 if (clcf
->client_body_in_file_only
) {
1475 r
->request_body_in_file_only
= 1;
1476 r
->request_body_in_persistent_file
= 1;
1477 r
->request_body_in_clean_file
=
1478 clcf
->client_body_in_file_only
== NGX_HTTP_REQUEST_BODY_FILE_CLEAN
;
1479 r
->request_body_file_log_level
= NGX_LOG_NOTICE
;
1482 r
->request_body_file_log_level
= NGX_LOG_WARN
;
1485 r
->request_body_in_single_buf
= clcf
->client_body_in_single_buffer
;
1488 if (clcf
->keepalive_timeout
== 0) {
1491 } else if (r
->connection
->requests
>= clcf
->keepalive_requests
) {
1494 } else if (r
->headers_in
.msie6
1495 && r
->method
== NGX_HTTP_POST
1496 && (clcf
->keepalive_disable
1497 & NGX_HTTP_KEEPALIVE_DISABLE_MSIE6
))
1500 * MSIE may wait for some time if an response for
1501 * a POST request was sent over a keepalive connection
1505 } else if (r
->headers_in
.safari
1506 && (clcf
->keepalive_disable
1507 & NGX_HTTP_KEEPALIVE_DISABLE_SAFARI
))
1510 * Safari may send a POST request to a closed keepalive
1511 * connection and may stall for some time, see
1512 * https://bugs.webkit.org/show_bug.cgi?id=5760
1518 if (!clcf
->tcp_nopush
) {
1519 /* disable TCP_NOPUSH/TCP_CORK use */
1520 r
->connection
->tcp_nopush
= NGX_TCP_NOPUSH_DISABLED
;
1523 if (r
->limit_rate
== 0) {
1524 r
->limit_rate
= clcf
->limit_rate
;
1527 if (clcf
->handler
) {
1528 r
->content_handler
= clcf
->handler
;
1534 * NGX_OK - exact or regex match
1535 * NGX_DONE - auto redirect
1536 * NGX_AGAIN - inclusive match
1537 * NGX_ERROR - regex error
1538 * NGX_DECLINED - no match
1542 ngx_http_core_find_location(ngx_http_request_t
*r
)
1545 ngx_http_core_loc_conf_t
*pclcf
;
1549 ngx_http_core_loc_conf_t
*clcf
, **clcfp
;
1554 pclcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1556 rc
= ngx_http_core_find_static_location(r
, pclcf
->static_locations
);
1558 if (rc
== NGX_AGAIN
) {
1561 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1563 noregex
= clcf
->noregex
;
1566 /* look up nested locations */
1568 rc
= ngx_http_core_find_location(r
);
1571 if (rc
== NGX_OK
|| rc
== NGX_DONE
) {
1575 /* rc == NGX_DECLINED or rc == NGX_AGAIN in nested location */
1579 if (noregex
== 0 && pclcf
->regex_locations
) {
1581 for (clcfp
= pclcf
->regex_locations
; *clcfp
; clcfp
++) {
1583 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1584 "test location: ~ \"%V\"", &(*clcfp
)->name
);
1586 n
= ngx_http_regex_exec(r
, (*clcfp
)->regex
, &r
->uri
);
1589 r
->loc_conf
= (*clcfp
)->loc_conf
;
1591 /* look up nested locations */
1593 rc
= ngx_http_core_find_location(r
);
1595 return (rc
== NGX_ERROR
) ? rc
: NGX_OK
;
1598 if (n
== NGX_DECLINED
) {
1612 * NGX_OK - exact match
1613 * NGX_DONE - auto redirect
1614 * NGX_AGAIN - inclusive match
1615 * NGX_DECLINED - no match
1619 ngx_http_core_find_static_location(ngx_http_request_t
*r
,
1620 ngx_http_location_tree_node_t
*node
)
1637 ngx_log_debug2(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
1638 "test location: \"%*s\"", node
->len
, node
->name
);
1640 n
= (len
<= (size_t) node
->len
) ? len
: node
->len
;
1642 rc
= ngx_filename_cmp(uri
, node
->name
, n
);
1645 node
= (rc
< 0) ? node
->left
: node
->right
;
1650 if (len
> (size_t) node
->len
) {
1652 if (node
->inclusive
) {
1654 r
->loc_conf
= node
->inclusive
->loc_conf
;
1671 if (len
== (size_t) node
->len
) {
1674 r
->loc_conf
= node
->exact
->loc_conf
;
1678 r
->loc_conf
= node
->inclusive
->loc_conf
;
1683 /* len < node->len */
1685 if (len
+ 1 == (size_t) node
->len
&& node
->auto_redirect
) {
1687 r
->loc_conf
= (node
->exact
) ? node
->exact
->loc_conf
:
1688 node
->inclusive
->loc_conf
;
1698 ngx_http_test_content_type(ngx_http_request_t
*r
, ngx_hash_t
*types_hash
)
1704 if (types_hash
->size
== 0) {
1708 if (r
->headers_out
.content_type
.len
== 0) {
1712 len
= r
->headers_out
.content_type_len
;
1714 if (r
->headers_out
.content_type_lowcase
== NULL
) {
1716 lowcase
= ngx_pnalloc(r
->pool
, len
);
1717 if (lowcase
== NULL
) {
1721 r
->headers_out
.content_type_lowcase
= lowcase
;
1725 for (i
= 0; i
< len
; i
++) {
1726 c
= ngx_tolower(r
->headers_out
.content_type
.data
[i
]);
1727 hash
= ngx_hash(hash
, c
);
1731 r
->headers_out
.content_type_hash
= hash
;
1734 return ngx_hash_find(types_hash
, r
->headers_out
.content_type_hash
,
1735 r
->headers_out
.content_type_lowcase
, len
);
1740 ngx_http_set_content_type(ngx_http_request_t
*r
)
1745 ngx_http_core_loc_conf_t
*clcf
;
1747 if (r
->headers_out
.content_type
.len
) {
1751 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1757 for (i
= 0; i
< r
->exten
.len
; i
++) {
1758 c
= r
->exten
.data
[i
];
1760 if (c
>= 'A' && c
<= 'Z') {
1762 exten
= ngx_pnalloc(r
->pool
, r
->exten
.len
);
1763 if (exten
== NULL
) {
1767 hash
= ngx_hash_strlow(exten
, r
->exten
.data
, r
->exten
.len
);
1769 r
->exten
.data
= exten
;
1774 hash
= ngx_hash(hash
, c
);
1777 type
= ngx_hash_find(&clcf
->types_hash
, hash
,
1778 r
->exten
.data
, r
->exten
.len
);
1781 r
->headers_out
.content_type_len
= type
->len
;
1782 r
->headers_out
.content_type
= *type
;
1788 r
->headers_out
.content_type_len
= clcf
->default_type
.len
;
1789 r
->headers_out
.content_type
= clcf
->default_type
;
1796 ngx_http_set_exten(ngx_http_request_t
*r
)
1800 ngx_str_null(&r
->exten
);
1802 for (i
= r
->uri
.len
- 1; i
> 1; i
--) {
1803 if (r
->uri
.data
[i
] == '.' && r
->uri
.data
[i
- 1] != '/') {
1805 r
->exten
.len
= r
->uri
.len
- i
- 1;
1806 r
->exten
.data
= &r
->uri
.data
[i
+ 1];
1810 } else if (r
->uri
.data
[i
] == '/') {
1820 ngx_http_set_etag(ngx_http_request_t
*r
)
1822 ngx_table_elt_t
*etag
;
1823 ngx_http_core_loc_conf_t
*clcf
;
1825 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1831 etag
= ngx_list_push(&r
->headers_out
.headers
);
1837 ngx_str_set(&etag
->key
, "ETag");
1839 etag
->value
.data
= ngx_pnalloc(r
->pool
, NGX_OFF_T_LEN
+ NGX_TIME_T_LEN
+ 3);
1840 if (etag
->value
.data
== NULL
) {
1844 etag
->value
.len
= ngx_sprintf(etag
->value
.data
, "\"%xT-%xO\"",
1845 r
->headers_out
.last_modified_time
,
1846 r
->headers_out
.content_length_n
)
1849 r
->headers_out
.etag
= etag
;
1856 ngx_http_send_response(ngx_http_request_t
*r
, ngx_uint_t status
,
1857 ngx_str_t
*ct
, ngx_http_complex_value_t
*cv
)
1864 if (ngx_http_discard_request_body(r
) != NGX_OK
) {
1865 return NGX_HTTP_INTERNAL_SERVER_ERROR
;
1868 r
->headers_out
.status
= status
;
1870 if (ngx_http_complex_value(r
, cv
, &val
) != NGX_OK
) {
1871 return NGX_HTTP_INTERNAL_SERVER_ERROR
;
1874 if (status
== NGX_HTTP_MOVED_PERMANENTLY
1875 || status
== NGX_HTTP_MOVED_TEMPORARILY
1876 || status
== NGX_HTTP_SEE_OTHER
1877 || status
== NGX_HTTP_TEMPORARY_REDIRECT
)
1879 ngx_http_clear_location(r
);
1881 r
->headers_out
.location
= ngx_list_push(&r
->headers_out
.headers
);
1882 if (r
->headers_out
.location
== NULL
) {
1883 return NGX_HTTP_INTERNAL_SERVER_ERROR
;
1886 r
->headers_out
.location
->hash
= 1;
1887 ngx_str_set(&r
->headers_out
.location
->key
, "Location");
1888 r
->headers_out
.location
->value
= val
;
1893 r
->headers_out
.content_length_n
= val
.len
;
1896 r
->headers_out
.content_type_len
= ct
->len
;
1897 r
->headers_out
.content_type
= *ct
;
1900 if (ngx_http_set_content_type(r
) != NGX_OK
) {
1901 return NGX_HTTP_INTERNAL_SERVER_ERROR
;
1905 if (r
->method
== NGX_HTTP_HEAD
|| (r
!= r
->main
&& val
.len
== 0)) {
1906 return ngx_http_send_header(r
);
1909 b
= ngx_pcalloc(r
->pool
, sizeof(ngx_buf_t
));
1911 return NGX_HTTP_INTERNAL_SERVER_ERROR
;
1915 b
->last
= val
.data
+ val
.len
;
1916 b
->memory
= val
.len
? 1 : 0;
1917 b
->last_buf
= (r
== r
->main
) ? 1 : 0;
1918 b
->last_in_chain
= 1;
1923 rc
= ngx_http_send_header(r
);
1925 if (rc
== NGX_ERROR
|| rc
> NGX_OK
|| r
->header_only
) {
1929 return ngx_http_output_filter(r
, &out
);
1934 ngx_http_send_header(ngx_http_request_t
*r
)
1936 if (r
->err_status
) {
1937 r
->headers_out
.status
= r
->err_status
;
1938 r
->headers_out
.status_line
.len
= 0;
1941 return ngx_http_top_header_filter(r
);
1946 ngx_http_output_filter(ngx_http_request_t
*r
, ngx_chain_t
*in
)
1949 ngx_connection_t
*c
;
1953 ngx_log_debug2(NGX_LOG_DEBUG_HTTP
, c
->log
, 0,
1954 "http output filter \"%V?%V\"", &r
->uri
, &r
->args
);
1956 rc
= ngx_http_top_body_filter(r
, in
);
1958 if (rc
== NGX_ERROR
) {
1959 /* NGX_ERROR may be returned by any filter */
1968 ngx_http_map_uri_to_path(ngx_http_request_t
*r
, ngx_str_t
*path
,
1969 size_t *root_length
, size_t reserved
)
1973 ngx_http_core_loc_conf_t
*clcf
;
1975 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
1977 alias
= clcf
->alias
;
1979 if (alias
&& !r
->valid_location
) {
1980 ngx_log_error(NGX_LOG_ALERT
, r
->connection
->log
, 0,
1981 "\"alias\" cannot be used in location \"%V\" "
1982 "where URI was rewritten", &clcf
->name
);
1986 if (clcf
->root_lengths
== NULL
) {
1988 *root_length
= clcf
->root
.len
;
1990 path
->len
= clcf
->root
.len
+ reserved
+ r
->uri
.len
- alias
+ 1;
1992 path
->data
= ngx_pnalloc(r
->pool
, path
->len
);
1993 if (path
->data
== NULL
) {
1997 last
= ngx_copy(path
->data
, clcf
->root
.data
, clcf
->root
.len
);
2002 ngx_uint_t captures
;
2004 captures
= alias
&& clcf
->regex
;
2006 reserved
+= captures
? r
->add_uri_to_alias
? r
->uri
.len
+ 1 : 1
2007 : r
->uri
.len
- alias
+ 1;
2009 reserved
+= r
->uri
.len
- alias
+ 1;
2012 if (ngx_http_script_run(r
, path
, clcf
->root_lengths
->elts
, reserved
,
2013 clcf
->root_values
->elts
)
2019 if (ngx_conf_full_name((ngx_cycle_t
*) ngx_cycle
, path
, 0) != NGX_OK
) {
2023 *root_length
= path
->len
- reserved
;
2024 last
= path
->data
+ *root_length
;
2028 if (!r
->add_uri_to_alias
) {
2038 last
= ngx_cpystrn(last
, r
->uri
.data
+ alias
, r
->uri
.len
- alias
+ 1);
2045 ngx_http_auth_basic_user(ngx_http_request_t
*r
)
2047 ngx_str_t auth
, encoded
;
2050 if (r
->headers_in
.user
.len
== 0 && r
->headers_in
.user
.data
!= NULL
) {
2051 return NGX_DECLINED
;
2054 if (r
->headers_in
.authorization
== NULL
) {
2055 r
->headers_in
.user
.data
= (u_char
*) "";
2056 return NGX_DECLINED
;
2059 encoded
= r
->headers_in
.authorization
->value
;
2061 if (encoded
.len
< sizeof("Basic ") - 1
2062 || ngx_strncasecmp(encoded
.data
, (u_char
*) "Basic ",
2063 sizeof("Basic ") - 1)
2066 r
->headers_in
.user
.data
= (u_char
*) "";
2067 return NGX_DECLINED
;
2070 encoded
.len
-= sizeof("Basic ") - 1;
2071 encoded
.data
+= sizeof("Basic ") - 1;
2073 while (encoded
.len
&& encoded
.data
[0] == ' ') {
2078 if (encoded
.len
== 0) {
2079 r
->headers_in
.user
.data
= (u_char
*) "";
2080 return NGX_DECLINED
;
2083 auth
.len
= ngx_base64_decoded_length(encoded
.len
);
2084 auth
.data
= ngx_pnalloc(r
->pool
, auth
.len
+ 1);
2085 if (auth
.data
== NULL
) {
2089 if (ngx_decode_base64(&auth
, &encoded
) != NGX_OK
) {
2090 r
->headers_in
.user
.data
= (u_char
*) "";
2091 return NGX_DECLINED
;
2094 auth
.data
[auth
.len
] = '\0';
2096 for (len
= 0; len
< auth
.len
; len
++) {
2097 if (auth
.data
[len
] == ':') {
2102 if (len
== 0 || len
== auth
.len
) {
2103 r
->headers_in
.user
.data
= (u_char
*) "";
2104 return NGX_DECLINED
;
2107 r
->headers_in
.user
.len
= len
;
2108 r
->headers_in
.user
.data
= auth
.data
;
2109 r
->headers_in
.passwd
.len
= auth
.len
- len
- 1;
2110 r
->headers_in
.passwd
.data
= &auth
.data
[len
+ 1];
2119 ngx_http_gzip_ok(ngx_http_request_t
*r
)
2121 time_t date
, expires
;
2124 ngx_table_elt_t
*e
, *d
, *ae
;
2125 ngx_http_core_loc_conf_t
*clcf
;
2130 return NGX_DECLINED
;
2134 if (r
->spdy_stream
) {
2140 ae
= r
->headers_in
.accept_encoding
;
2142 return NGX_DECLINED
;
2145 if (ae
->value
.len
< sizeof("gzip") - 1) {
2146 return NGX_DECLINED
;
2150 * test first for the most common case "gzip,...":
2151 * MSIE: "gzip, deflate"
2152 * Firefox: "gzip,deflate"
2153 * Chrome: "gzip,deflate,sdch"
2154 * Safari: "gzip, deflate"
2155 * Opera: "gzip, deflate"
2158 if (ngx_memcmp(ae
->value
.data
, "gzip,", 5) != 0
2159 && ngx_http_gzip_accept_encoding(&ae
->value
) != NGX_OK
)
2161 return NGX_DECLINED
;
2164 clcf
= ngx_http_get_module_loc_conf(r
, ngx_http_core_module
);
2166 if (r
->headers_in
.msie6
&& clcf
->gzip_disable_msie6
) {
2167 return NGX_DECLINED
;
2170 if (r
->http_version
< clcf
->gzip_http_version
) {
2171 return NGX_DECLINED
;
2174 if (r
->headers_in
.via
== NULL
) {
2178 p
= clcf
->gzip_proxied
;
2180 if (p
& NGX_HTTP_GZIP_PROXIED_OFF
) {
2181 return NGX_DECLINED
;
2184 if (p
& NGX_HTTP_GZIP_PROXIED_ANY
) {
2188 if (r
->headers_in
.authorization
&& (p
& NGX_HTTP_GZIP_PROXIED_AUTH
)) {
2192 e
= r
->headers_out
.expires
;
2196 if (!(p
& NGX_HTTP_GZIP_PROXIED_EXPIRED
)) {
2197 return NGX_DECLINED
;
2200 expires
= ngx_http_parse_time(e
->value
.data
, e
->value
.len
);
2201 if (expires
== NGX_ERROR
) {
2202 return NGX_DECLINED
;
2205 d
= r
->headers_out
.date
;
2208 date
= ngx_http_parse_time(d
->value
.data
, d
->value
.len
);
2209 if (date
== NGX_ERROR
) {
2210 return NGX_DECLINED
;
2217 if (expires
< date
) {
2221 return NGX_DECLINED
;
2224 cc
= &r
->headers_out
.cache_control
;
2228 if ((p
& NGX_HTTP_GZIP_PROXIED_NO_CACHE
)
2229 && ngx_http_parse_multi_header_lines(cc
, &ngx_http_gzip_no_cache
,
2236 if ((p
& NGX_HTTP_GZIP_PROXIED_NO_STORE
)
2237 && ngx_http_parse_multi_header_lines(cc
, &ngx_http_gzip_no_store
,
2244 if ((p
& NGX_HTTP_GZIP_PROXIED_PRIVATE
)
2245 && ngx_http_parse_multi_header_lines(cc
, &ngx_http_gzip_private
,
2252 return NGX_DECLINED
;
2255 if ((p
& NGX_HTTP_GZIP_PROXIED_NO_LM
) && r
->headers_out
.last_modified
) {
2256 return NGX_DECLINED
;
2259 if ((p
& NGX_HTTP_GZIP_PROXIED_NO_ETAG
) && r
->headers_out
.etag
) {
2260 return NGX_DECLINED
;
2267 if (clcf
->gzip_disable
&& r
->headers_in
.user_agent
) {
2269 if (ngx_regex_exec_array(clcf
->gzip_disable
,
2270 &r
->headers_in
.user_agent
->value
,
2274 return NGX_DECLINED
;
2287 * gzip is enabled for the following quantities:
2288 * "gzip; q=0.001" ... "gzip; q=1.000"
2289 * gzip is disabled for the following quantities:
2290 * "gzip; q=0" ... "gzip; q=0.000", and for any invalid cases
2294 ngx_http_gzip_accept_encoding(ngx_str_t
*ae
)
2296 u_char
*p
, *start
, *last
;
2299 last
= start
+ ae
->len
;
2302 p
= ngx_strcasestrn(start
, "gzip", 4 - 1);
2304 return NGX_DECLINED
;
2307 if (p
== start
|| (*(p
- 1) == ',' || *(p
- 1) == ' ')) {
2325 return NGX_DECLINED
;
2341 return NGX_DECLINED
;
2349 if (p
+ 2 > last
|| *p
++ != '=') {
2350 return NGX_DECLINED
;
2353 if (ngx_http_gzip_quantity(p
, last
) == 0) {
2354 return NGX_DECLINED
;
2362 ngx_http_gzip_quantity(u_char
*p
, u_char
*last
)
2369 if (c
!= '0' && c
!= '1') {
2373 q
= (c
- '0') * 100;
2381 if (c
== ',' || c
== ' ') {
2394 if (c
== ',' || c
== ' ') {
2398 if (c
>= '0' && c
<= '9') {
2407 if (q
> 100 || n
> 3) {
2418 ngx_http_subrequest(ngx_http_request_t
*r
,
2419 ngx_str_t
*uri
, ngx_str_t
*args
, ngx_http_request_t
**psr
,
2420 ngx_http_post_subrequest_t
*ps
, ngx_uint_t flags
)
2423 ngx_connection_t
*c
;
2424 ngx_http_request_t
*sr
;
2425 ngx_http_core_srv_conf_t
*cscf
;
2426 ngx_http_postponed_request_t
*pr
, *p
;
2428 r
->main
->subrequests
--;
2430 if (r
->main
->subrequests
== 0) {
2431 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
2432 "subrequests cycle while processing \"%V\"", uri
);
2433 r
->main
->subrequests
= 1;
2437 sr
= ngx_pcalloc(r
->pool
, sizeof(ngx_http_request_t
));
2442 sr
->signature
= NGX_HTTP_MODULE
;
2447 sr
->ctx
= ngx_pcalloc(r
->pool
, sizeof(void *) * ngx_http_max_module
);
2448 if (sr
->ctx
== NULL
) {
2452 if (ngx_list_init(&sr
->headers_out
.headers
, r
->pool
, 20,
2453 sizeof(ngx_table_elt_t
))
2459 cscf
= ngx_http_get_module_srv_conf(r
, ngx_http_core_module
);
2460 sr
->main_conf
= cscf
->ctx
->main_conf
;
2461 sr
->srv_conf
= cscf
->ctx
->srv_conf
;
2462 sr
->loc_conf
= cscf
->ctx
->loc_conf
;
2466 sr
->headers_in
= r
->headers_in
;
2468 ngx_http_clear_content_length(sr
);
2469 ngx_http_clear_accept_ranges(sr
);
2470 ngx_http_clear_last_modified(sr
);
2472 sr
->request_body
= r
->request_body
;
2475 sr
->spdy_stream
= r
->spdy_stream
;
2478 sr
->method
= NGX_HTTP_GET
;
2479 sr
->http_version
= r
->http_version
;
2481 sr
->request_line
= r
->request_line
;
2488 ngx_log_debug2(NGX_LOG_DEBUG_HTTP
, c
->log
, 0,
2489 "http subrequest \"%V?%V\"", uri
, &sr
->args
);
2491 sr
->subrequest_in_memory
= (flags
& NGX_HTTP_SUBREQUEST_IN_MEMORY
) != 0;
2492 sr
->waited
= (flags
& NGX_HTTP_SUBREQUEST_WAITED
) != 0;
2494 sr
->unparsed_uri
= r
->unparsed_uri
;
2495 sr
->method_name
= ngx_http_core_get_method
;
2496 sr
->http_protocol
= r
->http_protocol
;
2498 ngx_http_set_exten(sr
);
2502 sr
->post_subrequest
= ps
;
2503 sr
->read_event_handler
= ngx_http_request_empty_handler
;
2504 sr
->write_event_handler
= ngx_http_handler
;
2506 if (c
->data
== r
&& r
->postponed
== NULL
) {
2510 sr
->variables
= r
->variables
;
2512 sr
->log_handler
= r
->log_handler
;
2514 pr
= ngx_palloc(r
->pool
, sizeof(ngx_http_postponed_request_t
));
2524 for (p
= r
->postponed
; p
->next
; p
= p
->next
) { /* void */ }
2533 sr
->discard_body
= r
->discard_body
;
2534 sr
->expect_tested
= 1;
2535 sr
->main_filter_need_in_memory
= r
->main_filter_need_in_memory
;
2537 sr
->uri_changes
= NGX_HTTP_MAX_URI_CHANGES
+ 1;
2539 tp
= ngx_timeofday();
2540 sr
->start_sec
= tp
->sec
;
2541 sr
->start_msec
= tp
->msec
;
2547 return ngx_http_post_request(sr
, NULL
);
2552 ngx_http_internal_redirect(ngx_http_request_t
*r
,
2553 ngx_str_t
*uri
, ngx_str_t
*args
)
2555 ngx_http_core_srv_conf_t
*cscf
;
2559 if (r
->uri_changes
== 0) {
2560 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
2561 "rewrite or internal redirection cycle "
2562 "while internally redirecting to \"%V\"", uri
);
2565 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
2575 ngx_str_null(&r
->args
);
2578 ngx_log_debug2(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
2579 "internal redirect: \"%V?%V\"", uri
, &r
->args
);
2581 ngx_http_set_exten(r
);
2583 /* clear the modules contexts */
2584 ngx_memzero(r
->ctx
, sizeof(void *) * ngx_http_max_module
);
2586 cscf
= ngx_http_get_module_srv_conf(r
, ngx_http_core_module
);
2587 r
->loc_conf
= cscf
->ctx
->loc_conf
;
2589 ngx_http_update_location_config(r
);
2591 #if (NGX_HTTP_CACHE)
2596 r
->valid_unparsed_uri
= 0;
2597 r
->add_uri_to_alias
= 0;
2600 ngx_http_handler(r
);
2607 ngx_http_named_location(ngx_http_request_t
*r
, ngx_str_t
*name
)
2609 ngx_http_core_srv_conf_t
*cscf
;
2610 ngx_http_core_loc_conf_t
**clcfp
;
2611 ngx_http_core_main_conf_t
*cmcf
;
2616 if (r
->uri_changes
== 0) {
2617 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
2618 "rewrite or internal redirection cycle "
2619 "while redirect to named location \"%V\"", name
);
2621 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
2625 cscf
= ngx_http_get_module_srv_conf(r
, ngx_http_core_module
);
2627 if (cscf
->named_locations
) {
2629 for (clcfp
= cscf
->named_locations
; *clcfp
; clcfp
++) {
2631 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
2632 "test location: \"%V\"", &(*clcfp
)->name
);
2634 if (name
->len
!= (*clcfp
)->name
.len
2635 || ngx_strncmp(name
->data
, (*clcfp
)->name
.data
, name
->len
) != 0)
2640 ngx_log_debug3(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
2641 "using location: %V \"%V?%V\"",
2642 name
, &r
->uri
, &r
->args
);
2645 r
->content_handler
= NULL
;
2647 r
->loc_conf
= (*clcfp
)->loc_conf
;
2649 /* clear the modules contexts */
2650 ngx_memzero(r
->ctx
, sizeof(void *) * ngx_http_max_module
);
2652 ngx_http_update_location_config(r
);
2654 cmcf
= ngx_http_get_module_main_conf(r
, ngx_http_core_module
);
2656 r
->phase_handler
= cmcf
->phase_engine
.location_rewrite_index
;
2658 r
->write_event_handler
= ngx_http_core_run_phases
;
2659 ngx_http_core_run_phases(r
);
2665 ngx_log_error(NGX_LOG_ERR
, r
->connection
->log
, 0,
2666 "could not find named location \"%V\"", name
);
2668 ngx_http_finalize_request(r
, NGX_HTTP_INTERNAL_SERVER_ERROR
);
2674 ngx_http_cleanup_t
*
2675 ngx_http_cleanup_add(ngx_http_request_t
*r
, size_t size
)
2677 ngx_http_cleanup_t
*cln
;
2681 cln
= ngx_palloc(r
->pool
, sizeof(ngx_http_cleanup_t
));
2687 cln
->data
= ngx_palloc(r
->pool
, size
);
2688 if (cln
->data
== NULL
) {
2696 cln
->handler
= NULL
;
2697 cln
->next
= r
->cleanup
;
2701 ngx_log_debug1(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
2702 "http cleanup add: %p", cln
);
2709 ngx_http_set_disable_symlinks(ngx_http_request_t
*r
,
2710 ngx_http_core_loc_conf_t
*clcf
, ngx_str_t
*path
, ngx_open_file_info_t
*of
)
2712 #if (NGX_HAVE_OPENAT)
2716 of
->disable_symlinks
= clcf
->disable_symlinks
;
2718 if (clcf
->disable_symlinks_from
== NULL
) {
2722 if (ngx_http_complex_value(r
, clcf
->disable_symlinks_from
, &from
)
2729 || from
.len
> path
->len
2730 || ngx_memcmp(path
->data
, from
.data
, from
.len
) != 0)
2735 if (from
.len
== path
->len
) {
2736 of
->disable_symlinks
= NGX_DISABLE_SYMLINKS_OFF
;
2740 p
= path
->data
+ from
.len
;
2743 of
->disable_symlinks_from
= from
.len
;
2750 of
->disable_symlinks_from
= from
.len
- 1;
2759 ngx_http_get_forwarded_addr(ngx_http_request_t
*r
, ngx_addr_t
*addr
,
2760 ngx_array_t
*headers
, ngx_str_t
*value
, ngx_array_t
*proxies
,
2764 ngx_uint_t i
, found
;
2765 ngx_table_elt_t
**h
;
2767 if (headers
== NULL
) {
2768 return ngx_http_get_forwarded_addr_internal(r
, addr
, value
->data
,
2769 value
->len
, proxies
,
2781 rc
= ngx_http_get_forwarded_addr_internal(r
, addr
, h
[i
]->value
.data
,
2782 h
[i
]->value
.len
, proxies
,
2789 if (rc
== NGX_DECLINED
&& found
) {
2806 ngx_http_get_forwarded_addr_internal(ngx_http_request_t
*r
, ngx_addr_t
*addr
,
2807 u_char
*xff
, size_t xfflen
, ngx_array_t
*proxies
, int recursive
)
2814 ngx_uint_t family
, i
;
2815 #if (NGX_HAVE_INET6)
2817 struct in6_addr
*inaddr6
;
2820 #if (NGX_SUPPRESS_WARN)
2822 #if (NGX_HAVE_INET6)
2827 family
= addr
->sockaddr
->sa_family
;
2829 if (family
== AF_INET
) {
2830 inaddr
= ((struct sockaddr_in
*) addr
->sockaddr
)->sin_addr
.s_addr
;
2833 #if (NGX_HAVE_INET6)
2834 else if (family
== AF_INET6
) {
2835 inaddr6
= &((struct sockaddr_in6
*) addr
->sockaddr
)->sin6_addr
;
2837 if (IN6_IS_ADDR_V4MAPPED(inaddr6
)) {
2840 p
= inaddr6
->s6_addr
;
2842 inaddr
= p
[12] << 24;
2843 inaddr
+= p
[13] << 16;
2844 inaddr
+= p
[14] << 8;
2847 inaddr
= htonl(inaddr
);
2852 for (cidr
= proxies
->elts
, i
= 0; i
< proxies
->nelts
; i
++) {
2853 if (cidr
[i
].family
!= family
) {
2859 #if (NGX_HAVE_INET6)
2861 for (n
= 0; n
< 16; n
++) {
2862 if ((inaddr6
->s6_addr
[n
] & cidr
[i
].u
.in6
.mask
.s6_addr
[n
])
2863 != cidr
[i
].u
.in6
.addr
.s6_addr
[n
])
2871 #if (NGX_HAVE_UNIX_DOMAIN)
2876 default: /* AF_INET */
2877 if ((inaddr
& cidr
[i
].u
.in
.mask
) != cidr
[i
].u
.in
.addr
) {
2883 for (p
= xff
+ xfflen
- 1; p
> xff
; p
--, xfflen
--) {
2884 if (*p
!= ' ' && *p
!= ',') {
2889 for ( /* void */ ; p
> xff
; p
--) {
2890 if (*p
== ' ' || *p
== ',') {
2896 if (ngx_parse_addr(r
->pool
, &paddr
, p
, xfflen
- (p
- xff
)) != NGX_OK
) {
2897 return NGX_DECLINED
;
2902 if (recursive
&& p
> xff
) {
2903 rc
= ngx_http_get_forwarded_addr_internal(r
, addr
, xff
, p
- 1 - xff
,
2906 if (rc
== NGX_DECLINED
) {
2910 /* rc == NGX_OK || rc == NGX_DONE */
2920 return NGX_DECLINED
;
2925 ngx_http_core_server(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *dummy
)
2931 ngx_http_module_t
*module
;
2932 struct sockaddr_in
*sin
;
2933 ngx_http_conf_ctx_t
*ctx
, *http_ctx
;
2934 ngx_http_listen_opt_t lsopt
;
2935 ngx_http_core_srv_conf_t
*cscf
, **cscfp
;
2936 ngx_http_core_main_conf_t
*cmcf
;
2938 ctx
= ngx_pcalloc(cf
->pool
, sizeof(ngx_http_conf_ctx_t
));
2940 return NGX_CONF_ERROR
;
2944 ctx
->main_conf
= http_ctx
->main_conf
;
2946 /* the server{}'s srv_conf */
2948 ctx
->srv_conf
= ngx_pcalloc(cf
->pool
, sizeof(void *) * ngx_http_max_module
);
2949 if (ctx
->srv_conf
== NULL
) {
2950 return NGX_CONF_ERROR
;
2953 /* the server{}'s loc_conf */
2955 ctx
->loc_conf
= ngx_pcalloc(cf
->pool
, sizeof(void *) * ngx_http_max_module
);
2956 if (ctx
->loc_conf
== NULL
) {
2957 return NGX_CONF_ERROR
;
2960 for (i
= 0; ngx_modules
[i
]; i
++) {
2961 if (ngx_modules
[i
]->type
!= NGX_HTTP_MODULE
) {
2965 module
= ngx_modules
[i
]->ctx
;
2967 if (module
->create_srv_conf
) {
2968 mconf
= module
->create_srv_conf(cf
);
2969 if (mconf
== NULL
) {
2970 return NGX_CONF_ERROR
;
2973 ctx
->srv_conf
[ngx_modules
[i
]->ctx_index
] = mconf
;
2976 if (module
->create_loc_conf
) {
2977 mconf
= module
->create_loc_conf(cf
);
2978 if (mconf
== NULL
) {
2979 return NGX_CONF_ERROR
;
2982 ctx
->loc_conf
[ngx_modules
[i
]->ctx_index
] = mconf
;
2987 /* the server configuration context */
2989 cscf
= ctx
->srv_conf
[ngx_http_core_module
.ctx_index
];
2993 cmcf
= ctx
->main_conf
[ngx_http_core_module
.ctx_index
];
2995 cscfp
= ngx_array_push(&cmcf
->servers
);
2996 if (cscfp
== NULL
) {
2997 return NGX_CONF_ERROR
;
3003 /* parse inside server{} */
3007 cf
->cmd_type
= NGX_HTTP_SRV_CONF
;
3009 rv
= ngx_conf_parse(cf
, NULL
);
3013 if (rv
== NGX_CONF_OK
&& !cscf
->listen
) {
3014 ngx_memzero(&lsopt
, sizeof(ngx_http_listen_opt_t
));
3016 sin
= &lsopt
.u
.sockaddr_in
;
3018 sin
->sin_family
= AF_INET
;
3020 sin
->sin_port
= htons(80);
3022 sin
->sin_port
= htons((getuid() == 0) ? 80 : 8000);
3024 sin
->sin_addr
.s_addr
= INADDR_ANY
;
3026 lsopt
.socklen
= sizeof(struct sockaddr_in
);
3028 lsopt
.backlog
= NGX_LISTEN_BACKLOG
;
3031 #if (NGX_HAVE_SETFIB)
3036 (void) ngx_sock_ntop(&lsopt
.u
.sockaddr
, lsopt
.addr
,
3037 NGX_SOCKADDR_STRLEN
, 1);
3039 if (ngx_http_add_listen(cf
, cscf
, &lsopt
) != NGX_OK
) {
3040 return NGX_CONF_ERROR
;
3049 ngx_http_core_location(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *dummy
)
3054 ngx_str_t
*value
, *name
;
3057 ngx_http_module_t
*module
;
3058 ngx_http_conf_ctx_t
*ctx
, *pctx
;
3059 ngx_http_core_loc_conf_t
*clcf
, *pclcf
;
3061 ctx
= ngx_pcalloc(cf
->pool
, sizeof(ngx_http_conf_ctx_t
));
3063 return NGX_CONF_ERROR
;
3067 ctx
->main_conf
= pctx
->main_conf
;
3068 ctx
->srv_conf
= pctx
->srv_conf
;
3070 ctx
->loc_conf
= ngx_pcalloc(cf
->pool
, sizeof(void *) * ngx_http_max_module
);
3071 if (ctx
->loc_conf
== NULL
) {
3072 return NGX_CONF_ERROR
;
3075 for (i
= 0; ngx_modules
[i
]; i
++) {
3076 if (ngx_modules
[i
]->type
!= NGX_HTTP_MODULE
) {
3080 module
= ngx_modules
[i
]->ctx
;
3082 if (module
->create_loc_conf
) {
3083 ctx
->loc_conf
[ngx_modules
[i
]->ctx_index
] =
3084 module
->create_loc_conf(cf
);
3085 if (ctx
->loc_conf
[ngx_modules
[i
]->ctx_index
] == NULL
) {
3086 return NGX_CONF_ERROR
;
3091 clcf
= ctx
->loc_conf
[ngx_http_core_module
.ctx_index
];
3092 clcf
->loc_conf
= ctx
->loc_conf
;
3094 value
= cf
->args
->elts
;
3096 if (cf
->args
->nelts
== 3) {
3099 mod
= value
[1].data
;
3102 if (len
== 1 && mod
[0] == '=') {
3105 clcf
->exact_match
= 1;
3107 } else if (len
== 2 && mod
[0] == '^' && mod
[1] == '~') {
3112 } else if (len
== 1 && mod
[0] == '~') {
3114 if (ngx_http_core_regex_location(cf
, clcf
, name
, 0) != NGX_OK
) {
3115 return NGX_CONF_ERROR
;
3118 } else if (len
== 2 && mod
[0] == '~' && mod
[1] == '*') {
3120 if (ngx_http_core_regex_location(cf
, clcf
, name
, 1) != NGX_OK
) {
3121 return NGX_CONF_ERROR
;
3125 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3126 "invalid location modifier \"%V\"", &value
[1]);
3127 return NGX_CONF_ERROR
;
3134 if (name
->data
[0] == '=') {
3136 clcf
->name
.len
= name
->len
- 1;
3137 clcf
->name
.data
= name
->data
+ 1;
3138 clcf
->exact_match
= 1;
3140 } else if (name
->data
[0] == '^' && name
->data
[1] == '~') {
3142 clcf
->name
.len
= name
->len
- 2;
3143 clcf
->name
.data
= name
->data
+ 2;
3146 } else if (name
->data
[0] == '~') {
3151 if (name
->data
[0] == '*') {
3156 if (ngx_http_core_regex_location(cf
, clcf
, name
, 1) != NGX_OK
) {
3157 return NGX_CONF_ERROR
;
3161 if (ngx_http_core_regex_location(cf
, clcf
, name
, 0) != NGX_OK
) {
3162 return NGX_CONF_ERROR
;
3170 if (name
->data
[0] == '@') {
3176 pclcf
= pctx
->loc_conf
[ngx_http_core_module
.ctx_index
];
3178 if (pclcf
->name
.len
) {
3180 /* nested location */
3183 clcf
->prev_location
= pclcf
;
3186 if (pclcf
->exact_match
) {
3187 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3188 "location \"%V\" cannot be inside "
3189 "the exact location \"%V\"",
3190 &clcf
->name
, &pclcf
->name
);
3191 return NGX_CONF_ERROR
;
3195 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3196 "location \"%V\" cannot be inside "
3197 "the named location \"%V\"",
3198 &clcf
->name
, &pclcf
->name
);
3199 return NGX_CONF_ERROR
;
3203 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3204 "named location \"%V\" can be "
3205 "on the server level only",
3207 return NGX_CONF_ERROR
;
3210 len
= pclcf
->name
.len
;
3213 if (clcf
->regex
== NULL
3214 && ngx_strncmp(clcf
->name
.data
, pclcf
->name
.data
, len
) != 0)
3216 if (ngx_strncmp(clcf
->name
.data
, pclcf
->name
.data
, len
) != 0)
3219 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3220 "location \"%V\" is outside location \"%V\"",
3221 &clcf
->name
, &pclcf
->name
);
3222 return NGX_CONF_ERROR
;
3226 if (ngx_http_add_location(cf
, &pclcf
->locations
, clcf
) != NGX_OK
) {
3227 return NGX_CONF_ERROR
;
3232 cf
->cmd_type
= NGX_HTTP_LOC_CONF
;
3234 rv
= ngx_conf_parse(cf
, NULL
);
3243 ngx_http_core_regex_location(ngx_conf_t
*cf
, ngx_http_core_loc_conf_t
*clcf
,
3244 ngx_str_t
*regex
, ngx_uint_t caseless
)
3247 ngx_regex_compile_t rc
;
3248 u_char errstr
[NGX_MAX_CONF_ERRSTR
];
3250 ngx_memzero(&rc
, sizeof(ngx_regex_compile_t
));
3252 rc
.pattern
= *regex
;
3253 rc
.err
.len
= NGX_MAX_CONF_ERRSTR
;
3254 rc
.err
.data
= errstr
;
3256 #if (NGX_HAVE_CASELESS_FILESYSTEM)
3257 rc
.options
= NGX_REGEX_CASELESS
;
3259 rc
.options
= caseless
? NGX_REGEX_CASELESS
: 0;
3262 clcf
->regex
= ngx_http_regex_compile(cf
, &rc
);
3263 if (clcf
->regex
== NULL
) {
3267 clcf
->name
= *regex
;
3273 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3274 "using regex \"%V\" requires PCRE library",
3283 ngx_http_core_types(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
3285 ngx_http_core_loc_conf_t
*clcf
= conf
;
3290 if (clcf
->types
== NULL
) {
3291 clcf
->types
= ngx_array_create(cf
->pool
, 64, sizeof(ngx_hash_key_t
));
3292 if (clcf
->types
== NULL
) {
3293 return NGX_CONF_ERROR
;
3298 cf
->handler
= ngx_http_core_type
;
3299 cf
->handler_conf
= conf
;
3301 rv
= ngx_conf_parse(cf
, NULL
);
3310 ngx_http_core_type(ngx_conf_t
*cf
, ngx_command_t
*dummy
, void *conf
)
3312 ngx_http_core_loc_conf_t
*clcf
= conf
;
3314 ngx_str_t
*value
, *content_type
, *old
;
3315 ngx_uint_t i
, n
, hash
;
3316 ngx_hash_key_t
*type
;
3318 value
= cf
->args
->elts
;
3320 if (ngx_strcmp(value
[0].data
, "include") == 0) {
3321 if (cf
->args
->nelts
!= 2) {
3322 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3323 "invalid number of arguments"
3324 " in \"include\" directive");
3325 return NGX_CONF_ERROR
;
3328 return ngx_conf_include(cf
, dummy
, conf
);
3331 content_type
= ngx_palloc(cf
->pool
, sizeof(ngx_str_t
));
3332 if (content_type
== NULL
) {
3333 return NGX_CONF_ERROR
;
3336 *content_type
= value
[0];
3338 for (i
= 1; i
< cf
->args
->nelts
; i
++) {
3340 hash
= ngx_hash_strlow(value
[i
].data
, value
[i
].data
, value
[i
].len
);
3342 type
= clcf
->types
->elts
;
3343 for (n
= 0; n
< clcf
->types
->nelts
; n
++) {
3344 if (ngx_strcmp(value
[i
].data
, type
[n
].key
.data
) == 0) {
3345 old
= type
[n
].value
;
3346 type
[n
].value
= content_type
;
3348 ngx_conf_log_error(NGX_LOG_WARN
, cf
, 0,
3349 "duplicate extension \"%V\", "
3350 "content type: \"%V\", "
3351 "previous content type: \"%V\"",
3352 &value
[i
], content_type
, old
);
3358 type
= ngx_array_push(clcf
->types
);
3360 return NGX_CONF_ERROR
;
3363 type
->key
= value
[i
];
3364 type
->key_hash
= hash
;
3365 type
->value
= content_type
;
3376 ngx_http_core_preconfiguration(ngx_conf_t
*cf
)
3378 return ngx_http_variables_add_core_vars(cf
);
3383 ngx_http_core_create_main_conf(ngx_conf_t
*cf
)
3385 ngx_http_core_main_conf_t
*cmcf
;
3387 cmcf
= ngx_pcalloc(cf
->pool
, sizeof(ngx_http_core_main_conf_t
));
3392 if (ngx_array_init(&cmcf
->servers
, cf
->pool
, 4,
3393 sizeof(ngx_http_core_srv_conf_t
*))
3399 cmcf
->server_names_hash_max_size
= NGX_CONF_UNSET_UINT
;
3400 cmcf
->server_names_hash_bucket_size
= NGX_CONF_UNSET_UINT
;
3402 cmcf
->variables_hash_max_size
= NGX_CONF_UNSET_UINT
;
3403 cmcf
->variables_hash_bucket_size
= NGX_CONF_UNSET_UINT
;
3410 ngx_http_core_init_main_conf(ngx_conf_t
*cf
, void *conf
)
3412 ngx_http_core_main_conf_t
*cmcf
= conf
;
3414 if (cmcf
->server_names_hash_max_size
== NGX_CONF_UNSET_UINT
) {
3415 cmcf
->server_names_hash_max_size
= 512;
3418 if (cmcf
->server_names_hash_bucket_size
== NGX_CONF_UNSET_UINT
) {
3419 cmcf
->server_names_hash_bucket_size
= ngx_cacheline_size
;
3422 cmcf
->server_names_hash_bucket_size
=
3423 ngx_align(cmcf
->server_names_hash_bucket_size
, ngx_cacheline_size
);
3426 if (cmcf
->variables_hash_max_size
== NGX_CONF_UNSET_UINT
) {
3427 cmcf
->variables_hash_max_size
= 512;
3430 if (cmcf
->variables_hash_bucket_size
== NGX_CONF_UNSET_UINT
) {
3431 cmcf
->variables_hash_bucket_size
= 64;
3434 cmcf
->variables_hash_bucket_size
=
3435 ngx_align(cmcf
->variables_hash_bucket_size
, ngx_cacheline_size
);
3437 if (cmcf
->ncaptures
) {
3438 cmcf
->ncaptures
= (cmcf
->ncaptures
+ 1) * 3;
3446 ngx_http_core_create_srv_conf(ngx_conf_t
*cf
)
3448 ngx_http_core_srv_conf_t
*cscf
;
3450 cscf
= ngx_pcalloc(cf
->pool
, sizeof(ngx_http_core_srv_conf_t
));
3456 * set by ngx_pcalloc():
3458 * conf->client_large_buffers.num = 0;
3461 if (ngx_array_init(&cscf
->server_names
, cf
->temp_pool
, 4,
3462 sizeof(ngx_http_server_name_t
))
3468 cscf
->connection_pool_size
= NGX_CONF_UNSET_SIZE
;
3469 cscf
->request_pool_size
= NGX_CONF_UNSET_SIZE
;
3470 cscf
->client_header_timeout
= NGX_CONF_UNSET_MSEC
;
3471 cscf
->client_header_buffer_size
= NGX_CONF_UNSET_SIZE
;
3472 cscf
->ignore_invalid_headers
= NGX_CONF_UNSET
;
3473 cscf
->merge_slashes
= NGX_CONF_UNSET
;
3474 cscf
->underscores_in_headers
= NGX_CONF_UNSET
;
3481 ngx_http_core_merge_srv_conf(ngx_conf_t
*cf
, void *parent
, void *child
)
3483 ngx_http_core_srv_conf_t
*prev
= parent
;
3484 ngx_http_core_srv_conf_t
*conf
= child
;
3487 ngx_http_server_name_t
*sn
;
3489 /* TODO: it does not merge, it inits only */
3491 ngx_conf_merge_size_value(conf
->connection_pool_size
,
3492 prev
->connection_pool_size
, 256);
3493 ngx_conf_merge_size_value(conf
->request_pool_size
,
3494 prev
->request_pool_size
, 4096);
3495 ngx_conf_merge_msec_value(conf
->client_header_timeout
,
3496 prev
->client_header_timeout
, 60000);
3497 ngx_conf_merge_size_value(conf
->client_header_buffer_size
,
3498 prev
->client_header_buffer_size
, 1024);
3499 ngx_conf_merge_bufs_value(conf
->large_client_header_buffers
,
3500 prev
->large_client_header_buffers
,
3503 if (conf
->large_client_header_buffers
.size
< conf
->connection_pool_size
) {
3504 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3505 "the \"large_client_header_buffers\" size must be "
3506 "equal to or greater than \"connection_pool_size\"");
3507 return NGX_CONF_ERROR
;
3510 ngx_conf_merge_value(conf
->ignore_invalid_headers
,
3511 prev
->ignore_invalid_headers
, 1);
3513 ngx_conf_merge_value(conf
->merge_slashes
, prev
->merge_slashes
, 1);
3515 ngx_conf_merge_value(conf
->underscores_in_headers
,
3516 prev
->underscores_in_headers
, 0);
3518 if (conf
->server_names
.nelts
== 0) {
3519 /* the array has 4 empty preallocated elements, so push cannot fail */
3520 sn
= ngx_array_push(&conf
->server_names
);
3525 ngx_str_set(&sn
->name
, "");
3528 sn
= conf
->server_names
.elts
;
3538 if (name
.data
[0] == '.') {
3543 conf
->server_name
.len
= name
.len
;
3544 conf
->server_name
.data
= ngx_pstrdup(cf
->pool
, &name
);
3545 if (conf
->server_name
.data
== NULL
) {
3546 return NGX_CONF_ERROR
;
3554 ngx_http_core_create_loc_conf(ngx_conf_t
*cf
)
3556 ngx_http_core_loc_conf_t
*clcf
;
3558 clcf
= ngx_pcalloc(cf
->pool
, sizeof(ngx_http_core_loc_conf_t
));
3564 * set by ngx_pcalloc():
3566 * clcf->root = { 0, NULL };
3567 * clcf->limit_except = 0;
3568 * clcf->post_action = { 0, NULL };
3569 * clcf->types = NULL;
3570 * clcf->default_type = { 0, NULL };
3571 * clcf->error_log = NULL;
3572 * clcf->error_pages = NULL;
3573 * clcf->try_files = NULL;
3574 * clcf->client_body_path = NULL;
3575 * clcf->regex = NULL;
3576 * clcf->exact_match = 0;
3577 * clcf->auto_redirect = 0;
3579 * clcf->gzip_proxied = 0;
3580 * clcf->keepalive_disable = 0;
3583 clcf
->client_max_body_size
= NGX_CONF_UNSET
;
3584 clcf
->client_body_buffer_size
= NGX_CONF_UNSET_SIZE
;
3585 clcf
->client_body_timeout
= NGX_CONF_UNSET_MSEC
;
3586 clcf
->satisfy
= NGX_CONF_UNSET_UINT
;
3587 clcf
->if_modified_since
= NGX_CONF_UNSET_UINT
;
3588 clcf
->max_ranges
= NGX_CONF_UNSET_UINT
;
3589 clcf
->client_body_in_file_only
= NGX_CONF_UNSET_UINT
;
3590 clcf
->client_body_in_single_buffer
= NGX_CONF_UNSET
;
3591 clcf
->internal
= NGX_CONF_UNSET
;
3592 clcf
->sendfile
= NGX_CONF_UNSET
;
3593 clcf
->sendfile_max_chunk
= NGX_CONF_UNSET_SIZE
;
3594 #if (NGX_HAVE_FILE_AIO)
3595 clcf
->aio
= NGX_CONF_UNSET
;
3597 clcf
->read_ahead
= NGX_CONF_UNSET_SIZE
;
3598 clcf
->directio
= NGX_CONF_UNSET
;
3599 clcf
->directio_alignment
= NGX_CONF_UNSET
;
3600 clcf
->tcp_nopush
= NGX_CONF_UNSET
;
3601 clcf
->tcp_nodelay
= NGX_CONF_UNSET
;
3602 clcf
->send_timeout
= NGX_CONF_UNSET_MSEC
;
3603 clcf
->send_lowat
= NGX_CONF_UNSET_SIZE
;
3604 clcf
->postpone_output
= NGX_CONF_UNSET_SIZE
;
3605 clcf
->limit_rate
= NGX_CONF_UNSET_SIZE
;
3606 clcf
->limit_rate_after
= NGX_CONF_UNSET_SIZE
;
3607 clcf
->keepalive_timeout
= NGX_CONF_UNSET_MSEC
;
3608 clcf
->keepalive_header
= NGX_CONF_UNSET
;
3609 clcf
->keepalive_requests
= NGX_CONF_UNSET_UINT
;
3610 clcf
->lingering_close
= NGX_CONF_UNSET_UINT
;
3611 clcf
->lingering_time
= NGX_CONF_UNSET_MSEC
;
3612 clcf
->lingering_timeout
= NGX_CONF_UNSET_MSEC
;
3613 clcf
->resolver_timeout
= NGX_CONF_UNSET_MSEC
;
3614 clcf
->reset_timedout_connection
= NGX_CONF_UNSET
;
3615 clcf
->server_name_in_redirect
= NGX_CONF_UNSET
;
3616 clcf
->port_in_redirect
= NGX_CONF_UNSET
;
3617 clcf
->msie_padding
= NGX_CONF_UNSET
;
3618 clcf
->msie_refresh
= NGX_CONF_UNSET
;
3619 clcf
->log_not_found
= NGX_CONF_UNSET
;
3620 clcf
->log_subrequest
= NGX_CONF_UNSET
;
3621 clcf
->recursive_error_pages
= NGX_CONF_UNSET
;
3622 clcf
->server_tokens
= NGX_CONF_UNSET
;
3623 clcf
->chunked_transfer_encoding
= NGX_CONF_UNSET
;
3624 clcf
->etag
= NGX_CONF_UNSET
;
3625 clcf
->types_hash_max_size
= NGX_CONF_UNSET_UINT
;
3626 clcf
->types_hash_bucket_size
= NGX_CONF_UNSET_UINT
;
3628 clcf
->open_file_cache
= NGX_CONF_UNSET_PTR
;
3629 clcf
->open_file_cache_valid
= NGX_CONF_UNSET
;
3630 clcf
->open_file_cache_min_uses
= NGX_CONF_UNSET_UINT
;
3631 clcf
->open_file_cache_errors
= NGX_CONF_UNSET
;
3632 clcf
->open_file_cache_events
= NGX_CONF_UNSET
;
3635 clcf
->gzip_vary
= NGX_CONF_UNSET
;
3636 clcf
->gzip_http_version
= NGX_CONF_UNSET_UINT
;
3638 clcf
->gzip_disable
= NGX_CONF_UNSET_PTR
;
3640 clcf
->gzip_disable_msie6
= 3;
3641 #if (NGX_HTTP_DEGRADATION)
3642 clcf
->gzip_disable_degradation
= 3;
3646 #if (NGX_HAVE_OPENAT)
3647 clcf
->disable_symlinks
= NGX_CONF_UNSET_UINT
;
3648 clcf
->disable_symlinks_from
= NGX_CONF_UNSET_PTR
;
3655 static ngx_str_t ngx_http_core_text_html_type
= ngx_string("text/html");
3656 static ngx_str_t ngx_http_core_image_gif_type
= ngx_string("image/gif");
3657 static ngx_str_t ngx_http_core_image_jpeg_type
= ngx_string("image/jpeg");
3659 static ngx_hash_key_t ngx_http_core_default_types
[] = {
3660 { ngx_string("html"), 0, &ngx_http_core_text_html_type
},
3661 { ngx_string("gif"), 0, &ngx_http_core_image_gif_type
},
3662 { ngx_string("jpg"), 0, &ngx_http_core_image_jpeg_type
},
3663 { ngx_null_string
, 0, NULL
}
3668 ngx_http_core_merge_loc_conf(ngx_conf_t
*cf
, void *parent
, void *child
)
3670 ngx_http_core_loc_conf_t
*prev
= parent
;
3671 ngx_http_core_loc_conf_t
*conf
= child
;
3674 ngx_hash_key_t
*type
;
3675 ngx_hash_init_t types_hash
;
3677 if (conf
->root
.data
== NULL
) {
3679 conf
->alias
= prev
->alias
;
3680 conf
->root
= prev
->root
;
3681 conf
->root_lengths
= prev
->root_lengths
;
3682 conf
->root_values
= prev
->root_values
;
3684 if (prev
->root
.data
== NULL
) {
3685 ngx_str_set(&conf
->root
, "html");
3687 if (ngx_conf_full_name(cf
->cycle
, &conf
->root
, 0) != NGX_OK
) {
3688 return NGX_CONF_ERROR
;
3693 if (conf
->post_action
.data
== NULL
) {
3694 conf
->post_action
= prev
->post_action
;
3697 ngx_conf_merge_uint_value(conf
->types_hash_max_size
,
3698 prev
->types_hash_max_size
, 1024);
3700 ngx_conf_merge_uint_value(conf
->types_hash_bucket_size
,
3701 prev
->types_hash_bucket_size
,
3702 ngx_cacheline_size
);
3704 conf
->types_hash_bucket_size
= ngx_align(conf
->types_hash_bucket_size
,
3705 ngx_cacheline_size
);
3708 * the special handling of the "types" directive in the "http" section
3709 * to inherit the http's conf->types_hash to all servers
3712 if (prev
->types
&& prev
->types_hash
.buckets
== NULL
) {
3714 types_hash
.hash
= &prev
->types_hash
;
3715 types_hash
.key
= ngx_hash_key_lc
;
3716 types_hash
.max_size
= conf
->types_hash_max_size
;
3717 types_hash
.bucket_size
= conf
->types_hash_bucket_size
;
3718 types_hash
.name
= "types_hash";
3719 types_hash
.pool
= cf
->pool
;
3720 types_hash
.temp_pool
= NULL
;
3722 if (ngx_hash_init(&types_hash
, prev
->types
->elts
, prev
->types
->nelts
)
3725 return NGX_CONF_ERROR
;
3729 if (conf
->types
== NULL
) {
3730 conf
->types
= prev
->types
;
3731 conf
->types_hash
= prev
->types_hash
;
3734 if (conf
->types
== NULL
) {
3735 conf
->types
= ngx_array_create(cf
->pool
, 3, sizeof(ngx_hash_key_t
));
3736 if (conf
->types
== NULL
) {
3737 return NGX_CONF_ERROR
;
3740 for (i
= 0; ngx_http_core_default_types
[i
].key
.len
; i
++) {
3741 type
= ngx_array_push(conf
->types
);
3743 return NGX_CONF_ERROR
;
3746 type
->key
= ngx_http_core_default_types
[i
].key
;
3748 ngx_hash_key_lc(ngx_http_core_default_types
[i
].key
.data
,
3749 ngx_http_core_default_types
[i
].key
.len
);
3750 type
->value
= ngx_http_core_default_types
[i
].value
;
3754 if (conf
->types_hash
.buckets
== NULL
) {
3756 types_hash
.hash
= &conf
->types_hash
;
3757 types_hash
.key
= ngx_hash_key_lc
;
3758 types_hash
.max_size
= conf
->types_hash_max_size
;
3759 types_hash
.bucket_size
= conf
->types_hash_bucket_size
;
3760 types_hash
.name
= "types_hash";
3761 types_hash
.pool
= cf
->pool
;
3762 types_hash
.temp_pool
= NULL
;
3764 if (ngx_hash_init(&types_hash
, conf
->types
->elts
, conf
->types
->nelts
)
3767 return NGX_CONF_ERROR
;
3771 if (conf
->error_log
== NULL
) {
3772 if (prev
->error_log
) {
3773 conf
->error_log
= prev
->error_log
;
3775 conf
->error_log
= &cf
->cycle
->new_log
;
3779 if (conf
->error_pages
== NULL
&& prev
->error_pages
) {
3780 conf
->error_pages
= prev
->error_pages
;
3783 ngx_conf_merge_str_value(conf
->default_type
,
3784 prev
->default_type
, "text/plain");
3786 ngx_conf_merge_off_value(conf
->client_max_body_size
,
3787 prev
->client_max_body_size
, 1 * 1024 * 1024);
3788 ngx_conf_merge_size_value(conf
->client_body_buffer_size
,
3789 prev
->client_body_buffer_size
,
3790 (size_t) 2 * ngx_pagesize
);
3791 ngx_conf_merge_msec_value(conf
->client_body_timeout
,
3792 prev
->client_body_timeout
, 60000);
3794 ngx_conf_merge_bitmask_value(conf
->keepalive_disable
,
3795 prev
->keepalive_disable
,
3796 (NGX_CONF_BITMASK_SET
3797 |NGX_HTTP_KEEPALIVE_DISABLE_MSIE6
));
3798 ngx_conf_merge_uint_value(conf
->satisfy
, prev
->satisfy
,
3799 NGX_HTTP_SATISFY_ALL
);
3800 ngx_conf_merge_uint_value(conf
->if_modified_since
, prev
->if_modified_since
,
3801 NGX_HTTP_IMS_EXACT
);
3802 ngx_conf_merge_uint_value(conf
->max_ranges
, prev
->max_ranges
,
3803 NGX_MAX_INT32_VALUE
);
3804 ngx_conf_merge_uint_value(conf
->client_body_in_file_only
,
3805 prev
->client_body_in_file_only
,
3806 NGX_HTTP_REQUEST_BODY_FILE_OFF
);
3807 ngx_conf_merge_value(conf
->client_body_in_single_buffer
,
3808 prev
->client_body_in_single_buffer
, 0);
3809 ngx_conf_merge_value(conf
->internal
, prev
->internal
, 0);
3810 ngx_conf_merge_value(conf
->sendfile
, prev
->sendfile
, 0);
3811 ngx_conf_merge_size_value(conf
->sendfile_max_chunk
,
3812 prev
->sendfile_max_chunk
, 0);
3813 #if (NGX_HAVE_FILE_AIO)
3814 ngx_conf_merge_value(conf
->aio
, prev
->aio
, NGX_HTTP_AIO_OFF
);
3816 ngx_conf_merge_size_value(conf
->read_ahead
, prev
->read_ahead
, 0);
3817 ngx_conf_merge_off_value(conf
->directio
, prev
->directio
,
3818 NGX_OPEN_FILE_DIRECTIO_OFF
);
3819 ngx_conf_merge_off_value(conf
->directio_alignment
, prev
->directio_alignment
,
3821 ngx_conf_merge_value(conf
->tcp_nopush
, prev
->tcp_nopush
, 0);
3822 ngx_conf_merge_value(conf
->tcp_nodelay
, prev
->tcp_nodelay
, 1);
3824 ngx_conf_merge_msec_value(conf
->send_timeout
, prev
->send_timeout
, 60000);
3825 ngx_conf_merge_size_value(conf
->send_lowat
, prev
->send_lowat
, 0);
3826 ngx_conf_merge_size_value(conf
->postpone_output
, prev
->postpone_output
,
3828 ngx_conf_merge_size_value(conf
->limit_rate
, prev
->limit_rate
, 0);
3829 ngx_conf_merge_size_value(conf
->limit_rate_after
, prev
->limit_rate_after
,
3831 ngx_conf_merge_msec_value(conf
->keepalive_timeout
,
3832 prev
->keepalive_timeout
, 75000);
3833 ngx_conf_merge_sec_value(conf
->keepalive_header
,
3834 prev
->keepalive_header
, 0);
3835 ngx_conf_merge_uint_value(conf
->keepalive_requests
,
3836 prev
->keepalive_requests
, 100);
3837 ngx_conf_merge_uint_value(conf
->lingering_close
,
3838 prev
->lingering_close
, NGX_HTTP_LINGERING_ON
);
3839 ngx_conf_merge_msec_value(conf
->lingering_time
,
3840 prev
->lingering_time
, 30000);
3841 ngx_conf_merge_msec_value(conf
->lingering_timeout
,
3842 prev
->lingering_timeout
, 5000);
3843 ngx_conf_merge_msec_value(conf
->resolver_timeout
,
3844 prev
->resolver_timeout
, 30000);
3846 if (conf
->resolver
== NULL
) {
3848 if (prev
->resolver
== NULL
) {
3851 * create dummy resolver in http {} context
3852 * to inherit it in all servers
3855 prev
->resolver
= ngx_resolver_create(cf
, NULL
, 0);
3856 if (prev
->resolver
== NULL
) {
3857 return NGX_CONF_ERROR
;
3861 conf
->resolver
= prev
->resolver
;
3864 if (ngx_conf_merge_path_value(cf
, &conf
->client_body_temp_path
,
3865 prev
->client_body_temp_path
,
3866 &ngx_http_client_temp_path
)
3869 return NGX_CONF_ERROR
;
3872 ngx_conf_merge_value(conf
->reset_timedout_connection
,
3873 prev
->reset_timedout_connection
, 0);
3874 ngx_conf_merge_value(conf
->server_name_in_redirect
,
3875 prev
->server_name_in_redirect
, 0);
3876 ngx_conf_merge_value(conf
->port_in_redirect
, prev
->port_in_redirect
, 1);
3877 ngx_conf_merge_value(conf
->msie_padding
, prev
->msie_padding
, 1);
3878 ngx_conf_merge_value(conf
->msie_refresh
, prev
->msie_refresh
, 0);
3879 ngx_conf_merge_value(conf
->log_not_found
, prev
->log_not_found
, 1);
3880 ngx_conf_merge_value(conf
->log_subrequest
, prev
->log_subrequest
, 0);
3881 ngx_conf_merge_value(conf
->recursive_error_pages
,
3882 prev
->recursive_error_pages
, 0);
3883 ngx_conf_merge_value(conf
->server_tokens
, prev
->server_tokens
, 1);
3884 ngx_conf_merge_value(conf
->chunked_transfer_encoding
,
3885 prev
->chunked_transfer_encoding
, 1);
3886 ngx_conf_merge_value(conf
->etag
, prev
->etag
, 1);
3888 ngx_conf_merge_ptr_value(conf
->open_file_cache
,
3889 prev
->open_file_cache
, NULL
);
3891 ngx_conf_merge_sec_value(conf
->open_file_cache_valid
,
3892 prev
->open_file_cache_valid
, 60);
3894 ngx_conf_merge_uint_value(conf
->open_file_cache_min_uses
,
3895 prev
->open_file_cache_min_uses
, 1);
3897 ngx_conf_merge_sec_value(conf
->open_file_cache_errors
,
3898 prev
->open_file_cache_errors
, 0);
3900 ngx_conf_merge_sec_value(conf
->open_file_cache_events
,
3901 prev
->open_file_cache_events
, 0);
3904 ngx_conf_merge_value(conf
->gzip_vary
, prev
->gzip_vary
, 0);
3905 ngx_conf_merge_uint_value(conf
->gzip_http_version
, prev
->gzip_http_version
,
3906 NGX_HTTP_VERSION_11
);
3907 ngx_conf_merge_bitmask_value(conf
->gzip_proxied
, prev
->gzip_proxied
,
3908 (NGX_CONF_BITMASK_SET
|NGX_HTTP_GZIP_PROXIED_OFF
));
3911 ngx_conf_merge_ptr_value(conf
->gzip_disable
, prev
->gzip_disable
, NULL
);
3914 if (conf
->gzip_disable_msie6
== 3) {
3915 conf
->gzip_disable_msie6
=
3916 (prev
->gzip_disable_msie6
== 3) ? 0 : prev
->gzip_disable_msie6
;
3919 #if (NGX_HTTP_DEGRADATION)
3921 if (conf
->gzip_disable_degradation
== 3) {
3922 conf
->gzip_disable_degradation
=
3923 (prev
->gzip_disable_degradation
== 3) ?
3924 0 : prev
->gzip_disable_degradation
;
3930 #if (NGX_HAVE_OPENAT)
3931 ngx_conf_merge_uint_value(conf
->disable_symlinks
, prev
->disable_symlinks
,
3932 NGX_DISABLE_SYMLINKS_OFF
);
3933 ngx_conf_merge_ptr_value(conf
->disable_symlinks_from
,
3934 prev
->disable_symlinks_from
, NULL
);
3942 ngx_http_core_listen(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
3944 ngx_http_core_srv_conf_t
*cscf
= conf
;
3946 ngx_str_t
*value
, size
;
3949 ngx_http_listen_opt_t lsopt
;
3953 value
= cf
->args
->elts
;
3955 ngx_memzero(&u
, sizeof(ngx_url_t
));
3959 u
.default_port
= 80;
3961 if (ngx_parse_url(cf
->pool
, &u
) != NGX_OK
) {
3963 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
3964 "%s in \"%V\" of the \"listen\" directive",
3968 return NGX_CONF_ERROR
;
3971 ngx_memzero(&lsopt
, sizeof(ngx_http_listen_opt_t
));
3973 ngx_memcpy(&lsopt
.u
.sockaddr
, u
.sockaddr
, u
.socklen
);
3975 lsopt
.socklen
= u
.socklen
;
3976 lsopt
.backlog
= NGX_LISTEN_BACKLOG
;
3979 #if (NGX_HAVE_SETFIB)
3982 lsopt
.wildcard
= u
.wildcard
;
3983 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
3987 (void) ngx_sock_ntop(&lsopt
.u
.sockaddr
, lsopt
.addr
,
3988 NGX_SOCKADDR_STRLEN
, 1);
3990 for (n
= 2; n
< cf
->args
->nelts
; n
++) {
3992 if (ngx_strcmp(value
[n
].data
, "default_server") == 0
3993 || ngx_strcmp(value
[n
].data
, "default") == 0)
3995 lsopt
.default_server
= 1;
3999 if (ngx_strcmp(value
[n
].data
, "bind") == 0) {
4005 #if (NGX_HAVE_SETFIB)
4006 if (ngx_strncmp(value
[n
].data
, "setfib=", 7) == 0) {
4007 lsopt
.setfib
= ngx_atoi(value
[n
].data
+ 7, value
[n
].len
- 7);
4009 if (lsopt
.setfib
== NGX_ERROR
) {
4010 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4011 "invalid setfib \"%V\"", &value
[n
]);
4012 return NGX_CONF_ERROR
;
4018 if (ngx_strncmp(value
[n
].data
, "backlog=", 8) == 0) {
4019 lsopt
.backlog
= ngx_atoi(value
[n
].data
+ 8, value
[n
].len
- 8);
4023 if (lsopt
.backlog
== NGX_ERROR
|| lsopt
.backlog
== 0) {
4024 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4025 "invalid backlog \"%V\"", &value
[n
]);
4026 return NGX_CONF_ERROR
;
4032 if (ngx_strncmp(value
[n
].data
, "rcvbuf=", 7) == 0) {
4033 size
.len
= value
[n
].len
- 7;
4034 size
.data
= value
[n
].data
+ 7;
4036 lsopt
.rcvbuf
= ngx_parse_size(&size
);
4040 if (lsopt
.rcvbuf
== NGX_ERROR
) {
4041 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4042 "invalid rcvbuf \"%V\"", &value
[n
]);
4043 return NGX_CONF_ERROR
;
4049 if (ngx_strncmp(value
[n
].data
, "sndbuf=", 7) == 0) {
4050 size
.len
= value
[n
].len
- 7;
4051 size
.data
= value
[n
].data
+ 7;
4053 lsopt
.sndbuf
= ngx_parse_size(&size
);
4057 if (lsopt
.sndbuf
== NGX_ERROR
) {
4058 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4059 "invalid sndbuf \"%V\"", &value
[n
]);
4060 return NGX_CONF_ERROR
;
4066 if (ngx_strncmp(value
[n
].data
, "accept_filter=", 14) == 0) {
4067 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
4068 lsopt
.accept_filter
= (char *) &value
[n
].data
[14];
4072 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4073 "accept filters \"%V\" are not supported "
4074 "on this platform, ignored",
4080 if (ngx_strcmp(value
[n
].data
, "deferred") == 0) {
4081 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
4082 lsopt
.deferred_accept
= 1;
4086 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4087 "the deferred accept is not supported "
4088 "on this platform, ignored");
4093 if (ngx_strncmp(value
[n
].data
, "ipv6only=o", 10) == 0) {
4094 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
4095 struct sockaddr
*sa
;
4097 sa
= &lsopt
.u
.sockaddr
;
4099 if (sa
->sa_family
== AF_INET6
) {
4101 if (ngx_strcmp(&value
[n
].data
[10], "n") == 0) {
4104 } else if (ngx_strcmp(&value
[n
].data
[10], "ff") == 0) {
4108 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4109 "invalid ipv6only flags \"%s\"",
4111 return NGX_CONF_ERROR
;
4118 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4119 "ipv6only is not supported "
4120 "on addr \"%s\", ignored", lsopt
.addr
);
4125 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4126 "ipv6only is not supported "
4127 "on this platform");
4128 return NGX_CONF_ERROR
;
4132 if (ngx_strcmp(value
[n
].data
, "ssl") == 0) {
4137 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4138 "the \"ssl\" parameter requires "
4139 "ngx_http_ssl_module");
4140 return NGX_CONF_ERROR
;
4144 if (ngx_strcmp(value
[n
].data
, "spdy") == 0) {
4149 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4150 "the \"spdy\" parameter requires "
4151 "ngx_http_spdy_module");
4152 return NGX_CONF_ERROR
;
4156 if (ngx_strncmp(value
[n
].data
, "so_keepalive=", 13) == 0) {
4158 if (ngx_strcmp(&value
[n
].data
[13], "on") == 0) {
4159 lsopt
.so_keepalive
= 1;
4161 } else if (ngx_strcmp(&value
[n
].data
[13], "off") == 0) {
4162 lsopt
.so_keepalive
= 2;
4166 #if (NGX_HAVE_KEEPALIVE_TUNABLE)
4170 end
= value
[n
].data
+ value
[n
].len
;
4171 s
.data
= value
[n
].data
+ 13;
4173 p
= ngx_strlchr(s
.data
, end
, ':');
4181 lsopt
.tcp_keepidle
= ngx_parse_time(&s
, 1);
4182 if (lsopt
.tcp_keepidle
== (time_t) NGX_ERROR
) {
4183 goto invalid_so_keepalive
;
4187 s
.data
= (p
< end
) ? (p
+ 1) : end
;
4189 p
= ngx_strlchr(s
.data
, end
, ':');
4197 lsopt
.tcp_keepintvl
= ngx_parse_time(&s
, 1);
4198 if (lsopt
.tcp_keepintvl
== (time_t) NGX_ERROR
) {
4199 goto invalid_so_keepalive
;
4203 s
.data
= (p
< end
) ? (p
+ 1) : end
;
4206 s
.len
= end
- s
.data
;
4208 lsopt
.tcp_keepcnt
= ngx_atoi(s
.data
, s
.len
);
4209 if (lsopt
.tcp_keepcnt
== NGX_ERROR
) {
4210 goto invalid_so_keepalive
;
4214 if (lsopt
.tcp_keepidle
== 0 && lsopt
.tcp_keepintvl
== 0
4215 && lsopt
.tcp_keepcnt
== 0)
4217 goto invalid_so_keepalive
;
4220 lsopt
.so_keepalive
= 1;
4224 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4225 "the \"so_keepalive\" parameter accepts "
4226 "only \"on\" or \"off\" on this platform");
4227 return NGX_CONF_ERROR
;
4237 #if (NGX_HAVE_KEEPALIVE_TUNABLE)
4238 invalid_so_keepalive
:
4240 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4241 "invalid so_keepalive value: \"%s\"",
4242 &value
[n
].data
[13]);
4243 return NGX_CONF_ERROR
;
4247 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4248 "invalid parameter \"%V\"", &value
[n
]);
4249 return NGX_CONF_ERROR
;
4252 if (ngx_http_add_listen(cf
, cscf
, &lsopt
) == NGX_OK
) {
4256 return NGX_CONF_ERROR
;
4261 ngx_http_core_server_name(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
4263 ngx_http_core_srv_conf_t
*cscf
= conf
;
4268 ngx_http_server_name_t
*sn
;
4270 value
= cf
->args
->elts
;
4272 for (i
= 1; i
< cf
->args
->nelts
; i
++) {
4274 ch
= value
[i
].data
[0];
4276 if ((ch
== '*' && (value
[i
].len
< 3 || value
[i
].data
[1] != '.'))
4277 || (ch
== '.' && value
[i
].len
< 2))
4279 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4280 "server name \"%V\" is invalid", &value
[i
]);
4281 return NGX_CONF_ERROR
;
4284 if (ngx_strchr(value
[i
].data
, '/')) {
4285 ngx_conf_log_error(NGX_LOG_WARN
, cf
, 0,
4286 "server name \"%V\" has suspicious symbols",
4290 sn
= ngx_array_push(&cscf
->server_names
);
4292 return NGX_CONF_ERROR
;
4300 if (ngx_strcasecmp(value
[i
].data
, (u_char
*) "$hostname") == 0) {
4301 sn
->name
= cf
->cycle
->hostname
;
4304 sn
->name
= value
[i
];
4307 if (value
[i
].data
[0] != '~') {
4308 ngx_strlow(sn
->name
.data
, sn
->name
.data
, sn
->name
.len
);
4315 ngx_regex_compile_t rc
;
4316 u_char errstr
[NGX_MAX_CONF_ERRSTR
];
4318 if (value
[i
].len
== 1) {
4319 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4320 "empty regex in server name \"%V\"", &value
[i
]);
4321 return NGX_CONF_ERROR
;
4327 ngx_memzero(&rc
, sizeof(ngx_regex_compile_t
));
4329 rc
.pattern
= value
[i
];
4330 rc
.err
.len
= NGX_MAX_CONF_ERRSTR
;
4331 rc
.err
.data
= errstr
;
4333 for (p
= value
[i
].data
; p
< value
[i
].data
+ value
[i
].len
; p
++) {
4334 if (*p
>= 'A' && *p
<= 'Z') {
4335 rc
.options
= NGX_REGEX_CASELESS
;
4340 sn
->regex
= ngx_http_regex_compile(cf
, &rc
);
4341 if (sn
->regex
== NULL
) {
4342 return NGX_CONF_ERROR
;
4345 sn
->name
= value
[i
];
4346 cscf
->captures
= (rc
.captures
> 0);
4349 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4350 "using regex \"%V\" "
4351 "requires PCRE library", &value
[i
]);
4353 return NGX_CONF_ERROR
;
4362 ngx_http_core_root(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
4364 ngx_http_core_loc_conf_t
*clcf
= conf
;
4369 ngx_http_script_compile_t sc
;
4371 alias
= (cmd
->name
.len
== sizeof("alias") - 1) ? 1 : 0;
4373 if (clcf
->root
.data
) {
4375 if ((clcf
->alias
!= 0) == alias
) {
4376 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4377 "\"%V\" directive is duplicate",
4380 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4381 "\"%V\" directive is duplicate, "
4382 "\"%s\" directive was specified earlier",
4383 &cmd
->name
, clcf
->alias
? "alias" : "root");
4386 return NGX_CONF_ERROR
;
4389 if (clcf
->named
&& alias
) {
4390 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4391 "the \"alias\" directive cannot be used "
4392 "inside the named location");
4394 return NGX_CONF_ERROR
;
4397 value
= cf
->args
->elts
;
4399 if (ngx_strstr(value
[1].data
, "$document_root")
4400 || ngx_strstr(value
[1].data
, "${document_root}"))
4402 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4403 "the $document_root variable cannot be used "
4404 "in the \"%V\" directive",
4407 return NGX_CONF_ERROR
;
4410 if (ngx_strstr(value
[1].data
, "$realpath_root")
4411 || ngx_strstr(value
[1].data
, "${realpath_root}"))
4413 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4414 "the $realpath_root variable cannot be used "
4415 "in the \"%V\" directive",
4418 return NGX_CONF_ERROR
;
4421 clcf
->alias
= alias
? clcf
->name
.len
: 0;
4422 clcf
->root
= value
[1];
4424 if (!alias
&& clcf
->root
.data
[clcf
->root
.len
- 1] == '/') {
4428 if (clcf
->root
.data
[0] != '$') {
4429 if (ngx_conf_full_name(cf
->cycle
, &clcf
->root
, 0) != NGX_OK
) {
4430 return NGX_CONF_ERROR
;
4434 n
= ngx_http_script_variables_count(&clcf
->root
);
4436 ngx_memzero(&sc
, sizeof(ngx_http_script_compile_t
));
4440 if (alias
&& clcf
->regex
) {
4447 sc
.source
= &clcf
->root
;
4448 sc
.lengths
= &clcf
->root_lengths
;
4449 sc
.values
= &clcf
->root_values
;
4450 sc
.complete_lengths
= 1;
4451 sc
.complete_values
= 1;
4453 if (ngx_http_script_compile(&sc
) != NGX_OK
) {
4454 return NGX_CONF_ERROR
;
4462 static ngx_http_method_name_t ngx_methods_names
[] = {
4463 { (u_char
*) "GET", (uint32_t) ~NGX_HTTP_GET
},
4464 { (u_char
*) "HEAD", (uint32_t) ~NGX_HTTP_HEAD
},
4465 { (u_char
*) "POST", (uint32_t) ~NGX_HTTP_POST
},
4466 { (u_char
*) "PUT", (uint32_t) ~NGX_HTTP_PUT
},
4467 { (u_char
*) "DELETE", (uint32_t) ~NGX_HTTP_DELETE
},
4468 { (u_char
*) "MKCOL", (uint32_t) ~NGX_HTTP_MKCOL
},
4469 { (u_char
*) "COPY", (uint32_t) ~NGX_HTTP_COPY
},
4470 { (u_char
*) "MOVE", (uint32_t) ~NGX_HTTP_MOVE
},
4471 { (u_char
*) "OPTIONS", (uint32_t) ~NGX_HTTP_OPTIONS
},
4472 { (u_char
*) "PROPFIND" , (uint32_t) ~NGX_HTTP_PROPFIND
},
4473 { (u_char
*) "PROPPATCH", (uint32_t) ~NGX_HTTP_PROPPATCH
},
4474 { (u_char
*) "LOCK", (uint32_t) ~NGX_HTTP_LOCK
},
4475 { (u_char
*) "UNLOCK", (uint32_t) ~NGX_HTTP_UNLOCK
},
4476 { (u_char
*) "PATCH", (uint32_t) ~NGX_HTTP_PATCH
},
4482 ngx_http_core_limit_except(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
4484 ngx_http_core_loc_conf_t
*pclcf
= conf
;
4491 ngx_http_module_t
*module
;
4492 ngx_http_conf_ctx_t
*ctx
, *pctx
;
4493 ngx_http_method_name_t
*name
;
4494 ngx_http_core_loc_conf_t
*clcf
;
4496 if (pclcf
->limit_except
) {
4500 pclcf
->limit_except
= 0xffffffff;
4502 value
= cf
->args
->elts
;
4504 for (i
= 1; i
< cf
->args
->nelts
; i
++) {
4505 for (name
= ngx_methods_names
; name
->name
; name
++) {
4507 if (ngx_strcasecmp(value
[i
].data
, name
->name
) == 0) {
4508 pclcf
->limit_except
&= name
->method
;
4513 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4514 "invalid method \"%V\"", &value
[i
]);
4515 return NGX_CONF_ERROR
;
4521 if (!(pclcf
->limit_except
& NGX_HTTP_GET
)) {
4522 pclcf
->limit_except
&= (uint32_t) ~NGX_HTTP_HEAD
;
4525 ctx
= ngx_pcalloc(cf
->pool
, sizeof(ngx_http_conf_ctx_t
));
4527 return NGX_CONF_ERROR
;
4531 ctx
->main_conf
= pctx
->main_conf
;
4532 ctx
->srv_conf
= pctx
->srv_conf
;
4534 ctx
->loc_conf
= ngx_pcalloc(cf
->pool
, sizeof(void *) * ngx_http_max_module
);
4535 if (ctx
->loc_conf
== NULL
) {
4536 return NGX_CONF_ERROR
;
4539 for (i
= 0; ngx_modules
[i
]; i
++) {
4540 if (ngx_modules
[i
]->type
!= NGX_HTTP_MODULE
) {
4544 module
= ngx_modules
[i
]->ctx
;
4546 if (module
->create_loc_conf
) {
4548 mconf
= module
->create_loc_conf(cf
);
4549 if (mconf
== NULL
) {
4550 return NGX_CONF_ERROR
;
4553 ctx
->loc_conf
[ngx_modules
[i
]->ctx_index
] = mconf
;
4558 clcf
= ctx
->loc_conf
[ngx_http_core_module
.ctx_index
];
4559 pclcf
->limit_except_loc_conf
= ctx
->loc_conf
;
4560 clcf
->loc_conf
= ctx
->loc_conf
;
4561 clcf
->name
= pclcf
->name
;
4563 clcf
->lmt_excpt
= 1;
4565 if (ngx_http_add_location(cf
, &pclcf
->locations
, clcf
) != NGX_OK
) {
4566 return NGX_CONF_ERROR
;
4571 cf
->cmd_type
= NGX_HTTP_LMT_CONF
;
4573 rv
= ngx_conf_parse(cf
, NULL
);
4582 ngx_http_core_directio(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
4584 ngx_http_core_loc_conf_t
*clcf
= conf
;
4588 if (clcf
->directio
!= NGX_CONF_UNSET
) {
4589 return "is duplicate";
4592 value
= cf
->args
->elts
;
4594 if (ngx_strcmp(value
[1].data
, "off") == 0) {
4595 clcf
->directio
= NGX_OPEN_FILE_DIRECTIO_OFF
;
4599 clcf
->directio
= ngx_parse_offset(&value
[1]);
4600 if (clcf
->directio
== (off_t
) NGX_ERROR
) {
4601 return "invalid value";
4609 ngx_http_core_error_page(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
4611 ngx_http_core_loc_conf_t
*clcf
= conf
;
4614 ngx_int_t overwrite
;
4615 ngx_str_t
*value
, uri
, args
;
4617 ngx_http_err_page_t
*err
;
4618 ngx_http_complex_value_t cv
;
4619 ngx_http_compile_complex_value_t ccv
;
4621 if (clcf
->error_pages
== NULL
) {
4622 clcf
->error_pages
= ngx_array_create(cf
->pool
, 4,
4623 sizeof(ngx_http_err_page_t
));
4624 if (clcf
->error_pages
== NULL
) {
4625 return NGX_CONF_ERROR
;
4629 value
= cf
->args
->elts
;
4631 i
= cf
->args
->nelts
- 2;
4633 if (value
[i
].data
[0] == '=') {
4635 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4636 "invalid value \"%V\"", &value
[i
]);
4637 return NGX_CONF_ERROR
;
4640 if (value
[i
].len
> 1) {
4641 overwrite
= ngx_atoi(&value
[i
].data
[1], value
[i
].len
- 1);
4643 if (overwrite
== NGX_ERROR
) {
4644 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4645 "invalid value \"%V\"", &value
[i
]);
4646 return NGX_CONF_ERROR
;
4660 uri
= value
[cf
->args
->nelts
- 1];
4662 ngx_memzero(&ccv
, sizeof(ngx_http_compile_complex_value_t
));
4666 ccv
.complex_value
= &cv
;
4668 if (ngx_http_compile_complex_value(&ccv
) != NGX_OK
) {
4669 return NGX_CONF_ERROR
;
4672 ngx_str_null(&args
);
4674 if (cv
.lengths
== NULL
&& uri
.len
&& uri
.data
[0] == '/') {
4675 p
= (u_char
*) ngx_strchr(uri
.data
, '?');
4678 cv
.value
.len
= p
- uri
.data
;
4679 cv
.value
.data
= uri
.data
;
4681 args
.len
= (uri
.data
+ uri
.len
) - p
;
4686 for (i
= 1; i
< cf
->args
->nelts
- n
; i
++) {
4687 err
= ngx_array_push(clcf
->error_pages
);
4689 return NGX_CONF_ERROR
;
4692 err
->status
= ngx_atoi(value
[i
].data
, value
[i
].len
);
4694 if (err
->status
== NGX_ERROR
|| err
->status
== 499) {
4695 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4696 "invalid value \"%V\"", &value
[i
]);
4697 return NGX_CONF_ERROR
;
4700 if (err
->status
< 300 || err
->status
> 599) {
4701 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4702 "value \"%V\" must be between 300 and 599",
4704 return NGX_CONF_ERROR
;
4707 err
->overwrite
= overwrite
;
4709 if (overwrite
== -1) {
4710 switch (err
->status
) {
4711 case NGX_HTTP_TO_HTTPS
:
4712 case NGX_HTTPS_CERT_ERROR
:
4713 case NGX_HTTPS_NO_CERT
:
4714 err
->overwrite
= NGX_HTTP_BAD_REQUEST
;
4729 ngx_http_core_try_files(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
4731 ngx_http_core_loc_conf_t
*clcf
= conf
;
4736 ngx_http_try_file_t
*tf
;
4737 ngx_http_script_compile_t sc
;
4738 ngx_http_core_main_conf_t
*cmcf
;
4740 if (clcf
->try_files
) {
4741 return "is duplicate";
4744 cmcf
= ngx_http_conf_get_module_main_conf(cf
, ngx_http_core_module
);
4746 cmcf
->try_files
= 1;
4748 tf
= ngx_pcalloc(cf
->pool
, cf
->args
->nelts
* sizeof(ngx_http_try_file_t
));
4750 return NGX_CONF_ERROR
;
4753 clcf
->try_files
= tf
;
4755 value
= cf
->args
->elts
;
4757 for (i
= 0; i
< cf
->args
->nelts
- 1; i
++) {
4759 tf
[i
].name
= value
[i
+ 1];
4761 if (tf
[i
].name
.data
[tf
[i
].name
.len
- 1] == '/') {
4764 tf
[i
].name
.data
[tf
[i
].name
.len
] = '\0';
4767 n
= ngx_http_script_variables_count(&tf
[i
].name
);
4770 ngx_memzero(&sc
, sizeof(ngx_http_script_compile_t
));
4773 sc
.source
= &tf
[i
].name
;
4774 sc
.lengths
= &tf
[i
].lengths
;
4775 sc
.values
= &tf
[i
].values
;
4777 sc
.complete_lengths
= 1;
4778 sc
.complete_values
= 1;
4780 if (ngx_http_script_compile(&sc
) != NGX_OK
) {
4781 return NGX_CONF_ERROR
;
4785 /* add trailing '\0' to length */
4790 if (tf
[i
- 1].name
.data
[0] == '=') {
4792 code
= ngx_atoi(tf
[i
- 1].name
.data
+ 1, tf
[i
- 1].name
.len
- 2);
4794 if (code
== NGX_ERROR
|| code
> 999) {
4795 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4796 "invalid code \"%*s\"",
4797 tf
[i
- 1].name
.len
- 1, tf
[i
- 1].name
.data
);
4798 return NGX_CONF_ERROR
;
4809 ngx_http_core_open_file_cache(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
4811 ngx_http_core_loc_conf_t
*clcf
= conf
;
4814 ngx_str_t
*value
, s
;
4818 if (clcf
->open_file_cache
!= NGX_CONF_UNSET_PTR
) {
4819 return "is duplicate";
4822 value
= cf
->args
->elts
;
4827 for (i
= 1; i
< cf
->args
->nelts
; i
++) {
4829 if (ngx_strncmp(value
[i
].data
, "max=", 4) == 0) {
4831 max
= ngx_atoi(value
[i
].data
+ 4, value
[i
].len
- 4);
4839 if (ngx_strncmp(value
[i
].data
, "inactive=", 9) == 0) {
4841 s
.len
= value
[i
].len
- 9;
4842 s
.data
= value
[i
].data
+ 9;
4844 inactive
= ngx_parse_time(&s
, 1);
4845 if (inactive
== (time_t) NGX_ERROR
) {
4852 if (ngx_strcmp(value
[i
].data
, "off") == 0) {
4854 clcf
->open_file_cache
= NULL
;
4861 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4862 "invalid \"open_file_cache\" parameter \"%V\"",
4864 return NGX_CONF_ERROR
;
4867 if (clcf
->open_file_cache
== NULL
) {
4872 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
4873 "\"open_file_cache\" must have the \"max\" parameter");
4874 return NGX_CONF_ERROR
;
4877 clcf
->open_file_cache
= ngx_open_file_cache_init(cf
->pool
, max
, inactive
);
4878 if (clcf
->open_file_cache
) {
4882 return NGX_CONF_ERROR
;
4887 ngx_http_core_error_log(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
4889 ngx_http_core_loc_conf_t
*clcf
= conf
;
4891 ngx_str_t
*value
, name
;
4893 if (clcf
->error_log
) {
4894 return "is duplicate";
4897 value
= cf
->args
->elts
;
4899 if (ngx_strcmp(value
[1].data
, "stderr") == 0) {
4900 ngx_str_null(&name
);
4906 clcf
->error_log
= ngx_log_create(cf
->cycle
, &name
);
4907 if (clcf
->error_log
== NULL
) {
4908 return NGX_CONF_ERROR
;
4911 if (cf
->args
->nelts
== 2) {
4912 clcf
->error_log
->log_level
= NGX_LOG_ERR
;
4916 return ngx_log_set_levels(cf
, clcf
->error_log
);
4921 ngx_http_core_keepalive(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
4923 ngx_http_core_loc_conf_t
*clcf
= conf
;
4927 if (clcf
->keepalive_timeout
!= NGX_CONF_UNSET_MSEC
) {
4928 return "is duplicate";
4931 value
= cf
->args
->elts
;
4933 clcf
->keepalive_timeout
= ngx_parse_time(&value
[1], 0);
4935 if (clcf
->keepalive_timeout
== (ngx_msec_t
) NGX_ERROR
) {
4936 return "invalid value";
4939 if (cf
->args
->nelts
== 2) {
4943 clcf
->keepalive_header
= ngx_parse_time(&value
[2], 1);
4945 if (clcf
->keepalive_header
== (time_t) NGX_ERROR
) {
4946 return "invalid value";
4954 ngx_http_core_internal(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
4956 ngx_http_core_loc_conf_t
*clcf
= conf
;
4958 if (clcf
->internal
!= NGX_CONF_UNSET
) {
4959 return "is duplicate";
4969 ngx_http_core_resolver(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
4971 ngx_http_core_loc_conf_t
*clcf
= conf
;
4975 if (clcf
->resolver
) {
4976 return "is duplicate";
4979 value
= cf
->args
->elts
;
4981 clcf
->resolver
= ngx_resolver_create(cf
, &value
[1], cf
->args
->nelts
- 1);
4982 if (clcf
->resolver
== NULL
) {
4983 return NGX_CONF_ERROR
;
4993 ngx_http_gzip_disable(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
4995 ngx_http_core_loc_conf_t
*clcf
= conf
;
5001 ngx_regex_elt_t
*re
;
5002 ngx_regex_compile_t rc
;
5003 u_char errstr
[NGX_MAX_CONF_ERRSTR
];
5005 if (clcf
->gzip_disable
== NGX_CONF_UNSET_PTR
) {
5006 clcf
->gzip_disable
= ngx_array_create(cf
->pool
, 2,
5007 sizeof(ngx_regex_elt_t
));
5008 if (clcf
->gzip_disable
== NULL
) {
5009 return NGX_CONF_ERROR
;
5013 value
= cf
->args
->elts
;
5015 ngx_memzero(&rc
, sizeof(ngx_regex_compile_t
));
5018 rc
.err
.len
= NGX_MAX_CONF_ERRSTR
;
5019 rc
.err
.data
= errstr
;
5021 for (i
= 1; i
< cf
->args
->nelts
; i
++) {
5023 if (ngx_strcmp(value
[i
].data
, "msie6") == 0) {
5024 clcf
->gzip_disable_msie6
= 1;
5028 #if (NGX_HTTP_DEGRADATION)
5030 if (ngx_strcmp(value
[i
].data
, "degradation") == 0) {
5031 clcf
->gzip_disable_degradation
= 1;
5037 re
= ngx_array_push(clcf
->gzip_disable
);
5039 return NGX_CONF_ERROR
;
5042 rc
.pattern
= value
[i
];
5043 rc
.options
= NGX_REGEX_CASELESS
;
5045 if (ngx_regex_compile(&rc
) != NGX_OK
) {
5046 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0, "%V", &rc
.err
);
5047 return NGX_CONF_ERROR
;
5050 re
->regex
= rc
.regex
;
5051 re
->name
= value
[i
].data
;
5060 value
= cf
->args
->elts
;
5062 for (i
= 1; i
< cf
->args
->nelts
; i
++) {
5063 if (ngx_strcmp(value
[i
].data
, "msie6") == 0) {
5064 clcf
->gzip_disable_msie6
= 1;
5068 #if (NGX_HTTP_DEGRADATION)
5070 if (ngx_strcmp(value
[i
].data
, "degradation") == 0) {
5071 clcf
->gzip_disable_degradation
= 1;
5077 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
5078 "without PCRE library \"gzip_disable\" supports "
5079 "builtin \"msie6\" and \"degradation\" mask only");
5081 return NGX_CONF_ERROR
;
5092 #if (NGX_HAVE_OPENAT)
5095 ngx_http_disable_symlinks(ngx_conf_t
*cf
, ngx_command_t
*cmd
, void *conf
)
5097 ngx_http_core_loc_conf_t
*clcf
= conf
;
5101 ngx_http_compile_complex_value_t ccv
;
5103 if (clcf
->disable_symlinks
!= NGX_CONF_UNSET_UINT
) {
5104 return "is duplicate";
5107 value
= cf
->args
->elts
;
5109 for (i
= 1; i
< cf
->args
->nelts
; i
++) {
5111 if (ngx_strcmp(value
[i
].data
, "off") == 0) {
5112 clcf
->disable_symlinks
= NGX_DISABLE_SYMLINKS_OFF
;
5116 if (ngx_strcmp(value
[i
].data
, "if_not_owner") == 0) {
5117 clcf
->disable_symlinks
= NGX_DISABLE_SYMLINKS_NOTOWNER
;
5121 if (ngx_strcmp(value
[i
].data
, "on") == 0) {
5122 clcf
->disable_symlinks
= NGX_DISABLE_SYMLINKS_ON
;
5126 if (ngx_strncmp(value
[i
].data
, "from=", 5) == 0) {
5130 ngx_memzero(&ccv
, sizeof(ngx_http_compile_complex_value_t
));
5133 ccv
.value
= &value
[i
];
5134 ccv
.complex_value
= ngx_palloc(cf
->pool
,
5135 sizeof(ngx_http_complex_value_t
));
5136 if (ccv
.complex_value
== NULL
) {
5137 return NGX_CONF_ERROR
;
5140 if (ngx_http_compile_complex_value(&ccv
) != NGX_OK
) {
5141 return NGX_CONF_ERROR
;
5144 clcf
->disable_symlinks_from
= ccv
.complex_value
;
5149 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
5150 "invalid parameter \"%V\"", &value
[i
]);
5151 return NGX_CONF_ERROR
;
5154 if (clcf
->disable_symlinks
== NGX_CONF_UNSET_UINT
) {
5155 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
5156 "\"%V\" must have \"off\", \"on\" "
5157 "or \"if_not_owner\" parameter",
5159 return NGX_CONF_ERROR
;
5162 if (cf
->args
->nelts
== 2) {
5163 clcf
->disable_symlinks_from
= NULL
;
5167 if (clcf
->disable_symlinks_from
== NGX_CONF_UNSET_PTR
) {
5168 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
5169 "duplicate parameters \"%V %V\"",
5170 &value
[1], &value
[2]);
5171 return NGX_CONF_ERROR
;
5174 if (clcf
->disable_symlinks
== NGX_DISABLE_SYMLINKS_OFF
) {
5175 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
5176 "\"from=\" cannot be used with \"off\" parameter");
5177 return NGX_CONF_ERROR
;
5187 ngx_http_core_lowat_check(ngx_conf_t
*cf
, void *post
, void *data
)
5192 if ((u_long
) *np
>= ngx_freebsd_net_inet_tcp_sendspace
) {
5193 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
5194 "\"send_lowat\" must be less than %d "
5195 "(sysctl net.inet.tcp.sendspace)",
5196 ngx_freebsd_net_inet_tcp_sendspace
);
5198 return NGX_CONF_ERROR
;
5201 #elif !(NGX_HAVE_SO_SNDLOWAT)
5204 ngx_conf_log_error(NGX_LOG_WARN
, cf
, 0,
5205 "\"send_lowat\" is not supported, ignored");
5216 ngx_http_core_pool_size(ngx_conf_t
*cf
, void *post
, void *data
)
5220 if (*sp
< NGX_MIN_POOL_SIZE
) {
5221 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
5222 "the pool size must be no less than %uz",
5224 return NGX_CONF_ERROR
;
5227 if (*sp
% NGX_POOL_ALIGNMENT
) {
5228 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
5229 "the pool size must be a multiple of %uz",
5230 NGX_POOL_ALIGNMENT
);
5231 return NGX_CONF_ERROR
;