blob: eb4934e8e5d437fa68e4b9258cf41aa16a5eebbc [file] [log] [blame]
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001
Igor Sysoevd90282d2004-09-28 08:34:51 +00002/*
Igor Sysoevff8da912004-09-29 16:00:49 +00003 * Copyright (C) Igor Sysoev
Igor Sysoevd90282d2004-09-28 08:34:51 +00004 */
5
6
Igor Sysoev4e9393a2003-01-09 05:36:00 +00007#include <ngx_config.h>
Igor Sysoev4e9393a2003-01-09 05:36:00 +00008#include <ngx_core.h>
Igor Sysoevb3e73d82003-10-10 15:10:50 +00009#include <ngx_event.h>
Igor Sysoev6253ca12003-05-27 12:18:54 +000010#include <ngx_http.h>
Igor Sysoeva9830112003-05-19 16:39:14 +000011#include <nginx.h>
Igor Sysoev4e9393a2003-01-09 05:36:00 +000012
Igor Sysoev1b735832004-11-11 14:07:14 +000013
Igor Sysoev94e32ce2006-04-07 14:08:04 +000014typedef struct {
15 char *name;
16 uint32_t method;
17} ngx_http_method_name_t;
18
19
Igor Sysoev74a5ddb2004-07-18 19:11:20 +000020#define NGX_HTTP_LOCATION_EXACT 1
21#define NGX_HTTP_LOCATION_AUTO_REDIRECT 2
Igor Sysoevd43bee82004-11-20 19:52:20 +000022#define NGX_HTTP_LOCATION_NOREGEX 3
23#define NGX_HTTP_LOCATION_REGEX 4
Igor Sysoev74a5ddb2004-07-18 19:11:20 +000024
Igor Sysoev6253ca12003-05-27 12:18:54 +000025
Igor Sysoev805d9db2005-02-03 19:33:37 +000026static void ngx_http_core_run_phases(ngx_http_request_t *r);
27static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r,
Igor Sysoevaa828612005-02-09 14:31:07 +000028 ngx_array_t *locations, size_t len);
Igor Sysoev4e9393a2003-01-09 05:36:00 +000029
Igor Sysoev899b44e2005-05-12 14:58:06 +000030static ngx_int_t ngx_http_core_preconfiguration(ngx_conf_t *cf);
Igor Sysoev890fc962003-07-20 21:15:59 +000031static void *ngx_http_core_create_main_conf(ngx_conf_t *cf);
32static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf);
33static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf);
34static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
Igor Sysoevaa828612005-02-09 14:31:07 +000035 void *parent, void *child);
Igor Sysoev890fc962003-07-20 21:15:59 +000036static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf);
37static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
Igor Sysoevaa828612005-02-09 14:31:07 +000038 void *parent, void *child);
Igor Sysoevdc479b42003-03-20 16:09:44 +000039
Igor Sysoev805d9db2005-02-03 19:33:37 +000040static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000041 void *dummy);
Igor Sysoev805d9db2005-02-03 19:33:37 +000042static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000043 void *dummy);
Igor Sysoev4d656dc2005-03-22 16:02:46 +000044static int ngx_libc_cdecl ngx_http_core_cmp_locations(const void *first,
45 const void *second);
Igor Sysoev805d9db2005-02-03 19:33:37 +000046
47static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000048 void *conf);
Igor Sysoev805d9db2005-02-03 19:33:37 +000049static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy,
Igor Sysoevaa828612005-02-09 14:31:07 +000050 void *conf);
Igor Sysoev4e9393a2003-01-09 05:36:00 +000051
Igor Sysoev805d9db2005-02-03 19:33:37 +000052static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000053 void *conf);
Igor Sysoev805d9db2005-02-03 19:33:37 +000054static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000055 void *conf);
Igor Sysoev805d9db2005-02-03 19:33:37 +000056static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
Igor Sysoev94e32ce2006-04-07 14:08:04 +000057static char *ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd,
58 void *conf);
Igor Sysoev805d9db2005-02-03 19:33:37 +000059static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000060 void *conf);
Igor Sysoev805d9db2005-02-03 19:33:37 +000061static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000062 void *conf);
Igor Sysoev805d9db2005-02-03 19:33:37 +000063static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000064 void *conf);
Igor Sysoev899b44e2005-05-12 14:58:06 +000065static char *ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd,
66 void *conf);
Igor Sysoevb5faed22003-10-29 08:30:44 +000067
Igor Sysoev805d9db2005-02-03 19:33:37 +000068static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data);
69
70static ngx_conf_post_t ngx_http_core_lowat_post =
71 { ngx_http_core_lowat_check };
Igor Sysoevb5faed22003-10-29 08:30:44 +000072
Igor Sysoev8290d282006-02-03 12:58:48 +000073static ngx_conf_deprecated_t ngx_conf_deprecated_optimize_host_names = {
74 ngx_conf_deprecated, "optimize_host_names", "optimize_server_names"
75};
76
Igor Sysoev4e9393a2003-01-09 05:36:00 +000077
78static ngx_command_t ngx_http_core_commands[] = {
79
Igor Sysoevffe71442006-02-08 15:33:12 +000080 { ngx_string("variables_hash_max_size"),
81 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
82 ngx_conf_set_num_slot,
83 NGX_HTTP_MAIN_CONF_OFFSET,
84 offsetof(ngx_http_core_main_conf_t, variables_hash_max_size),
85 NULL },
86
87 { ngx_string("variables_hash_bucket_size"),
88 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
89 ngx_conf_set_num_slot,
90 NGX_HTTP_MAIN_CONF_OFFSET,
91 offsetof(ngx_http_core_main_conf_t, variables_hash_bucket_size),
92 NULL },
93
Igor Sysoev305a9d82005-12-26 17:07:48 +000094 { ngx_string("server_names_hash_max_size"),
Igor Sysoevb1dfe472004-12-21 12:30:30 +000095 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
96 ngx_conf_set_num_slot,
97 NGX_HTTP_MAIN_CONF_OFFSET,
Igor Sysoev305a9d82005-12-26 17:07:48 +000098 offsetof(ngx_http_core_main_conf_t, server_names_hash_max_size),
Igor Sysoevb1dfe472004-12-21 12:30:30 +000099 NULL },
100
Igor Sysoev305a9d82005-12-26 17:07:48 +0000101 { ngx_string("server_names_hash_bucket_size"),
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000102 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
103 ngx_conf_set_num_slot,
104 NGX_HTTP_MAIN_CONF_OFFSET,
Igor Sysoev305a9d82005-12-26 17:07:48 +0000105 offsetof(ngx_http_core_main_conf_t, server_names_hash_bucket_size),
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000106 NULL },
107
Igor Sysoev865c1502003-11-30 20:03:18 +0000108 { ngx_string("server"),
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000109 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_MULTI|NGX_CONF_NOARGS,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000110 ngx_http_core_server,
Igor Sysoev865c1502003-11-30 20:03:18 +0000111 0,
112 0,
113 NULL },
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000114
Igor Sysoev865c1502003-11-30 20:03:18 +0000115 { ngx_string("connection_pool_size"),
116 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
117 ngx_conf_set_size_slot,
118 NGX_HTTP_SRV_CONF_OFFSET,
119 offsetof(ngx_http_core_srv_conf_t, connection_pool_size),
120 NULL },
Igor Sysoev6a644c62003-03-04 06:33:48 +0000121
Igor Sysoev865c1502003-11-30 20:03:18 +0000122 { ngx_string("request_pool_size"),
123 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
124 ngx_conf_set_size_slot,
125 NGX_HTTP_SRV_CONF_OFFSET,
126 offsetof(ngx_http_core_srv_conf_t, request_pool_size),
127 NULL },
Igor Sysoev187fcd82003-05-23 11:53:01 +0000128
Igor Sysoev865c1502003-11-30 20:03:18 +0000129 { ngx_string("client_header_timeout"),
130 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
131 ngx_conf_set_msec_slot,
132 NGX_HTTP_SRV_CONF_OFFSET,
133 offsetof(ngx_http_core_srv_conf_t, client_header_timeout),
134 NULL },
Igor Sysoev6a644c62003-03-04 06:33:48 +0000135
Igor Sysoev865c1502003-11-30 20:03:18 +0000136 { ngx_string("client_header_buffer_size"),
137 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
138 ngx_conf_set_size_slot,
139 NGX_HTTP_SRV_CONF_OFFSET,
140 offsetof(ngx_http_core_srv_conf_t, client_header_buffer_size),
141 NULL },
Igor Sysoev6a644c62003-03-04 06:33:48 +0000142
Igor Sysoevf7abd722004-09-23 06:32:00 +0000143 { ngx_string("large_client_header_buffers"),
Igor Sysoev85080d02004-09-22 16:18:21 +0000144 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE2,
145 ngx_conf_set_bufs_slot,
146 NGX_HTTP_SRV_CONF_OFFSET,
Igor Sysoevf7abd722004-09-23 06:32:00 +0000147 offsetof(ngx_http_core_srv_conf_t, large_client_header_buffers),
Igor Sysoev865c1502003-11-30 20:03:18 +0000148 NULL },
Igor Sysoev6a644c62003-03-04 06:33:48 +0000149
Igor Sysoev8290d282006-02-03 12:58:48 +0000150 { ngx_string("optimize_server_names"),
151 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
152 ngx_conf_set_flag_slot,
153 NGX_HTTP_SRV_CONF_OFFSET,
154 offsetof(ngx_http_core_srv_conf_t, optimize_server_names),
155 NULL },
156
Igor Sysoev34303462006-01-24 16:08:27 +0000157 { ngx_string("optimize_host_names"),
158 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
159 ngx_conf_set_flag_slot,
160 NGX_HTTP_SRV_CONF_OFFSET,
Igor Sysoev8290d282006-02-03 12:58:48 +0000161 offsetof(ngx_http_core_srv_conf_t, optimize_server_names),
162 &ngx_conf_deprecated_optimize_host_names },
Igor Sysoev34303462006-01-24 16:08:27 +0000163
Igor Sysoev3362b8d2005-05-14 18:42:03 +0000164 { ngx_string("ignore_invalid_headers"),
165 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
166 ngx_conf_set_flag_slot,
167 NGX_HTTP_SRV_CONF_OFFSET,
168 offsetof(ngx_http_core_srv_conf_t, ignore_invalid_headers),
169 NULL },
170
Igor Sysoev865c1502003-11-30 20:03:18 +0000171 { ngx_string("location"),
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000172 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000173 ngx_http_core_location,
Igor Sysoev865c1502003-11-30 20:03:18 +0000174 NGX_HTTP_SRV_CONF_OFFSET,
175 0,
176 NULL },
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000177
Igor Sysoev865c1502003-11-30 20:03:18 +0000178 { ngx_string("listen"),
Igor Sysoevb145b062005-06-15 18:33:41 +0000179 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000180 ngx_http_core_listen,
Igor Sysoev865c1502003-11-30 20:03:18 +0000181 NGX_HTTP_SRV_CONF_OFFSET,
182 0,
183 NULL },
Igor Sysoeva19a85e2003-01-28 15:56:37 +0000184
Igor Sysoev865c1502003-11-30 20:03:18 +0000185 { ngx_string("server_name"),
186 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000187 ngx_http_core_server_name,
Igor Sysoev865c1502003-11-30 20:03:18 +0000188 NGX_HTTP_SRV_CONF_OFFSET,
189 0,
190 NULL },
Igor Sysoev13933252003-05-29 13:02:09 +0000191
Igor Sysoev24025022005-12-16 15:07:08 +0000192 { ngx_string("types_hash_max_size"),
193 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
194 ngx_conf_set_num_slot,
195 NGX_HTTP_LOC_CONF_OFFSET,
196 offsetof(ngx_http_core_loc_conf_t, types_hash_max_size),
197 NULL },
198
199 { ngx_string("types_hash_bucket_size"),
200 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
201 ngx_conf_set_num_slot,
202 NGX_HTTP_LOC_CONF_OFFSET,
203 offsetof(ngx_http_core_loc_conf_t, types_hash_bucket_size),
204 NULL },
205
Igor Sysoev865c1502003-11-30 20:03:18 +0000206 { ngx_string("types"),
207 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF
208 |NGX_CONF_BLOCK|NGX_CONF_NOARGS,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000209 ngx_http_core_types,
Igor Sysoev865c1502003-11-30 20:03:18 +0000210 NGX_HTTP_LOC_CONF_OFFSET,
211 0,
212 NULL },
Igor Sysoev79a80482003-05-14 17:13:13 +0000213
Igor Sysoev865c1502003-11-30 20:03:18 +0000214 { ngx_string("default_type"),
215 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
216 ngx_conf_set_str_slot,
217 NGX_HTTP_LOC_CONF_OFFSET,
218 offsetof(ngx_http_core_loc_conf_t, default_type),
219 NULL },
Igor Sysoev6253ca12003-05-27 12:18:54 +0000220
Igor Sysoev865c1502003-11-30 20:03:18 +0000221 { ngx_string("root"),
Igor Sysoev899b44e2005-05-12 14:58:06 +0000222 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
223 |NGX_CONF_TAKE1,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000224 ngx_http_core_root,
Igor Sysoev865c1502003-11-30 20:03:18 +0000225 NGX_HTTP_LOC_CONF_OFFSET,
Igor Sysoev10a543a2004-03-16 07:10:12 +0000226 0,
227 NULL },
228
229 { ngx_string("alias"),
230 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000231 ngx_http_core_root,
Igor Sysoev10a543a2004-03-16 07:10:12 +0000232 NGX_HTTP_LOC_CONF_OFFSET,
233 0,
Igor Sysoev865c1502003-11-30 20:03:18 +0000234 NULL },
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000235
Igor Sysoev94e32ce2006-04-07 14:08:04 +0000236 { ngx_string("limit_except"),
237 NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_1MORE,
238 ngx_http_core_limit_except,
239 NGX_HTTP_LOC_CONF_OFFSET,
240 0,
241 NULL },
242
Igor Sysoevae02c192004-03-19 05:25:53 +0000243 { ngx_string("client_max_body_size"),
244 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
Igor Sysoev1765f472006-07-07 16:33:19 +0000245 ngx_conf_set_off_slot,
Igor Sysoevae02c192004-03-19 05:25:53 +0000246 NGX_HTTP_LOC_CONF_OFFSET,
247 offsetof(ngx_http_core_loc_conf_t, client_max_body_size),
248 NULL },
249
Igor Sysoevdbb27762004-04-01 16:20:53 +0000250 { ngx_string("client_body_buffer_size"),
251 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
252 ngx_conf_set_size_slot,
253 NGX_HTTP_LOC_CONF_OFFSET,
254 offsetof(ngx_http_core_loc_conf_t, client_body_buffer_size),
255 NULL },
256
Igor Sysoev865c1502003-11-30 20:03:18 +0000257 { ngx_string("client_body_timeout"),
258 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
259 ngx_conf_set_msec_slot,
260 NGX_HTTP_LOC_CONF_OFFSET,
261 offsetof(ngx_http_core_loc_conf_t, client_body_timeout),
262 NULL },
Igor Sysoev2b0c76c2003-10-27 21:01:00 +0000263
Igor Sysoev02025fd2005-01-18 13:03:58 +0000264 { ngx_string("client_body_temp_path"),
265 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
266 ngx_conf_set_path_slot,
267 NGX_HTTP_LOC_CONF_OFFSET,
268 offsetof(ngx_http_core_loc_conf_t, client_body_temp_path),
269 (void *) ngx_garbage_collector_temp_handler },
270
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +0000271 { ngx_string("client_body_in_file_only"),
272 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
273 ngx_conf_set_flag_slot,
274 NGX_HTTP_LOC_CONF_OFFSET,
275 offsetof(ngx_http_core_loc_conf_t, client_body_in_file_only),
276 NULL },
277
Igor Sysoev865c1502003-11-30 20:03:18 +0000278 { ngx_string("sendfile"),
279 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
280 ngx_conf_set_flag_slot,
281 NGX_HTTP_LOC_CONF_OFFSET,
282 offsetof(ngx_http_core_loc_conf_t, sendfile),
283 NULL },
Igor Sysoev5bf3d252003-10-22 07:05:29 +0000284
Igor Sysoev3c3ca172004-01-05 20:55:48 +0000285 { ngx_string("tcp_nopush"),
286 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
287 ngx_conf_set_flag_slot,
288 NGX_HTTP_LOC_CONF_OFFSET,
289 offsetof(ngx_http_core_loc_conf_t, tcp_nopush),
290 NULL },
291
Igor Sysoev924bd792004-10-11 15:07:03 +0000292 { ngx_string("tcp_nodelay"),
293 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
294 ngx_conf_set_flag_slot,
295 NGX_HTTP_LOC_CONF_OFFSET,
296 offsetof(ngx_http_core_loc_conf_t, tcp_nodelay),
297 NULL },
298
Igor Sysoev865c1502003-11-30 20:03:18 +0000299 { ngx_string("send_timeout"),
300 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
301 ngx_conf_set_msec_slot,
302 NGX_HTTP_LOC_CONF_OFFSET,
303 offsetof(ngx_http_core_loc_conf_t, send_timeout),
304 NULL },
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000305
Igor Sysoev865c1502003-11-30 20:03:18 +0000306 { ngx_string("send_lowat"),
307 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
308 ngx_conf_set_size_slot,
309 NGX_HTTP_LOC_CONF_OFFSET,
310 offsetof(ngx_http_core_loc_conf_t, send_lowat),
Igor Sysoev805d9db2005-02-03 19:33:37 +0000311 &ngx_http_core_lowat_post },
Igor Sysoevb5faed22003-10-29 08:30:44 +0000312
Igor Sysoev7823cc32004-07-14 16:01:42 +0000313 { ngx_string("postpone_output"),
314 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
315 ngx_conf_set_size_slot,
316 NGX_HTTP_LOC_CONF_OFFSET,
317 offsetof(ngx_http_core_loc_conf_t, postpone_output),
318 NULL },
319
320 { ngx_string("limit_rate"),
Igor Sysoev805d9db2005-02-03 19:33:37 +0000321 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
322 |NGX_CONF_TAKE1,
Igor Sysoev7823cc32004-07-14 16:01:42 +0000323 ngx_conf_set_size_slot,
324 NGX_HTTP_LOC_CONF_OFFSET,
325 offsetof(ngx_http_core_loc_conf_t, limit_rate),
326 NULL },
327
Igor Sysoev865c1502003-11-30 20:03:18 +0000328 { ngx_string("keepalive_timeout"),
Igor Sysoev307c3ad2004-09-17 16:07:35 +0000329 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000330 ngx_http_core_keepalive,
Igor Sysoev865c1502003-11-30 20:03:18 +0000331 NGX_HTTP_LOC_CONF_OFFSET,
Igor Sysoev307c3ad2004-09-17 16:07:35 +0000332 0,
Igor Sysoev865c1502003-11-30 20:03:18 +0000333 NULL },
Igor Sysoevfa73aac2003-05-21 13:28:21 +0000334
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000335 { ngx_string("satisfy_any"),
336 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
337 ngx_conf_set_flag_slot,
338 NGX_HTTP_LOC_CONF_OFFSET,
339 offsetof(ngx_http_core_loc_conf_t, satisfy_any),
340 NULL },
341
Igor Sysoev899b44e2005-05-12 14:58:06 +0000342 { ngx_string("internal"),
343 NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
344 ngx_http_core_internal,
345 NGX_HTTP_LOC_CONF_OFFSET,
346 0,
347 NULL },
348
Igor Sysoev865c1502003-11-30 20:03:18 +0000349 { ngx_string("lingering_time"),
350 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
351 ngx_conf_set_msec_slot,
352 NGX_HTTP_LOC_CONF_OFFSET,
353 offsetof(ngx_http_core_loc_conf_t, lingering_time),
354 NULL },
Igor Sysoevb7387572003-03-11 20:38:13 +0000355
Igor Sysoev865c1502003-11-30 20:03:18 +0000356 { ngx_string("lingering_timeout"),
357 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
358 ngx_conf_set_msec_slot,
359 NGX_HTTP_LOC_CONF_OFFSET,
360 offsetof(ngx_http_core_loc_conf_t, lingering_timeout),
361 NULL },
Igor Sysoevb7387572003-03-11 20:38:13 +0000362
Igor Sysoev0ab91b92004-06-06 19:49:18 +0000363 { ngx_string("reset_timedout_connection"),
364 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
365 ngx_conf_set_flag_slot,
366 NGX_HTTP_LOC_CONF_OFFSET,
367 offsetof(ngx_http_core_loc_conf_t, reset_timedout_connection),
368 NULL },
369
Igor Sysoev7b190b42005-06-07 15:56:31 +0000370 { ngx_string("port_in_redirect"),
371 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
372 ngx_conf_set_flag_slot,
373 NGX_HTTP_LOC_CONF_OFFSET,
374 offsetof(ngx_http_core_loc_conf_t, port_in_redirect),
375 NULL },
376
Igor Sysoev865c1502003-11-30 20:03:18 +0000377 { ngx_string("msie_padding"),
378 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
379 ngx_conf_set_flag_slot,
380 NGX_HTTP_LOC_CONF_OFFSET,
381 offsetof(ngx_http_core_loc_conf_t, msie_padding),
382 NULL },
Igor Sysoev12b4b002003-10-24 06:53:41 +0000383
Igor Sysoev5192b362005-07-08 14:34:20 +0000384 { ngx_string("log_not_found"),
385 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
386 ngx_conf_set_flag_slot,
387 NGX_HTTP_LOC_CONF_OFFSET,
388 offsetof(ngx_http_core_loc_conf_t, log_not_found),
389 NULL },
390
Igor Sysoev865c1502003-11-30 20:03:18 +0000391 { ngx_string("error_page"),
Igor Sysoev899b44e2005-05-12 14:58:06 +0000392 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
393 |NGX_CONF_2MORE,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000394 ngx_http_core_error_page,
Igor Sysoev865c1502003-11-30 20:03:18 +0000395 NGX_HTTP_LOC_CONF_OFFSET,
396 0,
397 NULL },
Igor Sysoev74e95c22003-11-09 20:03:38 +0000398
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000399 { ngx_string("post_action"),
400 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
401 |NGX_CONF_TAKE1,
402 ngx_conf_set_str_slot,
403 NGX_HTTP_LOC_CONF_OFFSET,
404 offsetof(ngx_http_core_loc_conf_t, post_action),
405 NULL },
406
Igor Sysoev865c1502003-11-30 20:03:18 +0000407 { ngx_string("error_log"),
Igor Sysoev03420a62004-01-20 20:40:08 +0000408 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000409 ngx_http_core_error_log,
Igor Sysoev865c1502003-11-30 20:03:18 +0000410 NGX_HTTP_LOC_CONF_OFFSET,
411 0,
412 NULL },
Igor Sysoev890fc962003-07-20 21:15:59 +0000413
Igor Sysoev67f88e92004-03-12 16:57:08 +0000414#if (NGX_HTTP_CACHE)
415
Igor Sysoev865c1502003-11-30 20:03:18 +0000416 { ngx_string("open_file_cache"),
417 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE4,
418 ngx_http_set_cache_slot,
419 NGX_HTTP_LOC_CONF_OFFSET,
420 offsetof(ngx_http_core_loc_conf_t, open_files),
421 NULL },
422
Igor Sysoev67f88e92004-03-12 16:57:08 +0000423#endif
424
Igor Sysoev865c1502003-11-30 20:03:18 +0000425 ngx_null_command
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000426};
427
428
Igor Sysoev8f125582006-07-28 15:16:17 +0000429static ngx_http_module_t ngx_http_core_module_ctx = {
Igor Sysoev899b44e2005-05-12 14:58:06 +0000430 ngx_http_core_preconfiguration, /* preconfiguration */
Igor Sysoev09c684b2005-11-09 17:25:55 +0000431 NULL, /* postconfiguration */
Igor Sysoev78329332003-11-10 17:17:31 +0000432
Igor Sysoeva9830112003-05-19 16:39:14 +0000433 ngx_http_core_create_main_conf, /* create main configuration */
434 ngx_http_core_init_main_conf, /* init main configuration */
Igor Sysoevdc479b42003-03-20 16:09:44 +0000435
Igor Sysoeva9830112003-05-19 16:39:14 +0000436 ngx_http_core_create_srv_conf, /* create server configuration */
437 ngx_http_core_merge_srv_conf, /* merge server configuration */
438
439 ngx_http_core_create_loc_conf, /* create location configuration */
440 ngx_http_core_merge_loc_conf /* merge location configuration */
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000441};
442
443
444ngx_module_t ngx_http_core_module = {
Igor Sysoev899b44e2005-05-12 14:58:06 +0000445 NGX_MODULE_V1,
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000446 &ngx_http_core_module_ctx, /* module context */
447 ngx_http_core_commands, /* module directives */
Igor Sysoev6253ca12003-05-27 12:18:54 +0000448 NGX_HTTP_MODULE, /* module type */
Igor Sysoeve5733802005-09-08 14:36:09 +0000449 NULL, /* init master */
Igor Sysoev899b44e2005-05-12 14:58:06 +0000450 NULL, /* init module */
Igor Sysoeve5733802005-09-08 14:36:09 +0000451 NULL, /* init process */
452 NULL, /* init thread */
453 NULL, /* exit thread */
454 NULL, /* exit process */
455 NULL, /* exit master */
456 NGX_MODULE_V1_PADDING
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000457};
458
459
Igor Sysoevaa828612005-02-09 14:31:07 +0000460void
461ngx_http_handler(ngx_http_request_t *r)
Igor Sysoev6ddfbf02003-05-15 15:42:53 +0000462{
Igor Sysoeve5a222c2005-01-25 12:27:35 +0000463 r->connection->log->action = NULL;
Igor Sysoev6ddfbf02003-05-15 15:42:53 +0000464
465 r->connection->unexpected_eof = 0;
466
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000467 if (r->err_ctx == NULL) {
468 switch (r->headers_in.connection_type) {
469 case 0:
470 if (r->http_version > NGX_HTTP_VERSION_10) {
471 r->keepalive = 1;
472 } else {
473 r->keepalive = 0;
474 }
475 break;
476
477 case NGX_HTTP_CONNECTION_CLOSE:
478 r->keepalive = 0;
479 break;
480
481 case NGX_HTTP_CONNECTION_KEEP_ALIVE:
Igor Sysoev419f9ac2003-10-21 16:49:56 +0000482 r->keepalive = 1;
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000483 break;
484 }
485
486 if (r->keepalive && r->headers_in.msie && r->method == NGX_HTTP_POST) {
487
488 /*
Igor Sysoevcdf609a2006-04-17 19:55:41 +0000489 * MSIE may wait for some time if the response for
490 * the POST request is sent over the keepalive connection
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000491 */
492
Igor Sysoev9760a132003-10-21 07:47:21 +0000493 r->keepalive = 0;
494 }
Igor Sysoev419f9ac2003-10-21 16:49:56 +0000495
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000496 if (r->headers_in.content_length_n > 0) {
497 r->lingering_close = 1;
Igor Sysoev419f9ac2003-10-21 16:49:56 +0000498
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000499 } else {
500 r->lingering_close = 0;
501 }
Igor Sysoev9760a132003-10-21 07:47:21 +0000502 }
503
Igor Sysoev899b44e2005-05-12 14:58:06 +0000504 r->write_event_handler = ngx_http_core_run_phases;
Igor Sysoev6ddfbf02003-05-15 15:42:53 +0000505
Igor Sysoevc04deca2005-03-28 14:43:02 +0000506 r->valid_unparsed_uri = 1;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000507 r->valid_location = 1;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000508 r->uri_changed = 1;
Igor Sysoevc04deca2005-03-28 14:43:02 +0000509
Igor Sysoevdf3254a2006-01-11 15:26:57 +0000510 r->phase = (r == r->main) ? NGX_HTTP_POST_READ_PHASE:
Igor Sysoev09c684b2005-11-09 17:25:55 +0000511 NGX_HTTP_SERVER_REWRITE_PHASE;
Igor Sysoev1ebfead2005-02-16 13:40:36 +0000512 r->phase_handler = 0;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000513
514 ngx_http_core_run_phases(r);
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000515}
Igor Sysoeve2a31542003-04-08 15:40:10 +0000516
517
Igor Sysoevaa828612005-02-09 14:31:07 +0000518static void
Igor Sysoevaa828612005-02-09 14:31:07 +0000519ngx_http_core_run_phases(ngx_http_request_t *r)
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000520{
Igor Sysoev865c1502003-11-30 20:03:18 +0000521 ngx_int_t rc;
Igor Sysoevef809b82006-06-28 16:00:26 +0000522 ngx_str_t path;
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000523 ngx_http_handler_pt *h;
Igor Sysoev865c1502003-11-30 20:03:18 +0000524 ngx_http_core_loc_conf_t *clcf;
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000525 ngx_http_core_main_conf_t *cmcf;
526
Igor Sysoev899b44e2005-05-12 14:58:06 +0000527 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
528 "http phase handler");
529
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000530 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
531
Igor Sysoevc31a9bb2005-11-26 10:11:11 +0000532 for (/* void */; r->phase < NGX_HTTP_LOG_PHASE; r->phase++) {
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000533
Igor Sysoev1ebfead2005-02-16 13:40:36 +0000534 if (r->phase == NGX_HTTP_REWRITE_PHASE + 1 && r->uri_changed) {
Igor Sysoev805d9db2005-02-03 19:33:37 +0000535
536 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
537 "uri changes: %d", r->uri_changes);
538
539 /*
540 * gcc before 3.3 compiles the broken code for
541 * if (r->uri_changes-- == 0)
542 * if the r->uri_changes is defined as
543 * unsigned uri_changes:4
544 */
545
546 r->uri_changes--;
547
548 if (r->uri_changes == 0) {
549 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000550 "rewrite or internal redirection cycle");
Igor Sysoev805d9db2005-02-03 19:33:37 +0000551 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
552 return;
553 }
554
Igor Sysoev1ebfead2005-02-16 13:40:36 +0000555 r->phase = NGX_HTTP_FIND_CONFIG_PHASE;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000556 }
557
Igor Sysoevdf3254a2006-01-11 15:26:57 +0000558 if (r->phase == NGX_HTTP_ACCESS_PHASE && r != r->main) {
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000559 continue;
560 }
561
Igor Sysoev865c1502003-11-30 20:03:18 +0000562 if (r->phase == NGX_HTTP_CONTENT_PHASE && r->content_handler) {
Igor Sysoev899b44e2005-05-12 14:58:06 +0000563 r->write_event_handler = ngx_http_request_empty_handler;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000564 ngx_http_finalize_request(r, r->content_handler(r));
Igor Sysoev865c1502003-11-30 20:03:18 +0000565 return;
566 }
567
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000568 h = cmcf->phases[r->phase].handlers.elts;
569 for (r->phase_handler = cmcf->phases[r->phase].handlers.nelts - 1;
570 r->phase_handler >= 0;
571 r->phase_handler--)
572 {
573 rc = h[r->phase_handler](r);
574
Igor Sysoev9760a132003-10-21 07:47:21 +0000575 if (rc == NGX_DONE) {
Igor Sysoev865c1502003-11-30 20:03:18 +0000576
577 /*
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000578 * we should never use r here because
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000579 * it may point to already freed data
Igor Sysoev865c1502003-11-30 20:03:18 +0000580 */
581
Igor Sysoev9760a132003-10-21 07:47:21 +0000582 return;
583 }
584
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000585 if (rc == NGX_DECLINED) {
586 continue;
587 }
588
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000589 if (r->phase == NGX_HTTP_ACCESS_PHASE) {
590 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
591
592 if (clcf->satisfy_any) {
593
594 if (rc == NGX_OK) {
595 r->access_code = 0;
596
597 if (r->headers_out.www_authenticate) {
598 r->headers_out.www_authenticate->hash = 0;
599 }
600
601 break;
602 }
603
604 if (rc == NGX_HTTP_FORBIDDEN || rc == NGX_HTTP_UNAUTHORIZED)
605 {
606 r->access_code = rc;
607
608 continue;
609 }
610 }
611 }
612
Igor Sysoev3362b8d2005-05-14 18:42:03 +0000613 if (rc >= NGX_HTTP_SPECIAL_RESPONSE
614 || rc == NGX_HTTP_NO_CONTENT
615 || rc == NGX_ERROR)
616 {
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000617 ngx_http_finalize_request(r, rc);
618 return;
619 }
620
Igor Sysoeve3466a42003-12-15 13:57:13 +0000621 if (r->phase == NGX_HTTP_CONTENT_PHASE) {
622 ngx_http_finalize_request(r, rc);
623 return;
624 }
625
626 if (rc == NGX_AGAIN) {
Igor Sysoev865c1502003-11-30 20:03:18 +0000627 return;
628 }
629
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000630 if (rc == NGX_OK && cmcf->phases[r->phase].type == NGX_OK) {
631 break;
632 }
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000633
634 }
635
636 if (r->phase == NGX_HTTP_ACCESS_PHASE && r->access_code) {
Igor Sysoev1765f472006-07-07 16:33:19 +0000637
638 if (r->access_code == NGX_HTTP_FORBIDDEN) {
639 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
640 "access forbidden by rule");
641 }
642
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000643 ngx_http_finalize_request(r, r->access_code);
644 return;
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000645 }
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000646 }
647
Igor Sysoev805d9db2005-02-03 19:33:37 +0000648 /* no content handler was found */
Igor Sysoev865c1502003-11-30 20:03:18 +0000649
Igor Sysoev1ebfead2005-02-16 13:40:36 +0000650 if (r->uri.data[r->uri.len - 1] == '/' && !r->zero_in_uri) {
Igor Sysoev865c1502003-11-30 20:03:18 +0000651
Igor Sysoevef809b82006-06-28 16:00:26 +0000652 if (ngx_http_map_uri_to_path(r, &path, 0) != NULL) {
653 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
654 "directory index of \"%V\" is forbidden", &path);
655 }
Igor Sysoev865c1502003-11-30 20:03:18 +0000656
657 ngx_http_finalize_request(r, NGX_HTTP_FORBIDDEN);
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000658 return;
659 }
660
Igor Sysoev865c1502003-11-30 20:03:18 +0000661 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no handler found");
662
663 ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000664}
665
666
Igor Sysoevaa828612005-02-09 14:31:07 +0000667ngx_int_t
668ngx_http_find_location_config(ngx_http_request_t *r)
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000669{
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000670 ngx_int_t rc;
671 ngx_http_core_loc_conf_t *clcf;
672 ngx_http_core_srv_conf_t *cscf;
Igor Sysoeve2a31542003-04-08 15:40:10 +0000673
Igor Sysoev1ebfead2005-02-16 13:40:36 +0000674 r->content_handler = NULL;
675 r->uri_changed = 0;
676
Igor Sysoev6253ca12003-05-27 12:18:54 +0000677 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
Igor Sysoeve2a31542003-04-08 15:40:10 +0000678
Igor Sysoev805d9db2005-02-03 19:33:37 +0000679 rc = ngx_http_core_find_location(r, &cscf->locations, 0);
Igor Sysoeva8fa0a62003-11-25 20:44:56 +0000680
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000681 if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) {
682 return rc;
Igor Sysoeva8fa0a62003-11-25 20:44:56 +0000683 }
684
Igor Sysoev419f9ac2003-10-21 16:49:56 +0000685 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
686
Igor Sysoev899b44e2005-05-12 14:58:06 +0000687 if (!r->internal && clcf->internal) {
688 return NGX_HTTP_NOT_FOUND;
689 }
690
Igor Sysoeva2573672005-10-05 14:46:21 +0000691 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
692 "using configuration \"%s%V\"",
693 (clcf->noname ? "*" : (clcf->exact_match ? "=" : "")),
694 &clcf->name);
695
Igor Sysoevb85fd592005-08-23 15:36:54 +0000696 ngx_http_update_location_config(r);
Igor Sysoev89690bf2004-03-23 06:01:52 +0000697
698 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
Igor Sysoev1765f472006-07-07 16:33:19 +0000699 "http cl:%O max:%O",
Igor Sysoev1b735832004-11-11 14:07:14 +0000700 r->headers_in.content_length_n, clcf->client_max_body_size);
Igor Sysoev89690bf2004-03-23 06:01:52 +0000701
702 if (r->headers_in.content_length_n != -1
703 && clcf->client_max_body_size
Igor Sysoev1765f472006-07-07 16:33:19 +0000704 && clcf->client_max_body_size < r->headers_in.content_length_n)
Igor Sysoev89690bf2004-03-23 06:01:52 +0000705 {
706 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
Igor Sysoev1765f472006-07-07 16:33:19 +0000707 "client intented to send too large body: %O bytes",
Igor Sysoev89690bf2004-03-23 06:01:52 +0000708 r->headers_in.content_length_n);
709
710 return NGX_HTTP_REQUEST_ENTITY_TOO_LARGE;
711 }
712
713
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000714 if (rc == NGX_HTTP_LOCATION_AUTO_REDIRECT) {
Igor Sysoevaab4d8c2004-09-06 18:45:00 +0000715 r->headers_out.location = ngx_list_push(&r->headers_out.headers);
716 if (r->headers_out.location == NULL) {
Igor Sysoev1b138ed2003-11-18 21:34:08 +0000717 return NGX_HTTP_INTERNAL_SERVER_ERROR;
718 }
719
Igor Sysoev899b44e2005-05-12 14:58:06 +0000720 /*
721 * we do not need to set the r->headers_out.location->hash and
722 * r->headers_out.location->key fields
723 */
724
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000725 r->headers_out.location->value = clcf->name;
Igor Sysoev1b138ed2003-11-18 21:34:08 +0000726
727 return NGX_HTTP_MOVED_PERMANENTLY;
728 }
729
Igor Sysoevb85fd592005-08-23 15:36:54 +0000730 return NGX_OK;
731}
732
733
734void
735ngx_http_update_location_config(ngx_http_request_t *r)
736{
737 ngx_http_core_loc_conf_t *clcf;
738
739 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
740
Igor Sysoev94e32ce2006-04-07 14:08:04 +0000741 if (r->method & clcf->limit_except) {
742 r->loc_conf = clcf->limit_except_loc_conf;
743 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
744 }
745
Igor Sysoevb0518172006-04-26 15:21:08 +0000746 if (r == r->main) {
747 r->connection->log->file = clcf->err_log->file;
748 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
749 r->connection->log->log_level = clcf->err_log->log_level;
750 }
Igor Sysoevb85fd592005-08-23 15:36:54 +0000751 }
752
753 if ((ngx_io.flags & NGX_IO_SENDFILE) && clcf->sendfile) {
754 r->connection->sendfile = 1;
755
756 } else {
757 r->connection->sendfile = 0;
758 }
759
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +0000760 if (clcf->client_body_in_file_only) {
761 r->request_body_in_file_only = 1;
762 r->request_body_in_persistent_file = 1;
Igor Sysoev7bdb7202006-04-19 15:30:56 +0000763 r->request_body_file_log_level = NGX_LOG_NOTICE;
764
765 } else {
766 r->request_body_file_log_level = NGX_LOG_WARN;
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +0000767 }
768
Igor Sysoevb85fd592005-08-23 15:36:54 +0000769 if (r->keepalive && clcf->keepalive_timeout == 0) {
770 r->keepalive = 0;
771 }
772
773 if (!clcf->tcp_nopush) {
774 /* disable TCP_NOPUSH/TCP_CORK use */
775 r->connection->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;
776 }
777
Igor Sysoevc2807ec2006-02-16 15:26:46 +0000778 if (r->limit_rate == 0) {
779 r->limit_rate = clcf->limit_rate;
780 }
Igor Sysoev5192b362005-07-08 14:34:20 +0000781
Igor Sysoev6253ca12003-05-27 12:18:54 +0000782 if (clcf->handler) {
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000783 r->content_handler = clcf->handler;
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000784 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000785}
786
787
Igor Sysoevaa828612005-02-09 14:31:07 +0000788static ngx_int_t
789ngx_http_core_find_location(ngx_http_request_t *r,
790 ngx_array_t *locations, size_t len)
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000791{
792 ngx_int_t n, rc;
Igor Sysoevd43bee82004-11-20 19:52:20 +0000793 ngx_uint_t i, found, noregex;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000794 ngx_http_core_loc_conf_t *clcf, **clcfp;
795
Igor Sysoeva2573672005-10-05 14:46:21 +0000796 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
797 "find location for \"%V\"", &r->uri);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000798
799 found = 0;
Igor Sysoevd43bee82004-11-20 19:52:20 +0000800 noregex = 0;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000801
802 clcfp = locations->elts;
803 for (i = 0; i < locations->nelts; i++) {
804
Igor Sysoevc0edbcc2004-10-21 15:34:38 +0000805#if (NGX_PCRE)
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000806 if (clcfp[i]->regex) {
807 break;
808 }
809#endif
810
Igor Sysoev805d9db2005-02-03 19:33:37 +0000811 if (clcfp[i]->noname) {
812 break;
813 }
814
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000815 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +0000816 "find location: %s\"%V\"",
817 clcfp[i]->exact_match ? "= " : "", &clcfp[i]->name);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000818
819 if (clcfp[i]->auto_redirect
820 && r->uri.len == clcfp[i]->name.len - 1
821 && ngx_strncmp(r->uri.data, clcfp[i]->name.data,
822 clcfp[i]->name.len - 1) == 0)
823 {
824 /* the locations are lexicographically sorted */
825
826 r->loc_conf = clcfp[i]->loc_conf;
827
828 return NGX_HTTP_LOCATION_AUTO_REDIRECT;
829 }
830
831 if (r->uri.len < clcfp[i]->name.len) {
832 continue;
833 }
834
835 n = ngx_strncmp(r->uri.data, clcfp[i]->name.data, clcfp[i]->name.len);
836
837 if (n < 0) {
838 /* the locations are lexicographically sorted */
839 break;
840 }
841
842 if (n == 0) {
Igor Sysoev805d9db2005-02-03 19:33:37 +0000843 if (clcfp[i]->exact_match) {
844
845 if (r->uri.len == clcfp[i]->name.len) {
846 r->loc_conf = clcfp[i]->loc_conf;
847 return NGX_HTTP_LOCATION_EXACT;
848 }
849
850 continue;
Igor Sysoevea521232004-07-26 16:21:18 +0000851 }
852
Igor Sysoev71057632004-08-30 19:24:51 +0000853 if (len > clcfp[i]->name.len) {
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000854 /* the previous match is longer */
855 break;
856 }
857
858 r->loc_conf = clcfp[i]->loc_conf;
Igor Sysoevd43bee82004-11-20 19:52:20 +0000859 noregex = clcfp[i]->noregex;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000860 found = 1;
861 }
862 }
863
864 if (found) {
865 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
866
867 if (clcf->locations.nelts) {
Igor Sysoev805d9db2005-02-03 19:33:37 +0000868 rc = ngx_http_core_find_location(r, &clcf->locations, len);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000869
870 if (rc != NGX_OK) {
871 return rc;
872 }
873 }
874 }
875
Igor Sysoevc0edbcc2004-10-21 15:34:38 +0000876#if (NGX_PCRE)
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000877
Igor Sysoevd43bee82004-11-20 19:52:20 +0000878 if (noregex) {
879 return NGX_HTTP_LOCATION_NOREGEX;
880 }
881
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000882 /* regex matches */
883
884 for (/* void */; i < locations->nelts; i++) {
885
886 if (!clcfp[i]->regex) {
887 continue;
888 }
889
Igor Sysoev805d9db2005-02-03 19:33:37 +0000890 if (clcfp[i]->noname) {
891 break;
892 }
893
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000894 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +0000895 "find location: ~ \"%V\"", &clcfp[i]->name);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000896
897 n = ngx_regex_exec(clcfp[i]->regex, &r->uri, NULL, 0);
898
Igor Sysoev3259e852005-01-19 13:10:56 +0000899 if (n == NGX_REGEX_NO_MATCHED) {
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000900 continue;
901 }
902
903 if (n < 0) {
904 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
905 ngx_regex_exec_n
Igor Sysoev1b735832004-11-11 14:07:14 +0000906 " failed: %d on \"%V\" using \"%V\"",
907 n, &r->uri, &clcfp[i]->name);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000908 return NGX_HTTP_INTERNAL_SERVER_ERROR;
909 }
910
911 /* match */
912
913 r->loc_conf = clcfp[i]->loc_conf;
914
915 return NGX_HTTP_LOCATION_REGEX;
916 }
917
Igor Sysoevc0edbcc2004-10-21 15:34:38 +0000918#endif /* NGX_PCRE */
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000919
920 return NGX_OK;
921}
922
923
Igor Sysoevaa828612005-02-09 14:31:07 +0000924ngx_int_t
925ngx_http_set_content_type(ngx_http_request_t *r)
Igor Sysoev865c1502003-11-30 20:03:18 +0000926{
Igor Sysoev805d9db2005-02-03 19:33:37 +0000927 u_char c, *p, *exten;
Igor Sysoev24025022005-12-16 15:07:08 +0000928 ngx_str_t *type;
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000929 ngx_uint_t i, hash;
Igor Sysoev865c1502003-11-30 20:03:18 +0000930 ngx_http_core_loc_conf_t *clcf;
931
Igor Sysoev865c1502003-11-30 20:03:18 +0000932 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
933
934 if (r->exten.len) {
Igor Sysoev805d9db2005-02-03 19:33:37 +0000935
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000936 hash = 0;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000937
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000938 for (i = 0; i < r->exten.len; i++) {
939 c = r->exten.data[i];
940
941 if (c >= 'A' && c <= 'Z') {
942
Igor Sysoevc1571722005-03-19 12:38:37 +0000943 p = ngx_palloc(r->pool, r->exten.len);
944 if (p == NULL) {
Igor Sysoev805d9db2005-02-03 19:33:37 +0000945 return NGX_HTTP_INTERNAL_SERVER_ERROR;
946 }
947
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000948 hash = 0;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000949 exten = p;
950
951 for (i = 0; i < r->exten.len; i++) {
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000952 c = ngx_tolower(r->exten.data[i]);
953 hash = ngx_hash(hash, c);
954 *p++ = c;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000955 }
956
957 r->exten.data = exten;
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000958
959 break;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000960 }
961
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000962 hash = ngx_hash(hash, c);
Igor Sysoev805d9db2005-02-03 19:33:37 +0000963 }
964
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000965 type = ngx_hash_find(&clcf->types_hash, hash,
Igor Sysoev24025022005-12-16 15:07:08 +0000966 r->exten.data, r->exten.len);
Igor Sysoev865c1502003-11-30 20:03:18 +0000967
Igor Sysoev24025022005-12-16 15:07:08 +0000968 if (type) {
Igor Sysoevef809b82006-06-28 16:00:26 +0000969 r->headers_out.content_type_len = type->len;
Igor Sysoev24025022005-12-16 15:07:08 +0000970 r->headers_out.content_type = *type;
Igor Sysoevef809b82006-06-28 16:00:26 +0000971
Igor Sysoev24025022005-12-16 15:07:08 +0000972 return NGX_OK;
Igor Sysoev865c1502003-11-30 20:03:18 +0000973 }
974 }
975
Igor Sysoevef809b82006-06-28 16:00:26 +0000976 r->headers_out.content_type_len = clcf->default_type.len;
Igor Sysoev24025022005-12-16 15:07:08 +0000977 r->headers_out.content_type = clcf->default_type;
Igor Sysoev865c1502003-11-30 20:03:18 +0000978
979 return NGX_OK;
980}
981
982
Igor Sysoevaa828612005-02-09 14:31:07 +0000983ngx_int_t
Igor Sysoevaa828612005-02-09 14:31:07 +0000984ngx_http_set_exten(ngx_http_request_t *r)
Igor Sysoev3b30a902003-12-25 20:26:58 +0000985{
986 ngx_int_t i;
987
988 r->exten.len = 0;
989 r->exten.data = NULL;
990
991 for (i = r->uri.len - 1; i > 1; i--) {
992 if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000993
Igor Sysoev3b30a902003-12-25 20:26:58 +0000994 r->exten.len = r->uri.len - i - 1;
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000995 r->exten.data = &r->uri.data[i + 1];
Igor Sysoev3b30a902003-12-25 20:26:58 +0000996
997 break;
998
999 } else if (r->uri.data[i] == '/') {
1000 break;
1001 }
1002 }
1003
1004 return NGX_OK;
1005}
1006
1007
Igor Sysoevaa828612005-02-09 14:31:07 +00001008ngx_int_t
Igor Sysoev208eed22005-10-07 13:30:52 +00001009ngx_http_send_header(ngx_http_request_t *r)
1010{
1011 if (r->err_status) {
1012 r->headers_out.status = r->err_status;
1013 r->headers_out.status_line.len = 0;
1014 }
1015
1016 return ngx_http_top_header_filter(r);
1017}
1018
1019
1020ngx_int_t
1021ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
1022{
1023 ngx_int_t rc;
1024
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001025 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1026 "http output filter \"%V?%V\"", &r->uri, &r->args);
Igor Sysoev208eed22005-10-07 13:30:52 +00001027
1028 rc = ngx_http_top_body_filter(r, in);
1029
1030 if (rc == NGX_ERROR) {
1031 /* NGX_ERROR may be returned by any filter */
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001032 r->connection->error = 1;
Igor Sysoev208eed22005-10-07 13:30:52 +00001033 }
1034
1035 return rc;
1036}
1037
1038
1039u_char *
1040ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,
1041 size_t reserved)
1042{
Igor Sysoev8fea8852006-03-15 09:53:04 +00001043 u_char *last;
1044 size_t alias;
1045 ngx_http_core_loc_conf_t *clcf;
Igor Sysoev208eed22005-10-07 13:30:52 +00001046
1047 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1048
1049 alias = clcf->alias ? clcf->name.len : 0;
1050
Igor Sysoev34303462006-01-24 16:08:27 +00001051 if (alias && !r->valid_location) {
1052 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
1053 "\"alias\" could not be used in location \"%V\" "
1054 "where URI was rewritten", &clcf->name);
1055 return NULL;
1056 }
1057
Igor Sysoev8fea8852006-03-15 09:53:04 +00001058 reserved += r->uri.len - alias + 1;
1059
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001060 if (clcf->root_lengths == NULL) {
Igor Sysoev208eed22005-10-07 13:30:52 +00001061
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001062 r->root_length = clcf->root.len;
1063
Igor Sysoev8fea8852006-03-15 09:53:04 +00001064 path->len = clcf->root.len + reserved;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001065
1066 path->data = ngx_palloc(r->pool, path->len);
1067 if (path->data == NULL) {
1068 return NULL;
1069 }
1070
1071 last = ngx_copy(path->data, clcf->root.data, clcf->root.len);
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001072
Igor Sysoev8fea8852006-03-15 09:53:04 +00001073 } else {
Igor Sysoev8f125582006-07-28 15:16:17 +00001074 if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved,
1075 clcf->root_values->elts)
1076 == NULL)
1077 {
1078 return NULL;
1079 }
1080
1081 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, path) == NGX_ERROR) {
Igor Sysoev8fea8852006-03-15 09:53:04 +00001082 return NULL;
1083 }
1084
1085 r->root_length = path->len - reserved;
Igor Sysoev8f125582006-07-28 15:16:17 +00001086 last = path->data + r->root_length;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001087 }
1088
Igor Sysoev8fea8852006-03-15 09:53:04 +00001089 last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1);
Igor Sysoev208eed22005-10-07 13:30:52 +00001090
1091 return last;
1092}
1093
1094
1095ngx_int_t
Igor Sysoevceb99292005-09-06 16:09:32 +00001096ngx_http_auth_basic_user(ngx_http_request_t *r)
1097{
1098 ngx_str_t auth, encoded;
1099 ngx_uint_t len;
1100
1101 if (r->headers_in.user.len == 0 && r->headers_in.user.data != NULL) {
1102 return NGX_DECLINED;
1103 }
1104
1105 if (r->headers_in.authorization == NULL) {
1106 r->headers_in.user.data = (u_char *) "";
1107 return NGX_DECLINED;
1108 }
1109
1110 encoded = r->headers_in.authorization->value;
1111
1112 if (encoded.len < sizeof("Basic ") - 1
1113 || ngx_strncasecmp(encoded.data, "Basic ", sizeof("Basic ") - 1) != 0)
1114 {
1115 r->headers_in.user.data = (u_char *) "";
1116 return NGX_DECLINED;
1117 }
1118
1119 encoded.len -= sizeof("Basic ") - 1;
1120 encoded.data += sizeof("Basic ") - 1;
1121
1122 while (encoded.len && encoded.data[0] == ' ') {
1123 encoded.len--;
1124 encoded.data++;
1125 }
1126
1127 if (encoded.len == 0) {
1128 r->headers_in.user.data = (u_char *) "";
1129 return NGX_DECLINED;
1130 }
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001131
Igor Sysoevceb99292005-09-06 16:09:32 +00001132 auth.len = ngx_base64_decoded_length(encoded.len);
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001133 auth.data = ngx_palloc(r->pool, auth.len + 1);
Igor Sysoevceb99292005-09-06 16:09:32 +00001134 if (auth.data == NULL) {
1135 return NGX_ERROR;
1136 }
1137
1138 if (ngx_decode_base64(&auth, &encoded) != NGX_OK) {
1139 r->headers_in.user.data = (u_char *) "";
1140 return NGX_DECLINED;
1141 }
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001142
Igor Sysoevceb99292005-09-06 16:09:32 +00001143 auth.data[auth.len] = '\0';
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001144
1145 for (len = 0; len < auth.len; len++) {
Igor Sysoevceb99292005-09-06 16:09:32 +00001146 if (auth.data[len] == ':') {
1147 break;
1148 }
1149 }
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001150
Igor Sysoev09c684b2005-11-09 17:25:55 +00001151 if (len == 0 || len == auth.len) {
Igor Sysoevceb99292005-09-06 16:09:32 +00001152 r->headers_in.user.data = (u_char *) "";
1153 return NGX_DECLINED;
1154 }
1155
1156 r->headers_in.user.len = len;
1157 r->headers_in.user.data = auth.data;
1158 r->headers_in.passwd.len = auth.len - len - 1;
1159 r->headers_in.passwd.data = &auth.data[len + 1];
1160
1161 return NGX_OK;
1162}
1163
1164
1165ngx_int_t
Igor Sysoev899b44e2005-05-12 14:58:06 +00001166ngx_http_subrequest(ngx_http_request_t *r,
Igor Sysoev8f125582006-07-28 15:16:17 +00001167 ngx_str_t *uri, ngx_str_t *args, ngx_chain_t *out, ngx_uint_t flags)
Igor Sysoev899b44e2005-05-12 14:58:06 +00001168{
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001169 ngx_connection_t *c;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001170 ngx_http_request_t *sr;
Igor Sysoevbb28b6d2006-07-11 13:20:19 +00001171 ngx_http_log_ctx_t *ctx;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001172 ngx_http_core_srv_conf_t *cscf;
1173 ngx_http_postponed_request_t *pr, *p;
1174
Igor Sysoevef809b82006-06-28 16:00:26 +00001175 r->main->subrequests--;
1176
1177 if (r->main->subrequests == 0) {
1178 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1179 "subrequests cycle");
1180 return NGX_ERROR;
1181 }
1182
Igor Sysoev899b44e2005-05-12 14:58:06 +00001183 sr = ngx_pcalloc(r->pool, sizeof(ngx_http_request_t));
1184 if (sr == NULL) {
Igor Sysoevac72bd12006-05-04 15:32:46 +00001185 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001186 }
1187
1188 sr->signature = NGX_HTTP_MODULE;
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001189
1190 c = r->connection;
1191 sr->connection = c;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001192
1193 sr->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
1194 if (sr->ctx == NULL) {
Igor Sysoevac72bd12006-05-04 15:32:46 +00001195 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001196 }
1197
1198 if (ngx_list_init(&sr->headers_out.headers, r->pool, 20,
Igor Sysoevc31a9bb2005-11-26 10:11:11 +00001199 sizeof(ngx_table_elt_t))
1200 == NGX_ERROR)
Igor Sysoev899b44e2005-05-12 14:58:06 +00001201 {
Igor Sysoevac72bd12006-05-04 15:32:46 +00001202 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001203 }
1204
1205 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
1206 sr->main_conf = cscf->ctx->main_conf;
1207 sr->srv_conf = cscf->ctx->srv_conf;
1208 sr->loc_conf = cscf->ctx->loc_conf;
1209
1210 sr->pool = r->pool;
1211
1212 sr->headers_in = r->headers_in;
1213
1214 sr->start_time = ngx_time();
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001215
1216 ngx_http_clear_content_length(sr);
1217 ngx_http_clear_accept_ranges(sr);
1218 ngx_http_clear_last_modified(sr);
Igor Sysoev899b44e2005-05-12 14:58:06 +00001219
1220 sr->request_body = r->request_body;
1221
1222 sr->method = NGX_HTTP_GET;
1223 sr->http_version = r->http_version;
1224 sr->http_major = r->http_minor;
1225
1226 sr->request_line = r->request_line;
1227 sr->uri = *uri;
Igor Sysoev09c684b2005-11-09 17:25:55 +00001228
Igor Sysoev899b44e2005-05-12 14:58:06 +00001229 if (args) {
1230 sr->args = *args;
1231 }
Igor Sysoev09c684b2005-11-09 17:25:55 +00001232
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001233 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1234 "http subrequest \"%V?%V\"", uri, &sr->args);
1235
Igor Sysoev09c684b2005-11-09 17:25:55 +00001236 if (flags & NGX_HTTP_ZERO_IN_URI) {
1237 sr->zero_in_uri = 1;
1238 }
1239
Igor Sysoev899b44e2005-05-12 14:58:06 +00001240 sr->unparsed_uri = r->unparsed_uri;
1241 sr->method_name = r->method_name;
1242 sr->http_protocol = r->http_protocol;
1243
1244 if (ngx_http_set_exten(sr) != NGX_OK) {
Igor Sysoevac72bd12006-05-04 15:32:46 +00001245 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001246 }
1247
Igor Sysoev8f125582006-07-28 15:16:17 +00001248 sr->out = out;
Igor Sysoevf6e1fe32005-10-04 10:38:53 +00001249 sr->main = r->main;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001250 sr->parent = r;
1251 sr->read_event_handler = ngx_http_request_empty_handler;
1252 sr->write_event_handler = ngx_http_request_empty_handler;
1253
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001254 if (c->data == r) {
1255 c->data = sr;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001256 }
1257
1258 sr->in_addr = r->in_addr;
1259 sr->port = r->port;
1260 sr->port_text = r->port_text;
1261 sr->server_name = r->server_name;
1262
1263 sr->variables = r->variables;
1264
1265 sr->log_handler = r->log_handler;
1266
1267 pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t));
1268 if (pr == NULL) {
Igor Sysoevac72bd12006-05-04 15:32:46 +00001269 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001270 }
1271
1272 pr->request = sr;
1273 pr->out = NULL;
1274 pr->next = NULL;
1275
1276 if (r->postponed) {
1277 for (p = r->postponed; p->next; p = p->next) { /* void */ }
1278 p->next = pr;
1279
1280 } else {
1281 r->postponed = pr;
1282 }
1283
Igor Sysoevbb28b6d2006-07-11 13:20:19 +00001284 ctx = c->log->data;
1285 ctx->current_request = sr;
1286
Igor Sysoev899b44e2005-05-12 14:58:06 +00001287 sr->internal = 1;
Igor Sysoevdf3254a2006-01-11 15:26:57 +00001288 sr->fast_subrequest = 1;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001289
Igor Sysoev31eb8c02005-09-23 11:02:22 +00001290 sr->discard_body = r->discard_body;
Igor Sysoevd52477f2005-05-16 13:53:20 +00001291 sr->main_filter_need_in_memory = r->main_filter_need_in_memory;
1292
Igor Sysoev6f134cc2006-05-23 14:54:58 +00001293 sr->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1;
1294
Igor Sysoev899b44e2005-05-12 14:58:06 +00001295 ngx_http_handler(sr);
1296
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001297 if (!c->destroyed) {
1298 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1299 "http subrequest done \"%V?%V\"", uri, &sr->args);
Igor Sysoevac72bd12006-05-04 15:32:46 +00001300
1301 if (sr->fast_subrequest) {
1302 sr->fast_subrequest = 0;
1303
1304 if (sr->done) {
1305 return NGX_OK;
1306 }
1307 }
1308
1309 return NGX_AGAIN;
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001310 }
Igor Sysoev899b44e2005-05-12 14:58:06 +00001311
1312 return NGX_OK;
1313}
1314
1315
1316ngx_int_t
Igor Sysoevaa828612005-02-09 14:31:07 +00001317ngx_http_internal_redirect(ngx_http_request_t *r,
1318 ngx_str_t *uri, ngx_str_t *args)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001319{
Igor Sysoevaa828612005-02-09 14:31:07 +00001320 ngx_http_core_srv_conf_t *cscf;
1321
Igor Sysoev1b735832004-11-11 14:07:14 +00001322 r->uri = *uri;
Igor Sysoev13933252003-05-29 13:02:09 +00001323
1324 if (args) {
Igor Sysoev1b735832004-11-11 14:07:14 +00001325 r->args = *args;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001326
1327 } else {
1328 r->args.len = 0;
1329 r->args.data = NULL;
Igor Sysoev13933252003-05-29 13:02:09 +00001330 }
1331
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001332 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1333 "internal redirect: \"%V?%V\"", uri, &r->args);
1334
Igor Sysoev3b30a902003-12-25 20:26:58 +00001335 if (ngx_http_set_exten(r) != NGX_OK) {
1336 return NGX_HTTP_INTERNAL_SERVER_ERROR;
Igor Sysoev13933252003-05-29 13:02:09 +00001337 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001338
Igor Sysoev27c30f92003-11-11 18:13:43 +00001339 if (r->err_ctx) {
Igor Sysoevd59a0472003-11-10 21:09:22 +00001340
Igor Sysoevaa828612005-02-09 14:31:07 +00001341 /* allocate the new module's contexts */
Igor Sysoev27c30f92003-11-11 18:13:43 +00001342
Igor Sysoevd59a0472003-11-10 21:09:22 +00001343 r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
1344 if (r->ctx == NULL) {
1345 return NGX_HTTP_INTERNAL_SERVER_ERROR;
1346 }
1347
1348 } else {
Igor Sysoev27c30f92003-11-11 18:13:43 +00001349
1350 /* clear the modules contexts */
1351
Igor Sysoevd59a0472003-11-10 21:09:22 +00001352 ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
1353 }
Igor Sysoev0a280a32003-10-12 16:49:16 +00001354
Igor Sysoevaa828612005-02-09 14:31:07 +00001355 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
1356 r->loc_conf = cscf->ctx->loc_conf;
1357
Igor Sysoevb85fd592005-08-23 15:36:54 +00001358 ngx_http_update_location_config(r);
1359
Igor Sysoev899b44e2005-05-12 14:58:06 +00001360 r->internal = 1;
1361
Igor Sysoev6f134cc2006-05-23 14:54:58 +00001362 r->uri_changes--;
1363
Igor Sysoev79a80482003-05-14 17:13:13 +00001364 ngx_http_handler(r);
Igor Sysoev13933252003-05-29 13:02:09 +00001365
Igor Sysoev9760a132003-10-21 07:47:21 +00001366 return NGX_DONE;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001367}
1368
1369
Igor Sysoev9ac946b2005-10-24 15:09:41 +00001370ngx_http_cleanup_t *
1371ngx_http_cleanup_add(ngx_http_request_t *r, size_t size)
Igor Sysoev0a280a32003-10-12 16:49:16 +00001372{
Igor Sysoev9ac946b2005-10-24 15:09:41 +00001373 ngx_http_cleanup_t *cln;
Igor Sysoev0a280a32003-10-12 16:49:16 +00001374
Igor Sysoev9ac946b2005-10-24 15:09:41 +00001375 r = r->main;
1376
1377 cln = ngx_palloc(r->pool, sizeof(ngx_http_cleanup_t));
1378 if (cln == NULL) {
1379 return NULL;
Igor Sysoev0a280a32003-10-12 16:49:16 +00001380 }
1381
Igor Sysoev9ac946b2005-10-24 15:09:41 +00001382 if (size) {
1383 cln->data = ngx_palloc(r->pool, size);
1384 if (cln->data == NULL) {
1385 return NULL;
1386 }
Igor Sysoev0a280a32003-10-12 16:49:16 +00001387
Igor Sysoev9ac946b2005-10-24 15:09:41 +00001388 } else {
1389 cln->data = NULL;
1390 }
1391
1392 cln->handler = NULL;
1393 cln->next = r->cleanup;
1394
1395 r->cleanup = cln;
1396
1397 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1398 "http cleanup add: %p", cln);
1399
1400 return cln;
1401}
Igor Sysoev0a280a32003-10-12 16:49:16 +00001402
1403
Igor Sysoevaa828612005-02-09 14:31:07 +00001404static char *
1405ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001406{
Igor Sysoevaa828612005-02-09 14:31:07 +00001407 char *rv;
1408 void *mconf;
Igor Sysoev7b190b42005-06-07 15:56:31 +00001409 ngx_uint_t m;
1410 ngx_conf_t pcf;
Igor Sysoevaa828612005-02-09 14:31:07 +00001411 ngx_http_module_t *module;
1412 ngx_http_conf_ctx_t *ctx, *http_ctx;
1413 ngx_http_core_srv_conf_t *cscf, **cscfp;
1414 ngx_http_core_main_conf_t *cmcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001415
Igor Sysoevc1571722005-03-19 12:38:37 +00001416 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
1417 if (ctx == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00001418 return NGX_CONF_ERROR;
1419 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001420
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001421 http_ctx = cf->ctx;
1422 ctx->main_conf = http_ctx->main_conf;
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +00001423
Igor Sysoeva9830112003-05-19 16:39:14 +00001424 /* the server{}'s srv_conf */
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +00001425
Igor Sysoevaa828612005-02-09 14:31:07 +00001426 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
1427 if (ctx->srv_conf == NULL) {
1428 return NGX_CONF_ERROR;
1429 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001430
Igor Sysoeva9830112003-05-19 16:39:14 +00001431 /* the server{}'s loc_conf */
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +00001432
Igor Sysoevaa828612005-02-09 14:31:07 +00001433 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
1434 if (ctx->loc_conf == NULL) {
1435 return NGX_CONF_ERROR;
1436 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001437
Igor Sysoev1c13c662003-05-20 15:37:55 +00001438 for (m = 0; ngx_modules[m]; m++) {
Igor Sysoev6253ca12003-05-27 12:18:54 +00001439 if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001440 continue;
1441 }
1442
Igor Sysoev6253ca12003-05-27 12:18:54 +00001443 module = ngx_modules[m]->ctx;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001444
1445 if (module->create_srv_conf) {
Igor Sysoevc1571722005-03-19 12:38:37 +00001446 mconf = module->create_srv_conf(cf);
1447 if (mconf == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00001448 return NGX_CONF_ERROR;
1449 }
1450
1451 ctx->srv_conf[ngx_modules[m]->ctx_index] = mconf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001452 }
1453
1454 if (module->create_loc_conf) {
Igor Sysoevc1571722005-03-19 12:38:37 +00001455 mconf = module->create_loc_conf(cf);
1456 if (mconf == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00001457 return NGX_CONF_ERROR;
1458 }
1459
1460 ctx->loc_conf[ngx_modules[m]->ctx_index] = mconf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001461 }
1462 }
1463
Igor Sysoevaa828612005-02-09 14:31:07 +00001464
1465 /* the server configuration context */
Igor Sysoeva9830112003-05-19 16:39:14 +00001466
Igor Sysoev6253ca12003-05-27 12:18:54 +00001467 cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
Igor Sysoeva9830112003-05-19 16:39:14 +00001468 cscf->ctx = ctx;
1469
Igor Sysoevaa828612005-02-09 14:31:07 +00001470
Igor Sysoev6253ca12003-05-27 12:18:54 +00001471 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
Igor Sysoevaa828612005-02-09 14:31:07 +00001472
Igor Sysoevc1571722005-03-19 12:38:37 +00001473 cscfp = ngx_array_push(&cmcf->servers);
1474 if (cscfp == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00001475 return NGX_CONF_ERROR;
1476 }
1477
Igor Sysoeva9830112003-05-19 16:39:14 +00001478 *cscfp = cscf;
1479
Igor Sysoevaa828612005-02-09 14:31:07 +00001480
Igor Sysoeva9830112003-05-19 16:39:14 +00001481 /* parse inside server{} */
1482
Igor Sysoev7b190b42005-06-07 15:56:31 +00001483 pcf = *cf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001484 cf->ctx = ctx;
Igor Sysoev79a80482003-05-14 17:13:13 +00001485 cf->cmd_type = NGX_HTTP_SRV_CONF;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001486
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001487 rv = ngx_conf_parse(cf, NULL);
Igor Sysoev805d9db2005-02-03 19:33:37 +00001488
Igor Sysoev7b190b42005-06-07 15:56:31 +00001489 *cf = pcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001490
Igor Sysoev13933252003-05-29 13:02:09 +00001491 if (rv != NGX_CONF_OK) {
1492 return rv;
1493 }
1494
Igor Sysoevd9d0ca12003-11-21 06:30:49 +00001495 ngx_qsort(cscf->locations.elts, (size_t) cscf->locations.nelts,
Igor Sysoev805d9db2005-02-03 19:33:37 +00001496 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations);
Igor Sysoev13933252003-05-29 13:02:09 +00001497
Igor Sysoeva9830112003-05-19 16:39:14 +00001498 return rv;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001499}
1500
1501
Igor Sysoevaa828612005-02-09 14:31:07 +00001502static char *
1503ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001504{
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001505 char *rv;
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001506 ngx_int_t m;
Igor Sysoevfc5a10a2004-03-09 19:47:07 +00001507 ngx_str_t *value;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001508 ngx_conf_t save;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001509 ngx_http_module_t *module;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001510 ngx_http_conf_ctx_t *ctx, *pctx;
Igor Sysoeva9830112003-05-19 16:39:14 +00001511 ngx_http_core_srv_conf_t *cscf;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001512 ngx_http_core_loc_conf_t *clcf, *pclcf, **clcfp;
Igor Sysoevc0edbcc2004-10-21 15:34:38 +00001513#if (NGX_PCRE)
Igor Sysoevfc5a10a2004-03-09 19:47:07 +00001514 ngx_str_t err;
Igor Sysoev10a543a2004-03-16 07:10:12 +00001515 u_char errstr[NGX_MAX_CONF_ERRSTR];
Igor Sysoevfc5a10a2004-03-09 19:47:07 +00001516#endif
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001517
Igor Sysoevc1571722005-03-19 12:38:37 +00001518 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
1519 if (ctx == NULL) {
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001520 return NGX_CONF_ERROR;
1521 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001522
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001523 pctx = cf->ctx;
1524 ctx->main_conf = pctx->main_conf;
1525 ctx->srv_conf = pctx->srv_conf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001526
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001527 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
1528 if (ctx->loc_conf == NULL) {
1529 return NGX_CONF_ERROR;
1530 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001531
Igor Sysoev6253ca12003-05-27 12:18:54 +00001532 for (m = 0; ngx_modules[m]; m++) {
1533 if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001534 continue;
1535 }
1536
Igor Sysoev6253ca12003-05-27 12:18:54 +00001537 module = ngx_modules[m]->ctx;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001538
1539 if (module->create_loc_conf) {
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001540 ctx->loc_conf[ngx_modules[m]->ctx_index] =
1541 module->create_loc_conf(cf);
1542 if (ctx->loc_conf[ngx_modules[m]->ctx_index] == NULL) {
1543 return NGX_CONF_ERROR;
1544 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001545 }
1546 }
1547
Igor Sysoev6253ca12003-05-27 12:18:54 +00001548 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
Igor Sysoeva9830112003-05-19 16:39:14 +00001549 clcf->loc_conf = ctx->loc_conf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001550
Igor Sysoev3b30a902003-12-25 20:26:58 +00001551 value = cf->args->elts;
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001552
1553 if (cf->args->nelts == 3) {
1554 if (value[1].len == 1 && value[1].data[0] == '=') {
Igor Sysoev2a3f4902004-11-11 20:58:09 +00001555 clcf->name = value[2];
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001556 clcf->exact_match = 1;
1557
Igor Sysoevd43bee82004-11-20 19:52:20 +00001558 } else if (value[1].len == 2
1559 && value[1].data[0] == '^'
1560 && value[1].data[1] == '~')
1561 {
1562 clcf->name = value[2];
1563 clcf->noregex = 1;
1564
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001565 } else if ((value[1].len == 1 && value[1].data[0] == '~')
1566 || (value[1].len == 2
1567 && value[1].data[0] == '~'
1568 && value[1].data[1] == '*'))
1569 {
Igor Sysoevc0edbcc2004-10-21 15:34:38 +00001570#if (NGX_PCRE)
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001571 err.len = NGX_MAX_CONF_ERRSTR;
1572 err.data = errstr;
1573
1574 clcf->regex = ngx_regex_compile(&value[2],
1575 value[1].len == 2 ? NGX_REGEX_CASELESS: 0,
1576 cf->pool, &err);
1577
1578 if (clcf->regex == NULL) {
1579 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
1580 return NGX_CONF_ERROR;
1581 }
1582
Igor Sysoev3b30a902003-12-25 20:26:58 +00001583 clcf->name = value[2];
Igor Sysoevdc867cd2003-12-14 20:10:27 +00001584#else
1585 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00001586 "the using of the regex \"%V\" "
1587 "requires PCRE library", &value[2]);
Igor Sysoevdc867cd2003-12-14 20:10:27 +00001588 return NGX_CONF_ERROR;
1589#endif
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001590
1591 } else {
1592 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00001593 "invalid location modifier \"%V\"", &value[1]);
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001594 return NGX_CONF_ERROR;
1595 }
1596
1597 } else {
Igor Sysoev2a3f4902004-11-11 20:58:09 +00001598 clcf->name = value[1];
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001599 }
1600
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001601 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
1602
1603 if (pclcf->name.len == 0) {
1604 cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
Igor Sysoevc1571722005-03-19 12:38:37 +00001605
1606 clcfp = ngx_array_push(&cscf->locations);
1607 if (clcfp == NULL) {
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001608 return NGX_CONF_ERROR;
1609 }
1610
1611 } else {
Igor Sysoev805d9db2005-02-03 19:33:37 +00001612#if 0
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001613 clcf->prev_location = pclcf;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001614#endif
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001615
1616 if (pclcf->exact_match) {
1617 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00001618 "location \"%V\" could not be inside "
1619 "the exact location \"%V\"",
1620 &clcf->name, &pclcf->name);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001621 return NGX_CONF_ERROR;
1622 }
1623
Igor Sysoevc0edbcc2004-10-21 15:34:38 +00001624#if (NGX_PCRE)
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001625 if (clcf->regex == NULL
1626 && ngx_strncmp(clcf->name.data, pclcf->name.data, pclcf->name.len)
1627 != 0)
Igor Sysoevea521232004-07-26 16:21:18 +00001628#else
1629 if (ngx_strncmp(clcf->name.data, pclcf->name.data, pclcf->name.len)
1630 != 0)
1631#endif
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001632 {
1633 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00001634 "location \"%V\" is outside location \"%V\"",
1635 &clcf->name, &pclcf->name);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001636 return NGX_CONF_ERROR;
1637 }
1638
1639 if (pclcf->locations.elts == NULL) {
Igor Sysoevc1571722005-03-19 12:38:37 +00001640 if (ngx_array_init(&pclcf->locations, cf->pool, 4, sizeof(void *))
1641 != NGX_OK)
1642 {
1643 return NGX_CONF_ERROR;
1644 }
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001645 }
1646
Igor Sysoevc1571722005-03-19 12:38:37 +00001647 clcfp = ngx_array_push(&pclcf->locations);
1648 if (clcfp == NULL) {
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001649 return NGX_CONF_ERROR;
1650 }
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001651 }
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001652
Igor Sysoeva9830112003-05-19 16:39:14 +00001653 *clcfp = clcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001654
Igor Sysoev805d9db2005-02-03 19:33:37 +00001655 save = *cf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001656 cf->ctx = ctx;
Igor Sysoev79a80482003-05-14 17:13:13 +00001657 cf->cmd_type = NGX_HTTP_LOC_CONF;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001658
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001659 rv = ngx_conf_parse(cf, NULL);
Igor Sysoev805d9db2005-02-03 19:33:37 +00001660
1661 *cf = save;
1662
1663 if (rv != NGX_CONF_OK) {
1664 return rv;
1665 }
1666
1667 ngx_qsort(clcf->locations.elts, (size_t) clcf->locations.nelts,
1668 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations);
Igor Sysoev79a80482003-05-14 17:13:13 +00001669
1670 return rv;
1671}
1672
1673
Igor Sysoev4d656dc2005-03-22 16:02:46 +00001674static int ngx_libc_cdecl
Igor Sysoevaa828612005-02-09 14:31:07 +00001675ngx_http_core_cmp_locations(const void *one, const void *two)
Igor Sysoev805d9db2005-02-03 19:33:37 +00001676{
1677 ngx_int_t rc;
1678 ngx_http_core_loc_conf_t *first, *second;
1679
1680 first = *(ngx_http_core_loc_conf_t **) one;
1681 second = *(ngx_http_core_loc_conf_t **) two;
1682
1683 if (first->noname && !second->noname) {
1684 /* shift no named locations to the end */
1685 return 1;
1686 }
1687
1688 if (!first->noname && second->noname) {
1689 /* shift no named locations to the end */
1690 return -1;
1691 }
1692
1693 if (first->noname || second->noname) {
1694 /* do not sort no named locations */
1695 return 0;
1696 }
1697
1698#if (NGX_PCRE)
1699
1700 if (first->regex && !second->regex) {
1701 /* shift the regex matches to the end */
1702 return 1;
1703 }
1704
1705 if (!first->regex && second->regex) {
1706 /* shift the regex matches to the end */
1707 return -1;
1708 }
1709
1710 if (first->regex || second->regex) {
1711 /* do not sort the regex matches */
1712 return 0;
1713 }
1714
1715#endif
1716
1717 rc = ngx_strcmp(first->name.data, second->name.data);
1718
1719 if (rc == 0 && second->exact_match) {
1720 /* an exact match must be before the same inclusive one */
1721 return 1;
1722 }
1723
1724 return (int) rc;
1725}
1726
1727
Igor Sysoevaa828612005-02-09 14:31:07 +00001728static char *
1729ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev79a80482003-05-14 17:13:13 +00001730{
Igor Sysoev7bdb7202006-04-19 15:30:56 +00001731 ngx_http_core_loc_conf_t *lcf = conf;
1732
Igor Sysoevaa3436c2003-05-30 14:27:59 +00001733 char *rv;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001734 ngx_conf_t save;
Igor Sysoevaa3436c2003-05-30 14:27:59 +00001735
Igor Sysoev7bdb7202006-04-19 15:30:56 +00001736 if (lcf->types == NULL) {
1737 lcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t));
1738 if (lcf->types == NULL) {
1739 return NGX_CONF_ERROR;
1740 }
1741 }
1742
Igor Sysoev805d9db2005-02-03 19:33:37 +00001743 save = *cf;
1744 cf->handler = ngx_http_core_type;
Igor Sysoevaa3436c2003-05-30 14:27:59 +00001745 cf->handler_conf = conf;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001746
Igor Sysoevaa3436c2003-05-30 14:27:59 +00001747 rv = ngx_conf_parse(cf, NULL);
Igor Sysoev805d9db2005-02-03 19:33:37 +00001748
1749 *cf = save;
Igor Sysoevaa3436c2003-05-30 14:27:59 +00001750
1751 return rv;
1752}
1753
1754
Igor Sysoevaa828612005-02-09 14:31:07 +00001755static char *
1756ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
Igor Sysoevaa3436c2003-05-30 14:27:59 +00001757{
1758 ngx_http_core_loc_conf_t *lcf = conf;
Igor Sysoev79a80482003-05-14 17:13:13 +00001759
Igor Sysoev24025022005-12-16 15:07:08 +00001760 ngx_str_t *value, *content_type, *old;
1761 ngx_uint_t i, n;
1762 ngx_hash_key_t *type;
Igor Sysoev79a80482003-05-14 17:13:13 +00001763
Igor Sysoev24025022005-12-16 15:07:08 +00001764 content_type = ngx_palloc(cf->pool, sizeof(ngx_str_t));
1765 if (content_type == NULL) {
1766 return NGX_CONF_ERROR;
Igor Sysoev79a80482003-05-14 17:13:13 +00001767 }
1768
Igor Sysoev805d9db2005-02-03 19:33:37 +00001769 value = cf->args->elts;
Igor Sysoev24025022005-12-16 15:07:08 +00001770 *content_type = value[0];
Igor Sysoev79a80482003-05-14 17:13:13 +00001771
1772 for (i = 1; i < cf->args->nelts; i++) {
Igor Sysoev79a80482003-05-14 17:13:13 +00001773
Igor Sysoev24025022005-12-16 15:07:08 +00001774 for (n = 0; n < value[i].len; n++) {
1775 value[i].data[n] = ngx_tolower(value[i].data[n]);
1776 }
1777
1778 type = lcf->types->elts;
1779 for (n = 0; n < lcf->types->nelts; n++) {
1780 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) {
1781 old = type[n].value;
1782 type[n].value = content_type;
1783
1784 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
1785 "duplicate extention \"%V\", "
1786 "content type: \"%V\", "
1787 "old content type: \"%V\"",
1788 &value[i], content_type, old);
1789 continue;
1790 }
1791 }
1792
1793
1794 type = ngx_array_push(lcf->types);
Igor Sysoevc1571722005-03-19 12:38:37 +00001795 if (type == NULL) {
Igor Sysoevdc3b2a72004-09-14 19:39:54 +00001796 return NGX_CONF_ERROR;
1797 }
1798
Igor Sysoev24025022005-12-16 15:07:08 +00001799 type->key = value[i];
1800 type->key_hash = ngx_hash_key(value[i].data, value[i].len);
1801 type->value = content_type;
Igor Sysoev79a80482003-05-14 17:13:13 +00001802 }
1803
1804 return NGX_CONF_OK;
1805}
1806
1807
Igor Sysoev899b44e2005-05-12 14:58:06 +00001808static ngx_int_t
1809ngx_http_core_preconfiguration(ngx_conf_t *cf)
1810{
1811 return ngx_http_variables_add_core_vars(cf);
1812}
1813
1814
Igor Sysoevaa828612005-02-09 14:31:07 +00001815static void *
1816ngx_http_core_create_main_conf(ngx_conf_t *cf)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001817{
Igor Sysoev805d9db2005-02-03 19:33:37 +00001818 ngx_http_core_main_conf_t *cmcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001819
Igor Sysoevc1571722005-03-19 12:38:37 +00001820 cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t));
1821 if (cmcf == NULL) {
Igor Sysoev805d9db2005-02-03 19:33:37 +00001822 return NGX_CONF_ERROR;
1823 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001824
Igor Sysoev8184d1b2005-03-04 14:06:57 +00001825 if (ngx_array_init(&cmcf->servers, cf->pool, 4,
Igor Sysoev9ac946b2005-10-24 15:09:41 +00001826 sizeof(ngx_http_core_srv_conf_t *))
Igor Sysoev6f134cc2006-05-23 14:54:58 +00001827 != NGX_OK)
Igor Sysoev805d9db2005-02-03 19:33:37 +00001828 {
1829 return NGX_CONF_ERROR;
1830 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001831
Igor Sysoev305a9d82005-12-26 17:07:48 +00001832 cmcf->server_names_hash_max_size = NGX_CONF_UNSET_UINT;
1833 cmcf->server_names_hash_bucket_size = NGX_CONF_UNSET_UINT;
Igor Sysoevb1dfe472004-12-21 12:30:30 +00001834
Igor Sysoevffe71442006-02-08 15:33:12 +00001835 cmcf->variables_hash_max_size = NGX_CONF_UNSET_UINT;
1836 cmcf->variables_hash_bucket_size = NGX_CONF_UNSET_UINT;
1837
Igor Sysoeva9830112003-05-19 16:39:14 +00001838 return cmcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001839}
1840
1841
Igor Sysoevaa828612005-02-09 14:31:07 +00001842static char *
1843ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001844{
Igor Sysoev6253ca12003-05-27 12:18:54 +00001845 ngx_http_core_main_conf_t *cmcf = conf;
Igor Sysoeva9830112003-05-19 16:39:14 +00001846
Igor Sysoev305a9d82005-12-26 17:07:48 +00001847 if (cmcf->server_names_hash_max_size == NGX_CONF_UNSET_UINT) {
1848 cmcf->server_names_hash_max_size = 512;
Igor Sysoevb1dfe472004-12-21 12:30:30 +00001849 }
1850
Igor Sysoev305a9d82005-12-26 17:07:48 +00001851 if (cmcf->server_names_hash_bucket_size == NGX_CONF_UNSET_UINT) {
1852 cmcf->server_names_hash_bucket_size = ngx_cacheline_size;
Igor Sysoevb1dfe472004-12-21 12:30:30 +00001853 }
Igor Sysoeva9830112003-05-19 16:39:14 +00001854
Igor Sysoev305a9d82005-12-26 17:07:48 +00001855 cmcf->server_names_hash_bucket_size =
1856 ngx_align(cmcf->server_names_hash_bucket_size, ngx_cacheline_size);
1857
Igor Sysoevffe71442006-02-08 15:33:12 +00001858
1859 if (cmcf->variables_hash_max_size == NGX_CONF_UNSET_UINT) {
1860 cmcf->variables_hash_max_size = 512;
1861 }
1862
1863 if (cmcf->variables_hash_bucket_size == NGX_CONF_UNSET_UINT) {
1864 cmcf->variables_hash_bucket_size = 64;
1865 }
1866
1867 cmcf->variables_hash_bucket_size =
1868 ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size);
1869
Igor Sysoeva9830112003-05-19 16:39:14 +00001870 return NGX_CONF_OK;
1871}
1872
1873
Igor Sysoevaa828612005-02-09 14:31:07 +00001874static void *
1875ngx_http_core_create_srv_conf(ngx_conf_t *cf)
Igor Sysoeva9830112003-05-19 16:39:14 +00001876{
1877 ngx_http_core_srv_conf_t *cscf;
1878
Igor Sysoevc1571722005-03-19 12:38:37 +00001879 cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t));
1880 if (cscf == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00001881 return NGX_CONF_ERROR;
1882 }
1883
Igor Sysoev85080d02004-09-22 16:18:21 +00001884 /*
Igor Sysoev02025fd2005-01-18 13:03:58 +00001885 * set by ngx_pcalloc():
Igor Sysoevaa828612005-02-09 14:31:07 +00001886 *
Igor Sysoev02025fd2005-01-18 13:03:58 +00001887 * conf->client_large_buffers.num = 0;
1888 */
Igor Sysoev85080d02004-09-22 16:18:21 +00001889
Igor Sysoev8184d1b2005-03-04 14:06:57 +00001890 if (ngx_array_init(&cscf->locations, cf->pool, 4, sizeof(void *))
Igor Sysoev305a9d82005-12-26 17:07:48 +00001891 == NGX_ERROR)
Igor Sysoevaa828612005-02-09 14:31:07 +00001892 {
1893 return NGX_CONF_ERROR;
1894 }
1895
Igor Sysoev8184d1b2005-03-04 14:06:57 +00001896 if (ngx_array_init(&cscf->listen, cf->pool, 4, sizeof(ngx_http_listen_t))
Igor Sysoev305a9d82005-12-26 17:07:48 +00001897 == NGX_ERROR)
Igor Sysoevaa828612005-02-09 14:31:07 +00001898 {
1899 return NGX_CONF_ERROR;
1900 }
1901
Igor Sysoev8184d1b2005-03-04 14:06:57 +00001902 if (ngx_array_init(&cscf->server_names, cf->pool, 4,
Igor Sysoev305a9d82005-12-26 17:07:48 +00001903 sizeof(ngx_http_server_name_t))
1904 == NGX_ERROR)
Igor Sysoevaa828612005-02-09 14:31:07 +00001905 {
1906 return NGX_CONF_ERROR;
1907 }
Igor Sysoeva9830112003-05-19 16:39:14 +00001908
Igor Sysoev10a543a2004-03-16 07:10:12 +00001909 cscf->connection_pool_size = NGX_CONF_UNSET_SIZE;
Igor Sysoev10a543a2004-03-16 07:10:12 +00001910 cscf->request_pool_size = NGX_CONF_UNSET_SIZE;
1911 cscf->client_header_timeout = NGX_CONF_UNSET_MSEC;
1912 cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE;
Igor Sysoev8290d282006-02-03 12:58:48 +00001913 cscf->optimize_server_names = NGX_CONF_UNSET;
Igor Sysoev3362b8d2005-05-14 18:42:03 +00001914 cscf->ignore_invalid_headers = NGX_CONF_UNSET;
Igor Sysoev187fcd82003-05-23 11:53:01 +00001915
Igor Sysoeva9830112003-05-19 16:39:14 +00001916 return cscf;
1917}
1918
1919
Igor Sysoevaa828612005-02-09 14:31:07 +00001920static char *
1921ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
Igor Sysoeva9830112003-05-19 16:39:14 +00001922{
Igor Sysoevaa3436c2003-05-30 14:27:59 +00001923 ngx_http_core_srv_conf_t *prev = parent;
1924 ngx_http_core_srv_conf_t *conf = child;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001925
Igor Sysoev305a9d82005-12-26 17:07:48 +00001926 ngx_http_listen_t *ls;
1927 ngx_http_server_name_t *sn;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001928
Igor Sysoev7578ec92003-06-02 15:24:30 +00001929 /* TODO: it does not merge, it inits only */
Igor Sysoeva9830112003-05-19 16:39:14 +00001930
1931 if (conf->listen.nelts == 0) {
Igor Sysoevc1571722005-03-19 12:38:37 +00001932 ls = ngx_array_push(&conf->listen);
1933 if (ls == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00001934 return NGX_CONF_ERROR;
1935 }
1936
Igor Sysoevb145b062005-06-15 18:33:41 +00001937 ngx_memzero(ls, sizeof(ngx_http_listen_t));
1938
Igor Sysoevaa828612005-02-09 14:31:07 +00001939 ls->addr = INADDR_ANY;
Igor Sysoev1b735832004-11-11 14:07:14 +00001940#if (NGX_WIN32)
Igor Sysoevaa828612005-02-09 14:31:07 +00001941 ls->port = 80;
Igor Sysoev1c104622003-06-03 15:42:58 +00001942#else
Igor Sysoev7578ec92003-06-02 15:24:30 +00001943 /* STUB: getuid() should be cached */
Igor Sysoevaa828612005-02-09 14:31:07 +00001944 ls->port = (getuid() == 0) ? 80 : 8000;
Igor Sysoev1c104622003-06-03 15:42:58 +00001945#endif
Igor Sysoevaa828612005-02-09 14:31:07 +00001946 ls->family = AF_INET;
Igor Sysoev9ac946b2005-10-24 15:09:41 +00001947
1948 ls->conf.backlog = -1;
1949 ls->conf.rcvbuf = -1;
1950 ls->conf.sndbuf = -1;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001951 }
1952
Igor Sysoev9e580192006-02-01 18:22:15 +00001953 if (conf->server_name.data == NULL) {
1954 conf->server_name.data = ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN);
1955 if (conf->server_name.data == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00001956 return NGX_CONF_ERROR;
1957 }
Igor Sysoev13933252003-05-29 13:02:09 +00001958
Igor Sysoev9e580192006-02-01 18:22:15 +00001959 if (gethostname((char *) conf->server_name.data, NGX_MAXHOSTNAMELEN)
1960 == -1)
1961 {
Igor Sysoev8e1fbe62003-07-18 14:44:05 +00001962 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
1963 "gethostname() failed");
1964 return NGX_CONF_ERROR;
Igor Sysoevad22e012003-01-15 07:02:27 +00001965 }
Igor Sysoev13933252003-05-29 13:02:09 +00001966
Igor Sysoev9e580192006-02-01 18:22:15 +00001967 conf->server_name.len = ngx_strlen(conf->server_name.data);
1968
1969 sn = ngx_array_push(&conf->server_names);
1970 if (sn == NULL) {
1971 return NGX_CONF_ERROR;
1972 }
1973
1974 sn->name.len = conf->server_name.len;
1975 sn->name.data = conf->server_name.data;
Igor Sysoevaa828612005-02-09 14:31:07 +00001976 sn->core_srv_conf = conf;
Igor Sysoevad22e012003-01-15 07:02:27 +00001977 }
1978
Igor Sysoev239baac2003-06-11 15:28:34 +00001979 ngx_conf_merge_size_value(conf->connection_pool_size,
Igor Sysoev8035fd22004-10-01 15:53:53 +00001980 prev->connection_pool_size, 256);
Igor Sysoev187fcd82003-05-23 11:53:01 +00001981 ngx_conf_merge_size_value(conf->request_pool_size,
Igor Sysoev8035fd22004-10-01 15:53:53 +00001982 prev->request_pool_size, 4096);
Igor Sysoev187fcd82003-05-23 11:53:01 +00001983 ngx_conf_merge_msec_value(conf->client_header_timeout,
1984 prev->client_header_timeout, 60000);
1985 ngx_conf_merge_size_value(conf->client_header_buffer_size,
1986 prev->client_header_buffer_size, 1024);
Igor Sysoevf7abd722004-09-23 06:32:00 +00001987 ngx_conf_merge_bufs_value(conf->large_client_header_buffers,
1988 prev->large_client_header_buffers,
1989 4, ngx_pagesize);
1990
1991 if (conf->large_client_header_buffers.size < conf->connection_pool_size) {
1992 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1993 "the \"large_client_header_buffers\" size must be "
1994 "equal to or bigger than \"connection_pool_size\"");
1995 return NGX_CONF_ERROR;
1996 }
1997
Igor Sysoev8290d282006-02-03 12:58:48 +00001998 ngx_conf_merge_value(conf->optimize_server_names,
1999 prev->optimize_server_names, 1);
Igor Sysoev34303462006-01-24 16:08:27 +00002000
Igor Sysoev3362b8d2005-05-14 18:42:03 +00002001 ngx_conf_merge_value(conf->ignore_invalid_headers,
2002 prev->ignore_invalid_headers, 1);
2003
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002004 return NGX_CONF_OK;
2005}
2006
2007
Igor Sysoevaa828612005-02-09 14:31:07 +00002008static void *
2009ngx_http_core_create_loc_conf(ngx_conf_t *cf)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002010{
Igor Sysoev805d9db2005-02-03 19:33:37 +00002011 ngx_http_core_loc_conf_t *lcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002012
Igor Sysoevc1571722005-03-19 12:38:37 +00002013 lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t));
2014 if (lcf == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002015 return NGX_CONF_ERROR;
2016 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002017
Igor Sysoev02025fd2005-01-18 13:03:58 +00002018 /*
2019 * set by ngx_pcalloc():
2020 *
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00002021 * lcf->root = { 0, NULL };
Igor Sysoev94e32ce2006-04-07 14:08:04 +00002022 * lcf->limit_except = 0;
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00002023 * lcf->post_action = { 0, NULL };
Igor Sysoev02025fd2005-01-18 13:03:58 +00002024 * lcf->types = NULL;
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00002025 * lcf->default_type = { 0, NULL };
Igor Sysoev02025fd2005-01-18 13:03:58 +00002026 * lcf->err_log = NULL;
2027 * lcf->error_pages = NULL;
2028 * lcf->client_body_path = NULL;
2029 * lcf->regex = NULL;
2030 * lcf->exact_match = 0;
2031 * lcf->auto_redirect = 0;
2032 * lcf->alias = 0;
2033 */
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002034
Igor Sysoev1765f472006-07-07 16:33:19 +00002035 lcf->client_max_body_size = NGX_CONF_UNSET;
Igor Sysoevdbb27762004-04-01 16:20:53 +00002036 lcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE;
Igor Sysoev10a543a2004-03-16 07:10:12 +00002037 lcf->client_body_timeout = NGX_CONF_UNSET_MSEC;
Igor Sysoev31eb8c02005-09-23 11:02:22 +00002038 lcf->satisfy_any = NGX_CONF_UNSET;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002039 lcf->internal = NGX_CONF_UNSET;
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +00002040 lcf->client_body_in_file_only = NGX_CONF_UNSET;
Igor Sysoev5bf3d252003-10-22 07:05:29 +00002041 lcf->sendfile = NGX_CONF_UNSET;
Igor Sysoev3c3ca172004-01-05 20:55:48 +00002042 lcf->tcp_nopush = NGX_CONF_UNSET;
Igor Sysoev924bd792004-10-11 15:07:03 +00002043 lcf->tcp_nodelay = NGX_CONF_UNSET;
Igor Sysoev10a543a2004-03-16 07:10:12 +00002044 lcf->send_timeout = NGX_CONF_UNSET_MSEC;
2045 lcf->send_lowat = NGX_CONF_UNSET_SIZE;
Igor Sysoev7823cc32004-07-14 16:01:42 +00002046 lcf->postpone_output = NGX_CONF_UNSET_SIZE;
2047 lcf->limit_rate = NGX_CONF_UNSET_SIZE;
Igor Sysoev10a543a2004-03-16 07:10:12 +00002048 lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
Igor Sysoev307c3ad2004-09-17 16:07:35 +00002049 lcf->keepalive_header = NGX_CONF_UNSET;
Igor Sysoev10a543a2004-03-16 07:10:12 +00002050 lcf->lingering_time = NGX_CONF_UNSET_MSEC;
2051 lcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
Igor Sysoev0ab91b92004-06-06 19:49:18 +00002052 lcf->reset_timedout_connection = NGX_CONF_UNSET;
Igor Sysoev7b190b42005-06-07 15:56:31 +00002053 lcf->port_in_redirect = NGX_CONF_UNSET;
Igor Sysoev12b4b002003-10-24 06:53:41 +00002054 lcf->msie_padding = NGX_CONF_UNSET;
Igor Sysoev5192b362005-07-08 14:34:20 +00002055 lcf->log_not_found = NGX_CONF_UNSET;
Igor Sysoev24025022005-12-16 15:07:08 +00002056 lcf->types_hash_max_size = NGX_CONF_UNSET_UINT;
2057 lcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT;
Igor Sysoev12b4b002003-10-24 06:53:41 +00002058
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002059 return lcf;
2060}
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002061
Igor Sysoev79a80482003-05-14 17:13:13 +00002062
Igor Sysoev24025022005-12-16 15:07:08 +00002063static ngx_str_t ngx_http_core_text_html_type = ngx_string("text/html");
2064static ngx_str_t ngx_http_core_image_gif_type = ngx_string("image/gif");
2065static ngx_str_t ngx_http_core_image_jpeg_type = ngx_string("image/jpeg");
2066
2067static ngx_hash_key_t ngx_http_core_default_types[] = {
2068 { ngx_string("html"), 0, &ngx_http_core_text_html_type },
2069 { ngx_string("gif"), 0, &ngx_http_core_image_gif_type },
2070 { ngx_string("jpg"), 0, &ngx_http_core_image_jpeg_type },
2071 { ngx_null_string, 0, NULL }
Igor Sysoev79a80482003-05-14 17:13:13 +00002072};
2073
2074
Igor Sysoevaa828612005-02-09 14:31:07 +00002075static char *
Igor Sysoev24025022005-12-16 15:07:08 +00002076ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
Igor Sysoeve2a31542003-04-08 15:40:10 +00002077{
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002078 ngx_http_core_loc_conf_t *prev = parent;
2079 ngx_http_core_loc_conf_t *conf = child;
Igor Sysoev79a80482003-05-14 17:13:13 +00002080
Igor Sysoevaa828612005-02-09 14:31:07 +00002081 ngx_uint_t i;
Igor Sysoev24025022005-12-16 15:07:08 +00002082 ngx_hash_key_t *type;
2083 ngx_hash_init_t types_hash;
Igor Sysoev79a80482003-05-14 17:13:13 +00002084
Igor Sysoev34303462006-01-24 16:08:27 +00002085 if (conf->root.data == NULL) {
Igor Sysoev79a80482003-05-14 17:13:13 +00002086
Igor Sysoev455a7fc2006-03-21 08:20:41 +00002087 conf->alias = prev->alias;
Igor Sysoev34303462006-01-24 16:08:27 +00002088 conf->root = prev->root;
2089 conf->root_lengths = prev->root_lengths;
2090 conf->root_values = prev->root_values;
2091
2092 if (prev->root.data == NULL) {
2093 conf->root.len = sizeof("html") - 1;
2094 conf->root.data = (u_char *) "html";
2095
2096 if (ngx_conf_full_name(cf->cycle, &conf->root) == NGX_ERROR) {
2097 return NGX_CONF_ERROR;
2098 }
2099 }
Igor Sysoev6d2a14a2004-09-27 16:03:21 +00002100 }
2101
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00002102 if (conf->post_action.data == NULL) {
2103 conf->post_action = prev->post_action;
2104 }
2105
Igor Sysoev1765f472006-07-07 16:33:19 +00002106 ngx_conf_merge_uint_value(conf->types_hash_max_size,
2107 prev->types_hash_max_size, 1024);
Igor Sysoev79a80482003-05-14 17:13:13 +00002108
Igor Sysoev1765f472006-07-07 16:33:19 +00002109 ngx_conf_merge_uint_value(conf->types_hash_bucket_size,
2110 prev->types_hash_bucket_size,
2111 ngx_cacheline_size);
Igor Sysoev24025022005-12-16 15:07:08 +00002112
2113 conf->types_hash_bucket_size = ngx_align(conf->types_hash_bucket_size,
2114 ngx_cacheline_size);
2115
2116 /*
2117 * the special handling the "types" directive in the "http" section
2118 * to inherit the http's conf->types_hash to all servers
2119 */
2120
2121 if (prev->types && prev->types_hash.buckets == NULL) {
2122
2123 types_hash.hash = &prev->types_hash;
2124 types_hash.key = ngx_hash_key_lc;
2125 types_hash.max_size = conf->types_hash_max_size;
2126 types_hash.bucket_size = conf->types_hash_bucket_size;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00002127 types_hash.name = "types_hash";
Igor Sysoev24025022005-12-16 15:07:08 +00002128 types_hash.pool = cf->pool;
2129 types_hash.temp_pool = NULL;
2130
2131 if (ngx_hash_init(&types_hash, prev->types->elts, prev->types->nelts)
2132 != NGX_OK)
2133 {
2134 return NGX_CONF_ERROR;
2135 }
2136 }
2137
2138 if (conf->types == NULL) {
2139 conf->types = prev->types;
2140 conf->types_hash = prev->types_hash;
2141 }
2142
2143 if (conf->types == NULL) {
2144 conf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_hash_key_t));
2145 if (conf->types == NULL) {
2146 return NGX_CONF_ERROR;
2147 }
2148
2149 for (i = 0; ngx_http_core_default_types[i].key.len; i++) {
2150 type = ngx_array_push(conf->types);
2151 if (type == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002152 return NGX_CONF_ERROR;
Igor Sysoev79a80482003-05-14 17:13:13 +00002153 }
2154
Igor Sysoev24025022005-12-16 15:07:08 +00002155 type->key = ngx_http_core_default_types[i].key;
2156 type->key_hash =
2157 ngx_hash_key_lc(ngx_http_core_default_types[i].key.data,
2158 ngx_http_core_default_types[i].key.len);
2159 type->value = ngx_http_core_default_types[i].value;
2160 }
2161 }
Igor Sysoev79a80482003-05-14 17:13:13 +00002162
Igor Sysoev24025022005-12-16 15:07:08 +00002163 if (conf->types_hash.buckets == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002164
Igor Sysoev24025022005-12-16 15:07:08 +00002165 types_hash.hash = &conf->types_hash;
2166 types_hash.key = ngx_hash_key_lc;
2167 types_hash.max_size = conf->types_hash_max_size;
2168 types_hash.bucket_size = conf->types_hash_bucket_size;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00002169 types_hash.name = "mime_types_hash";
Igor Sysoev24025022005-12-16 15:07:08 +00002170 types_hash.pool = cf->pool;
2171 types_hash.temp_pool = NULL;
Igor Sysoevaa828612005-02-09 14:31:07 +00002172
Igor Sysoev24025022005-12-16 15:07:08 +00002173 if (ngx_hash_init(&types_hash, conf->types->elts, conf->types->nelts)
2174 != NGX_OK)
2175 {
2176 return NGX_CONF_ERROR;
Igor Sysoev79a80482003-05-14 17:13:13 +00002177 }
2178 }
2179
Igor Sysoev890fc962003-07-20 21:15:59 +00002180 if (conf->err_log == NULL) {
2181 if (prev->err_log) {
2182 conf->err_log = prev->err_log;
2183 } else {
Igor Sysoev630ad0c2004-04-16 05:14:16 +00002184 conf->err_log = cf->cycle->new_log;
Igor Sysoev890fc962003-07-20 21:15:59 +00002185 }
2186 }
2187
Igor Sysoev74e95c22003-11-09 20:03:38 +00002188 if (conf->error_pages == NULL && prev->error_pages) {
2189 conf->error_pages = prev->error_pages;
2190 }
2191
Igor Sysoev6253ca12003-05-27 12:18:54 +00002192 ngx_conf_merge_str_value(conf->default_type,
Igor Sysoevaa828612005-02-09 14:31:07 +00002193 prev->default_type, "text/plain");
Igor Sysoev6253ca12003-05-27 12:18:54 +00002194
Igor Sysoev1765f472006-07-07 16:33:19 +00002195 ngx_conf_merge_off_value(conf->client_max_body_size,
Igor Sysoev8035fd22004-10-01 15:53:53 +00002196 prev->client_max_body_size, 1 * 1024 * 1024);
Igor Sysoevdbb27762004-04-01 16:20:53 +00002197 ngx_conf_merge_size_value(conf->client_body_buffer_size,
Igor Sysoev8035fd22004-10-01 15:53:53 +00002198 prev->client_body_buffer_size,
2199 (size_t) 2 * ngx_pagesize);
Igor Sysoev2b0c76c2003-10-27 21:01:00 +00002200 ngx_conf_merge_msec_value(conf->client_body_timeout,
Igor Sysoev7af6b162004-02-09 07:46:43 +00002201 prev->client_body_timeout, 60000);
Igor Sysoev899b44e2005-05-12 14:58:06 +00002202
Igor Sysoev31eb8c02005-09-23 11:02:22 +00002203 ngx_conf_merge_value(conf->satisfy_any, prev->satisfy_any, 0);
Igor Sysoev899b44e2005-05-12 14:58:06 +00002204 ngx_conf_merge_value(conf->internal, prev->internal, 0);
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +00002205 ngx_conf_merge_value(conf->client_body_in_file_only,
2206 prev->client_body_in_file_only, 0);
Igor Sysoev5bf3d252003-10-22 07:05:29 +00002207 ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
Igor Sysoev3c3ca172004-01-05 20:55:48 +00002208 ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0);
Igor Sysoev924bd792004-10-11 15:07:03 +00002209 ngx_conf_merge_value(conf->tcp_nodelay, prev->tcp_nodelay, 0);
Igor Sysoev899b44e2005-05-12 14:58:06 +00002210
Igor Sysoev7af6b162004-02-09 07:46:43 +00002211 ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000);
Igor Sysoevb5faed22003-10-29 08:30:44 +00002212 ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0);
Igor Sysoev7823cc32004-07-14 16:01:42 +00002213 ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output,
2214 1460);
2215 ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0);
Igor Sysoev187fcd82003-05-23 11:53:01 +00002216 ngx_conf_merge_msec_value(conf->keepalive_timeout,
Igor Sysoev307c3ad2004-09-17 16:07:35 +00002217 prev->keepalive_timeout, 75000);
2218 ngx_conf_merge_sec_value(conf->keepalive_header,
2219 prev->keepalive_header, 0);
Igor Sysoev187fcd82003-05-23 11:53:01 +00002220 ngx_conf_merge_msec_value(conf->lingering_time,
2221 prev->lingering_time, 30000);
2222 ngx_conf_merge_msec_value(conf->lingering_timeout,
2223 prev->lingering_timeout, 5000);
Igor Sysoev79a80482003-05-14 17:13:13 +00002224
Igor Sysoev02025fd2005-01-18 13:03:58 +00002225 ngx_conf_merge_path_value(conf->client_body_temp_path,
2226 prev->client_body_temp_path,
2227 NGX_HTTP_CLIENT_TEMP_PATH, 0, 0, 0,
2228 ngx_garbage_collector_temp_handler, cf);
2229
Igor Sysoev0ab91b92004-06-06 19:49:18 +00002230 ngx_conf_merge_value(conf->reset_timedout_connection,
Igor Sysoevaa828612005-02-09 14:31:07 +00002231 prev->reset_timedout_connection, 0);
Igor Sysoev7b190b42005-06-07 15:56:31 +00002232 ngx_conf_merge_value(conf->port_in_redirect, prev->port_in_redirect, 1);
Igor Sysoev12b4b002003-10-24 06:53:41 +00002233 ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1);
Igor Sysoev5192b362005-07-08 14:34:20 +00002234 ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1);
Igor Sysoev12b4b002003-10-24 06:53:41 +00002235
Igor Sysoev865c1502003-11-30 20:03:18 +00002236 if (conf->open_files == NULL) {
2237 conf->open_files = prev->open_files;
2238 }
2239
Igor Sysoeve2a31542003-04-08 15:40:10 +00002240 return NGX_CONF_OK;
2241}
2242
Igor Sysoev79a80482003-05-14 17:13:13 +00002243
Igor Sysoevb145b062005-06-15 18:33:41 +00002244/* AF_INET only */
2245
Igor Sysoevaa828612005-02-09 14:31:07 +00002246static char *
2247ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002248{
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002249 ngx_http_core_srv_conf_t *scf = conf;
Igor Sysoeva9830112003-05-19 16:39:14 +00002250
Igor Sysoevb145b062005-06-15 18:33:41 +00002251 char *err;
Igor Sysoevc2068d02005-10-19 12:33:58 +00002252 ngx_str_t *value, size;
Igor Sysoevb145b062005-06-15 18:33:41 +00002253 ngx_uint_t n;
2254 struct hostent *h;
2255 ngx_http_listen_t *ls;
2256 ngx_inet_upstream_t inet_upstream;
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002257
Igor Sysoeve2ff3ea2004-09-14 15:55:24 +00002258 /*
2259 * TODO: check duplicate 'listen' directives,
2260 * add resolved name to server names ???
2261 */
Igor Sysoev6ddfbf02003-05-15 15:42:53 +00002262
Igor Sysoevb145b062005-06-15 18:33:41 +00002263 value = cf->args->elts;
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00002264
Igor Sysoevb145b062005-06-15 18:33:41 +00002265 ngx_memzero(&inet_upstream, sizeof(ngx_inet_upstream_t));
2266
2267 inet_upstream.url = value[1];
2268 inet_upstream.port_only = 1;
2269
2270 err = ngx_inet_parse_host_port(&inet_upstream);
2271
2272 if (err) {
2273 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2274 "%s in \"%V\" of the \"listen\" directive",
2275 err, &inet_upstream.url);
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00002276 return NGX_CONF_ERROR;
Igor Sysoevb145b062005-06-15 18:33:41 +00002277 }
2278
Igor Sysoevc1571722005-03-19 12:38:37 +00002279 ls = ngx_array_push(&scf->listen);
2280 if (ls == NULL) {
Igor Sysoeve2ff3ea2004-09-14 15:55:24 +00002281 return NGX_CONF_ERROR;
2282 }
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002283
Igor Sysoevb145b062005-06-15 18:33:41 +00002284 ngx_memzero(ls, sizeof(ngx_http_listen_t));
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002285
2286 ls->family = AF_INET;
Igor Sysoevb145b062005-06-15 18:33:41 +00002287 ls->port = (in_port_t) (inet_upstream.default_port ?
Igor Sysoevffe71442006-02-08 15:33:12 +00002288 80 : inet_upstream.port);
Igor Sysoevfe5cb6b2003-01-29 07:25:51 +00002289 ls->file_name = cf->conf_file->file.name;
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002290 ls->line = cf->conf_file->line;
Igor Sysoevb145b062005-06-15 18:33:41 +00002291 ls->conf.backlog = -1;
Igor Sysoevc2068d02005-10-19 12:33:58 +00002292 ls->conf.rcvbuf = -1;
2293 ls->conf.sndbuf = -1;
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002294
Igor Sysoev13c68742006-03-10 12:51:52 +00002295 if (inet_upstream.host.len == 1 && inet_upstream.host.data[0] == '*') {
2296 inet_upstream.host.len = 0;
2297 }
2298
Igor Sysoevb145b062005-06-15 18:33:41 +00002299 if (inet_upstream.host.len) {
2300 inet_upstream.host.data[inet_upstream.host.len] = '\0';
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002301
Igor Sysoevb145b062005-06-15 18:33:41 +00002302 ls->addr = inet_addr((const char *) inet_upstream.host.data);
2303
2304 if (ls->addr == INADDR_NONE) {
2305 h = gethostbyname((const char *) inet_upstream.host.data);
2306
2307 if (h == NULL || h->h_addr_list[0] == NULL) {
2308 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2309 "can not resolve host \"%s\" "
2310 "in the \"listen\" directive",
2311 inet_upstream.host.data);
2312 return NGX_CONF_ERROR;
2313 }
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00002314
Igor Sysoevb145b062005-06-15 18:33:41 +00002315 ls->addr = *(in_addr_t *)(h->h_addr_list[0]);
Igor Sysoev6ddfbf02003-05-15 15:42:53 +00002316 }
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002317
Igor Sysoev236e0452004-09-23 16:39:34 +00002318 } else {
Igor Sysoevb145b062005-06-15 18:33:41 +00002319 ls->addr = INADDR_ANY;
Igor Sysoev236e0452004-09-23 16:39:34 +00002320 }
Igor Sysoevf1602632004-09-21 19:55:00 +00002321
Igor Sysoev94e32ce2006-04-07 14:08:04 +00002322 n = ngx_inet_ntop(AF_INET, &ls->addr, ls->conf.addr, INET_ADDRSTRLEN + 6);
2323 ngx_sprintf(&ls->conf.addr[n], ":%ui", ls->port);
2324
Igor Sysoevb145b062005-06-15 18:33:41 +00002325 if (cf->args->nelts == 2) {
2326 return NGX_CONF_OK;
2327 }
Igor Sysoevaa828612005-02-09 14:31:07 +00002328
Igor Sysoevb145b062005-06-15 18:33:41 +00002329 if (ngx_strcmp(value[2].data, "default") == 0) {
2330 ls->conf.default_server = 1;
2331 n = 3;
Igor Sysoev24025022005-12-16 15:07:08 +00002332
Igor Sysoevb145b062005-06-15 18:33:41 +00002333 } else {
2334 n = 2;
2335 }
Igor Sysoev13933252003-05-29 13:02:09 +00002336
Igor Sysoevb145b062005-06-15 18:33:41 +00002337 for ( /* void */ ; n < cf->args->nelts; n++) {
2338
2339 if (ls->conf.default_server == 0) {
Igor Sysoev8e1fbe62003-07-18 14:44:05 +00002340 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoevb145b062005-06-15 18:33:41 +00002341 "\"%V\" parameter can be specified for "
2342 "the default \"listen\" directive only",
2343 &value[n]);
Igor Sysoev8e1fbe62003-07-18 14:44:05 +00002344 return NGX_CONF_ERROR;
Igor Sysoev13933252003-05-29 13:02:09 +00002345 }
2346
Igor Sysoevb145b062005-06-15 18:33:41 +00002347 if (ngx_strcmp(value[n].data, "bind") == 0) {
2348 ls->conf.bind = 1;
2349 continue;
2350 }
2351
Igor Sysoevc2068d02005-10-19 12:33:58 +00002352 if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) {
2353 ls->conf.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8);
Igor Sysoevb145b062005-06-15 18:33:41 +00002354 ls->conf.bind = 1;
2355
2356 if (ls->conf.backlog == NGX_ERROR || ls->conf.backlog == 0) {
2357 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2358 "invalid backlog \"%V\"", &value[n]);
2359 return NGX_CONF_ERROR;
2360 }
2361
2362 continue;
2363 }
2364
Igor Sysoevc2068d02005-10-19 12:33:58 +00002365 if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) {
2366 size.len = value[n].len - 7;
2367 size.data = value[n].data + 7;
2368
2369 ls->conf.rcvbuf = ngx_parse_size(&size);
2370 ls->conf.bind = 1;
2371
2372 if (ls->conf.rcvbuf == NGX_ERROR) {
2373 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2374 "invalid rcvbuf \"%V\"", &value[n]);
2375 return NGX_CONF_ERROR;
2376 }
2377
2378 continue;
2379 }
2380
2381 if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) {
2382 size.len = value[n].len - 7;
2383 size.data = value[n].data + 7;
2384
2385 ls->conf.sndbuf = ngx_parse_size(&size);
2386 ls->conf.bind = 1;
2387
2388 if (ls->conf.sndbuf == NGX_ERROR) {
2389 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2390 "invalid sndbuf \"%V\"", &value[n]);
2391 return NGX_CONF_ERROR;
2392 }
2393
2394 continue;
2395 }
2396
2397 if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) {
Igor Sysoevb145b062005-06-15 18:33:41 +00002398#if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
Igor Sysoevc2068d02005-10-19 12:33:58 +00002399 ls->conf.accept_filter = (char *) &value[n].data[14];
Igor Sysoevb145b062005-06-15 18:33:41 +00002400 ls->conf.bind = 1;
2401#else
2402 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2403 "accept filters \"%V\" are not supported "
2404 "on this platform, ignored",
2405 &value[n]);
2406#endif
2407 continue;
2408 }
2409
2410 if (ngx_strcmp(value[n].data, "deferred") == 0) {
2411#if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
2412 ls->conf.deferred_accept = 1;
2413 ls->conf.bind = 1;
2414#else
2415 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2416 "the deferred accept is not supported "
2417 "on this platform, ignored");
2418#endif
2419 continue;
2420 }
2421
2422 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2423 "the invalid \"%V\" parameter", &value[n]);
2424 return NGX_CONF_ERROR;
Igor Sysoev13933252003-05-29 13:02:09 +00002425 }
2426
2427 return NGX_CONF_OK;
2428}
2429
2430
Igor Sysoevaa828612005-02-09 14:31:07 +00002431static char *
2432ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev13933252003-05-29 13:02:09 +00002433{
Igor Sysoev305a9d82005-12-26 17:07:48 +00002434 ngx_http_core_srv_conf_t *cscf = conf;
Igor Sysoev13933252003-05-29 13:02:09 +00002435
Igor Sysoev305a9d82005-12-26 17:07:48 +00002436 u_char ch;
2437 ngx_str_t *value, name;
2438 ngx_uint_t i;
2439 ngx_http_server_name_t *sn;
Igor Sysoevb1af9bb2004-06-25 14:42:03 +00002440
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002441 value = cf->args->elts;
Igor Sysoev13933252003-05-29 13:02:09 +00002442
Igor Sysoev305a9d82005-12-26 17:07:48 +00002443 ch = value[1].data[0];
2444
2445 if (cscf->server_name.data == NULL && value[1].len) {
2446 if (ch == '*') {
Igor Sysoev8e1fbe62003-07-18 14:44:05 +00002447 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev305a9d82005-12-26 17:07:48 +00002448 "first server name \"%V\" must not be wildcard",
2449 &value[1]);
Igor Sysoev8e1fbe62003-07-18 14:44:05 +00002450 return NGX_CONF_ERROR;
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002451 }
Igor Sysoev13933252003-05-29 13:02:09 +00002452
Igor Sysoev305a9d82005-12-26 17:07:48 +00002453 name = value[1];
2454
2455 if (ch == '.') {
2456 name.len--;
2457 name.data++;
2458 }
2459
2460 cscf->server_name.len = name.len;
2461 cscf->server_name.data = ngx_pstrdup(cf->pool, &name);
2462 if (cscf->server_name.data == NULL) {
2463 return NGX_CONF_ERROR;
2464 }
2465 }
2466
2467 for (i = 1; i < cf->args->nelts; i++) {
2468
2469 ch = value[i].data[0];
2470
Igor Sysoev1765f472006-07-07 16:33:19 +00002471 if (value[i].len == 1 && ch == '*') {
2472 cscf->wildcard = 1;
2473 continue;
2474 }
2475
Igor Sysoev305a9d82005-12-26 17:07:48 +00002476 if (value[i].len == 0
2477 || (ch == '*' && (value[i].len < 3 || value[i].data[1] != '.'))
2478 || (ch == '.' && value[i].len < 2))
2479 {
2480 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2481 "server name \"%V\" is invalid", &value[i]);
2482 return NGX_CONF_ERROR;
2483 }
2484
2485 sn = ngx_array_push(&cscf->server_names);
Igor Sysoevc1571722005-03-19 12:38:37 +00002486 if (sn == NULL) {
Igor Sysoevc0edbcc2004-10-21 15:34:38 +00002487 return NGX_CONF_ERROR;
2488 }
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002489
2490 sn->name.len = value[i].len;
2491 sn->name.data = value[i].data;
Igor Sysoev305a9d82005-12-26 17:07:48 +00002492 sn->core_srv_conf = cscf;
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002493 }
Igor Sysoev13933252003-05-29 13:02:09 +00002494
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002495 return NGX_CONF_OK;
2496}
Igor Sysoev9d639522003-07-07 06:11:50 +00002497
2498
Igor Sysoevaa828612005-02-09 14:31:07 +00002499static char *
2500ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev10a543a2004-03-16 07:10:12 +00002501{
2502 ngx_http_core_loc_conf_t *lcf = conf;
2503
Igor Sysoev3ca233e2005-12-28 14:23:52 +00002504 ngx_str_t *value;
2505 ngx_uint_t alias, n;
2506 ngx_http_script_compile_t sc;
Igor Sysoev10a543a2004-03-16 07:10:12 +00002507
2508 alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0;
2509
2510 if (lcf->root.data) {
Igor Sysoeva741f8d2004-03-30 20:31:58 +00002511
2512 /* the (ngx_uint_t) cast is required by gcc 2.7.2.3 */
2513
2514 if ((ngx_uint_t) lcf->alias == alias) {
Igor Sysoev10a543a2004-03-16 07:10:12 +00002515 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00002516 "\"%V\" directive is duplicate",
2517 &cmd->name);
Igor Sysoev10a543a2004-03-16 07:10:12 +00002518 } else {
2519 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00002520 "\"%V\" directive is duplicate, "
Igor Sysoev10a543a2004-03-16 07:10:12 +00002521 "\"%s\" directive is specified before",
Igor Sysoev1b735832004-11-11 14:07:14 +00002522 &cmd->name, lcf->alias ? "alias" : "root");
Igor Sysoev10a543a2004-03-16 07:10:12 +00002523 }
2524
2525 return NGX_CONF_ERROR;
2526 }
2527
2528 value = cf->args->elts;
2529
2530 lcf->alias = alias;
2531 lcf->root = value[1];
2532
Igor Sysoev71057632004-08-30 19:24:51 +00002533 if (!alias && lcf->root.data[lcf->root.len - 1] == '/') {
2534 lcf->root.len--;
2535 }
2536
Igor Sysoev8f125582006-07-28 15:16:17 +00002537 if (lcf->root.data[0] != '$') {
2538 if (ngx_conf_full_name(cf->cycle, &lcf->root) == NGX_ERROR) {
2539 return NGX_CONF_ERROR;
2540 }
Igor Sysoev34303462006-01-24 16:08:27 +00002541 }
2542
2543 n = ngx_http_script_variables_count(&lcf->root);
Igor Sysoev3ca233e2005-12-28 14:23:52 +00002544
2545 if (n == 0) {
2546 return NGX_CONF_OK;
2547 }
2548
2549 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
2550
2551 sc.cf = cf;
Igor Sysoev34303462006-01-24 16:08:27 +00002552 sc.source = &lcf->root;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00002553 sc.lengths = &lcf->root_lengths;
2554 sc.values = &lcf->root_values;
2555 sc.variables = n;
2556 sc.complete_lengths = 1;
2557 sc.complete_values = 1;
2558
2559 if (ngx_http_script_compile(&sc) != NGX_OK) {
2560 return NGX_CONF_ERROR;
2561 }
2562
Igor Sysoev10a543a2004-03-16 07:10:12 +00002563 return NGX_CONF_OK;
2564}
2565
2566
Igor Sysoev94e32ce2006-04-07 14:08:04 +00002567static ngx_http_method_name_t ngx_methods_names[] = {
2568 { "GET", (uint32_t) ~NGX_HTTP_GET },
2569 { "HEAD", (uint32_t) ~NGX_HTTP_HEAD },
Igor Sysoev7f7846d2006-04-26 09:52:47 +00002570 { "POST", (uint32_t) ~NGX_HTTP_POST },
Igor Sysoev94e32ce2006-04-07 14:08:04 +00002571 { NULL, 0 }
2572};
2573
2574
2575static char *
2576ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2577{
2578 ngx_http_core_loc_conf_t *clcf = conf;
2579
2580 char *rv;
2581 void *mconf;
2582 ngx_str_t *value;
2583 ngx_uint_t i;
2584 ngx_conf_t save;
2585 ngx_http_module_t *module;
2586 ngx_http_conf_ctx_t *ctx, *pctx;
2587 ngx_http_method_name_t *name;
2588 ngx_http_core_loc_conf_t *lcf, **clcfp;
2589
2590 if (clcf->limit_except) {
2591 return "duplicate";
2592 }
2593
2594 clcf->limit_except = 0xffffffff;
2595
2596 value = cf->args->elts;
2597
2598 for (i = 1; i < cf->args->nelts; i++) {
2599 for (name = ngx_methods_names; name->name; name++) {
2600
2601 if (ngx_strcasecmp(value[i].data, name->name) == 0) {
2602 clcf->limit_except &= name->method;
2603 goto next;
2604 }
2605 }
2606
2607 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2608 "invalid method \"%V\"", &value[i]);
2609 return NGX_CONF_ERROR;
2610
2611 next:
2612 continue;
2613 }
2614
2615 if (!(clcf->limit_except & NGX_HTTP_GET)) {
2616 clcf->limit_except &= (uint32_t) ~NGX_HTTP_HEAD;
2617 }
2618
2619 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
2620 if (ctx == NULL) {
2621 return NGX_CONF_ERROR;
2622 }
2623
2624 pctx = cf->ctx;
2625 ctx->main_conf = pctx->main_conf;
2626 ctx->srv_conf = pctx->srv_conf;
2627
2628 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2629 if (ctx->loc_conf == NULL) {
2630 return NGX_CONF_ERROR;
2631 }
2632
2633 for (i = 0; ngx_modules[i]; i++) {
2634 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
2635 continue;
2636 }
2637
2638 module = ngx_modules[i]->ctx;
2639
2640 if (module->create_loc_conf) {
2641
2642 mconf = module->create_loc_conf(cf);
2643 if (mconf == NULL) {
2644 return NGX_CONF_ERROR;
2645 }
2646
2647 ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
2648 }
2649 }
2650
2651
2652 lcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
2653 clcf->limit_except_loc_conf = ctx->loc_conf;
2654 lcf->loc_conf = ctx->loc_conf;
2655 lcf->name = clcf->name;
2656 lcf->noname = 1;
2657
2658 if (clcf->locations.elts == NULL) {
2659 if (ngx_array_init(&clcf->locations, cf->pool, 4, sizeof(void *))
2660 == NGX_ERROR)
2661 {
2662 return NGX_CONF_ERROR;
2663 }
2664 }
2665
2666 clcfp = ngx_array_push(&clcf->locations);
2667 if (clcfp == NULL) {
2668 return NGX_CONF_ERROR;
2669 }
2670
2671 *clcfp = lcf;
2672
2673
2674 save = *cf;
2675 cf->ctx = ctx;
2676 cf->cmd_type = NGX_HTTP_LMT_CONF;
2677
2678 rv = ngx_conf_parse(cf, NULL);
2679
2680 *cf = save;
2681
2682 return rv;
2683}
2684
2685
Igor Sysoevaa828612005-02-09 14:31:07 +00002686static char *
2687ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev74e95c22003-11-09 20:03:38 +00002688{
2689 ngx_http_core_loc_conf_t *lcf = conf;
2690
Igor Sysoevaa828612005-02-09 14:31:07 +00002691 ngx_int_t overwrite;
Igor Sysoev732a2712004-04-21 18:54:33 +00002692 ngx_uint_t i, n;
Igor Sysoev74e95c22003-11-09 20:03:38 +00002693 ngx_str_t *value;
2694 ngx_http_err_page_t *err;
2695
2696 if (lcf->error_pages == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002697 lcf->error_pages = ngx_array_create(cf->pool, 4,
Igor Sysoev74e95c22003-11-09 20:03:38 +00002698 sizeof(ngx_http_err_page_t));
2699 if (lcf->error_pages == NULL) {
2700 return NGX_CONF_ERROR;
2701 }
2702 }
2703
2704 value = cf->args->elts;
2705
Igor Sysoev732a2712004-04-21 18:54:33 +00002706 i = cf->args->nelts - 2;
2707
2708 if (value[i].data[0] == '=') {
2709 if (i == 1) {
2710 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00002711 "invalid value \"%V\"", &value[i]);
Igor Sysoev732a2712004-04-21 18:54:33 +00002712 return NGX_CONF_ERROR;
2713 }
2714
Igor Sysoeva2573672005-10-05 14:46:21 +00002715 if (value[i].len > 1) {
2716 overwrite = ngx_atoi(&value[i].data[1], value[i].len - 1);
Igor Sysoev732a2712004-04-21 18:54:33 +00002717
Igor Sysoeva2573672005-10-05 14:46:21 +00002718 if (overwrite == NGX_ERROR) {
2719 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2720 "invalid value \"%V\"", &value[i]);
2721 return NGX_CONF_ERROR;
2722 }
2723
2724 } else {
2725 overwrite = 0;
Igor Sysoev732a2712004-04-21 18:54:33 +00002726 }
2727
2728 n = 2;
2729
2730 } else {
Igor Sysoeva2573672005-10-05 14:46:21 +00002731 overwrite = -1;
Igor Sysoev732a2712004-04-21 18:54:33 +00002732 n = 1;
2733 }
2734
2735 for (i = 1; i < cf->args->nelts - n; i++) {
Igor Sysoevc1571722005-03-19 12:38:37 +00002736 err = ngx_array_push(lcf->error_pages);
2737 if (err == NULL) {
Igor Sysoev732a2712004-04-21 18:54:33 +00002738 return NGX_CONF_ERROR;
2739 }
2740
Igor Sysoev3f4685f2004-04-25 20:13:21 +00002741 err->status = ngx_atoi(value[i].data, value[i].len);
Igor Sysoevaa828612005-02-09 14:31:07 +00002742
Igor Sysoev3f4685f2004-04-25 20:13:21 +00002743 if (err->status == NGX_ERROR) {
Igor Sysoev74e95c22003-11-09 20:03:38 +00002744 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00002745 "invalid value \"%V\"", &value[i]);
Igor Sysoev74e95c22003-11-09 20:03:38 +00002746 return NGX_CONF_ERROR;
2747 }
2748
Igor Sysoev3f4685f2004-04-25 20:13:21 +00002749 if (err->status < 400 || err->status > 599) {
Igor Sysoev74e95c22003-11-09 20:03:38 +00002750 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00002751 "value \"%V\" must be between 400 and 599",
2752 &value[i]);
Igor Sysoev74e95c22003-11-09 20:03:38 +00002753 return NGX_CONF_ERROR;
2754 }
2755
Igor Sysoeva2573672005-10-05 14:46:21 +00002756 err->overwrite = (overwrite >= 0) ? overwrite : err->status;
2757
Igor Sysoev74e95c22003-11-09 20:03:38 +00002758 err->uri = value[cf->args->nelts - 1];
2759 }
2760
2761 return NGX_CONF_OK;
2762}
2763
2764
Igor Sysoevaa828612005-02-09 14:31:07 +00002765static char *
Igor Sysoev899b44e2005-05-12 14:58:06 +00002766ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2767{
2768 ngx_http_core_loc_conf_t *lcf = conf;
2769
2770 lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args);
2771 if (lcf->err_log == NULL) {
2772 return NGX_CONF_ERROR;
2773 }
2774
2775 return ngx_set_error_log_levels(cf, lcf->err_log);
2776}
2777
2778
2779static char *
Igor Sysoevaa828612005-02-09 14:31:07 +00002780ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev307c3ad2004-09-17 16:07:35 +00002781{
2782 ngx_http_core_loc_conf_t *lcf = conf;
2783
2784 ngx_str_t *value;
2785
2786 if (lcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) {
2787 return "is duplicate";
2788 }
2789
2790 value = cf->args->elts;
2791
2792 lcf->keepalive_timeout = ngx_parse_time(&value[1], 0);
Igor Sysoevaa828612005-02-09 14:31:07 +00002793
Igor Sysoev307c3ad2004-09-17 16:07:35 +00002794 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) {
2795 return "invalid value";
2796 }
2797
2798 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) {
2799 return "value must be less than 597 hours";
2800 }
2801
2802 if (cf->args->nelts == 2) {
2803 return NGX_CONF_OK;
2804 }
2805
2806 lcf->keepalive_header = ngx_parse_time(&value[2], 1);
Igor Sysoevaa828612005-02-09 14:31:07 +00002807
Igor Sysoev307c3ad2004-09-17 16:07:35 +00002808 if (lcf->keepalive_header == NGX_ERROR) {
2809 return "invalid value";
2810 }
2811
2812 if (lcf->keepalive_header == NGX_PARSE_LARGE_TIME) {
2813 return "value must be less than 68 years";
2814 }
2815
2816 return NGX_CONF_OK;
2817}
2818
2819
Igor Sysoevaa828612005-02-09 14:31:07 +00002820static char *
Igor Sysoev899b44e2005-05-12 14:58:06 +00002821ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev9d639522003-07-07 06:11:50 +00002822{
2823 ngx_http_core_loc_conf_t *lcf = conf;
2824
Igor Sysoev899b44e2005-05-12 14:58:06 +00002825 if (lcf->internal != NGX_CONF_UNSET) {
2826 return "is duplicate";
Igor Sysoev03420a62004-01-20 20:40:08 +00002827 }
Igor Sysoev9d639522003-07-07 06:11:50 +00002828
Igor Sysoev899b44e2005-05-12 14:58:06 +00002829 lcf->internal = 1;
2830
2831 return NGX_CONF_OK;
Igor Sysoev9d639522003-07-07 06:11:50 +00002832}
Igor Sysoevb5faed22003-10-29 08:30:44 +00002833
2834
Igor Sysoevaa828612005-02-09 14:31:07 +00002835static char *
2836ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data)
Igor Sysoevb5faed22003-10-29 08:30:44 +00002837{
Igor Sysoevc0edbcc2004-10-21 15:34:38 +00002838#if (NGX_FREEBSD)
Igor Sysoev42b12b32004-12-02 18:40:46 +00002839 ssize_t *np = data;
Igor Sysoev924bd792004-10-11 15:07:03 +00002840
Igor Sysoevb5faed22003-10-29 08:30:44 +00002841 if (*np >= ngx_freebsd_net_inet_tcp_sendspace) {
2842 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2843 "\"send_lowat\" must be less than %d "
2844 "(sysctl net.inet.tcp.sendspace)",
2845 ngx_freebsd_net_inet_tcp_sendspace);
2846
2847 return NGX_CONF_ERROR;
2848 }
2849
Igor Sysoevf6906042004-11-25 16:17:31 +00002850#elif !(NGX_HAVE_SO_SNDLOWAT)
Igor Sysoev42b12b32004-12-02 18:40:46 +00002851 ssize_t *np = data;
Igor Sysoevb5faed22003-10-29 08:30:44 +00002852
2853 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
2854 "\"send_lowat\" is not supported, ignored");
2855
Igor Sysoev924bd792004-10-11 15:07:03 +00002856 *np = 0;
2857
Igor Sysoevb5faed22003-10-29 08:30:44 +00002858#endif
2859
2860 return NGX_CONF_OK;
2861}