0
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #include <ngx_config.h>
|
|
8 #include <ngx_core.h>
|
|
9 #include <ngx_event.h>
|
|
10 #include <ngx_http.h>
|
|
11 #include <nginx.h>
|
|
12
|
10
|
13
|
180
|
14 typedef struct {
|
286
|
15 u_char *name;
|
180
|
16 uint32_t method;
|
|
17 } ngx_http_method_name_t;
|
|
18
|
|
19
|
0
|
20 #define NGX_HTTP_LOCATION_EXACT 1
|
|
21 #define NGX_HTTP_LOCATION_AUTO_REDIRECT 2
|
16
|
22 #define NGX_HTTP_LOCATION_NOREGEX 3
|
|
23 #define NGX_HTTP_LOCATION_REGEX 4
|
0
|
24
|
|
25
|
278
|
26 #define NGX_HTTP_REQUEST_BODY_FILE_OFF 0
|
|
27 #define NGX_HTTP_REQUEST_BODY_FILE_ON 1
|
|
28 #define NGX_HTTP_REQUEST_BODY_FILE_CLEAN 2
|
|
29
|
|
30
|
34
|
31 static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r,
|
308
|
32 ngx_array_t *locations, ngx_uint_t regex_start, size_t len);
|
380
|
33 static ngx_int_t ngx_http_core_send_continue(ngx_http_request_t *r);
|
0
|
34
|
58
|
35 static ngx_int_t ngx_http_core_preconfiguration(ngx_conf_t *cf);
|
0
|
36 static void *ngx_http_core_create_main_conf(ngx_conf_t *cf);
|
|
37 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf);
|
|
38 static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf);
|
|
39 static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
|
36
|
40 void *parent, void *child);
|
0
|
41 static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf);
|
|
42 static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
|
36
|
43 void *parent, void *child);
|
0
|
44
|
34
|
45 static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
46 void *dummy);
|
34
|
47 static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
48 void *dummy);
|
372
|
49 static ngx_int_t ngx_http_core_cmp_locations(const void *first,
|
|
50 const void *second);
|
34
|
51
|
|
52 static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
53 void *conf);
|
34
|
54 static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy,
|
36
|
55 void *conf);
|
0
|
56
|
34
|
57 static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
58 void *conf);
|
34
|
59 static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
60 void *conf);
|
34
|
61 static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
180
|
62 static char *ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
63 void *conf);
|
34
|
64 static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
65 void *conf);
|
332
|
66 static char *ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
67 void *conf);
|
34
|
68 static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
69 void *conf);
|
34
|
70 static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
71 void *conf);
|
58
|
72 static char *ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
73 void *conf);
|
354
|
74 static char *ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
|
348
|
75 void *conf);
|
358
|
76 #if (NGX_HTTP_GZIP)
|
|
77 static char *ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
78 void *conf);
|
|
79 #endif
|
0
|
80
|
34
|
81 static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data);
|
300
|
82 static char *ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data);
|
34
|
83
|
|
84 static ngx_conf_post_t ngx_http_core_lowat_post =
|
300
|
85 { ngx_http_core_lowat_check };
|
|
86
|
|
87 static ngx_conf_post_handler_pt ngx_http_core_pool_size_p =
|
|
88 ngx_http_core_pool_size;
|
0
|
89
|
158
|
90 static ngx_conf_deprecated_t ngx_conf_deprecated_optimize_host_names = {
|
|
91 ngx_conf_deprecated, "optimize_host_names", "optimize_server_names"
|
|
92 };
|
|
93
|
358
|
94 static ngx_conf_deprecated_t ngx_conf_deprecated_open_file_cache_retest = {
|
|
95 ngx_conf_deprecated, "open_file_cache_retest", "open_file_cache_valid"
|
|
96 };
|
|
97
|
362
|
98 static ngx_conf_deprecated_t ngx_conf_deprecated_satisfy_any = {
|
|
99 ngx_conf_deprecated, "satisfy_any", "satisfy"
|
|
100 };
|
|
101
|
0
|
102
|
278
|
103 static ngx_conf_enum_t ngx_http_core_request_body_in_file[] = {
|
|
104 { ngx_string("off"), NGX_HTTP_REQUEST_BODY_FILE_OFF },
|
|
105 { ngx_string("on"), NGX_HTTP_REQUEST_BODY_FILE_ON },
|
|
106 { ngx_string("clean"), NGX_HTTP_REQUEST_BODY_FILE_CLEAN },
|
|
107 { ngx_null_string, 0 }
|
|
108 };
|
|
109
|
|
110
|
362
|
111 static ngx_conf_enum_t ngx_http_core_satisfy[] = {
|
|
112 { ngx_string("all"), NGX_HTTP_SATISFY_ALL },
|
|
113 { ngx_string("any"), NGX_HTTP_SATISFY_ANY },
|
|
114 { ngx_null_string, 0 }
|
|
115 };
|
|
116
|
|
117
|
358
|
118 #if (NGX_HTTP_GZIP)
|
|
119
|
|
120 static ngx_conf_enum_t ngx_http_gzip_http_version[] = {
|
|
121 { ngx_string("1.0"), NGX_HTTP_VERSION_10 },
|
|
122 { ngx_string("1.1"), NGX_HTTP_VERSION_11 },
|
|
123 { ngx_null_string, 0 }
|
|
124 };
|
|
125
|
|
126
|
|
127 static ngx_conf_bitmask_t ngx_http_gzip_proxied_mask[] = {
|
|
128 { ngx_string("off"), NGX_HTTP_GZIP_PROXIED_OFF },
|
|
129 { ngx_string("expired"), NGX_HTTP_GZIP_PROXIED_EXPIRED },
|
|
130 { ngx_string("no-cache"), NGX_HTTP_GZIP_PROXIED_NO_CACHE },
|
|
131 { ngx_string("no-store"), NGX_HTTP_GZIP_PROXIED_NO_STORE },
|
|
132 { ngx_string("private"), NGX_HTTP_GZIP_PROXIED_PRIVATE },
|
|
133 { ngx_string("no_last_modified"), NGX_HTTP_GZIP_PROXIED_NO_LM },
|
|
134 { ngx_string("no_etag"), NGX_HTTP_GZIP_PROXIED_NO_ETAG },
|
|
135 { ngx_string("auth"), NGX_HTTP_GZIP_PROXIED_AUTH },
|
|
136 { ngx_string("any"), NGX_HTTP_GZIP_PROXIED_ANY },
|
|
137 { ngx_null_string, 0 }
|
|
138 };
|
|
139
|
|
140
|
|
141 static ngx_str_t ngx_http_gzip_no_cache = ngx_string("no-cache");
|
|
142 static ngx_str_t ngx_http_gzip_no_store = ngx_string("no-store");
|
|
143 static ngx_str_t ngx_http_gzip_private = ngx_string("private");
|
|
144
|
|
145 #endif
|
|
146
|
|
147
|
0
|
148 static ngx_command_t ngx_http_core_commands[] = {
|
|
149
|
160
|
150 { ngx_string("variables_hash_max_size"),
|
|
151 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
|
152 ngx_conf_set_num_slot,
|
|
153 NGX_HTTP_MAIN_CONF_OFFSET,
|
|
154 offsetof(ngx_http_core_main_conf_t, variables_hash_max_size),
|
|
155 NULL },
|
|
156
|
|
157 { ngx_string("variables_hash_bucket_size"),
|
|
158 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
|
159 ngx_conf_set_num_slot,
|
|
160 NGX_HTTP_MAIN_CONF_OFFSET,
|
|
161 offsetof(ngx_http_core_main_conf_t, variables_hash_bucket_size),
|
|
162 NULL },
|
|
163
|
142
|
164 { ngx_string("server_names_hash_max_size"),
|
26
|
165 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
|
166 ngx_conf_set_num_slot,
|
|
167 NGX_HTTP_MAIN_CONF_OFFSET,
|
142
|
168 offsetof(ngx_http_core_main_conf_t, server_names_hash_max_size),
|
26
|
169 NULL },
|
|
170
|
142
|
171 { ngx_string("server_names_hash_bucket_size"),
|
26
|
172 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
|
173 ngx_conf_set_num_slot,
|
|
174 NGX_HTTP_MAIN_CONF_OFFSET,
|
142
|
175 offsetof(ngx_http_core_main_conf_t, server_names_hash_bucket_size),
|
26
|
176 NULL },
|
|
177
|
0
|
178 { ngx_string("server"),
|
200
|
179 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_MULTI|NGX_CONF_NOARGS,
|
34
|
180 ngx_http_core_server,
|
0
|
181 0,
|
|
182 0,
|
|
183 NULL },
|
|
184
|
|
185 { ngx_string("connection_pool_size"),
|
|
186 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
187 ngx_conf_set_size_slot,
|
|
188 NGX_HTTP_SRV_CONF_OFFSET,
|
|
189 offsetof(ngx_http_core_srv_conf_t, connection_pool_size),
|
300
|
190 &ngx_http_core_pool_size_p },
|
0
|
191
|
|
192 { ngx_string("request_pool_size"),
|
|
193 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
194 ngx_conf_set_size_slot,
|
|
195 NGX_HTTP_SRV_CONF_OFFSET,
|
|
196 offsetof(ngx_http_core_srv_conf_t, request_pool_size),
|
300
|
197 &ngx_http_core_pool_size_p },
|
0
|
198
|
|
199 { ngx_string("client_header_timeout"),
|
|
200 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
201 ngx_conf_set_msec_slot,
|
|
202 NGX_HTTP_SRV_CONF_OFFSET,
|
|
203 offsetof(ngx_http_core_srv_conf_t, client_header_timeout),
|
|
204 NULL },
|
|
205
|
|
206 { ngx_string("client_header_buffer_size"),
|
|
207 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
208 ngx_conf_set_size_slot,
|
|
209 NGX_HTTP_SRV_CONF_OFFSET,
|
|
210 offsetof(ngx_http_core_srv_conf_t, client_header_buffer_size),
|
|
211 NULL },
|
|
212
|
|
213 { ngx_string("large_client_header_buffers"),
|
|
214 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE2,
|
|
215 ngx_conf_set_bufs_slot,
|
|
216 NGX_HTTP_SRV_CONF_OFFSET,
|
|
217 offsetof(ngx_http_core_srv_conf_t, large_client_header_buffers),
|
|
218 NULL },
|
|
219
|
158
|
220 { ngx_string("optimize_server_names"),
|
|
221 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
|
|
222 ngx_conf_set_flag_slot,
|
|
223 NGX_HTTP_SRV_CONF_OFFSET,
|
|
224 offsetof(ngx_http_core_srv_conf_t, optimize_server_names),
|
|
225 NULL },
|
|
226
|
152
|
227 { ngx_string("optimize_host_names"),
|
|
228 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
|
|
229 ngx_conf_set_flag_slot,
|
|
230 NGX_HTTP_SRV_CONF_OFFSET,
|
158
|
231 offsetof(ngx_http_core_srv_conf_t, optimize_server_names),
|
|
232 &ngx_conf_deprecated_optimize_host_names },
|
152
|
233
|
60
|
234 { ngx_string("ignore_invalid_headers"),
|
|
235 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
|
|
236 ngx_conf_set_flag_slot,
|
|
237 NGX_HTTP_SRV_CONF_OFFSET,
|
|
238 offsetof(ngx_http_core_srv_conf_t, ignore_invalid_headers),
|
|
239 NULL },
|
|
240
|
342
|
241 { ngx_string("merge_slashes"),
|
|
242 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
|
|
243 ngx_conf_set_flag_slot,
|
|
244 NGX_HTTP_SRV_CONF_OFFSET,
|
|
245 offsetof(ngx_http_core_srv_conf_t, merge_slashes),
|
|
246 NULL },
|
|
247
|
0
|
248 { ngx_string("location"),
|
|
249 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12,
|
34
|
250 ngx_http_core_location,
|
0
|
251 NGX_HTTP_SRV_CONF_OFFSET,
|
|
252 0,
|
|
253 NULL },
|
|
254
|
|
255 { ngx_string("listen"),
|
72
|
256 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
|
34
|
257 ngx_http_core_listen,
|
0
|
258 NGX_HTTP_SRV_CONF_OFFSET,
|
|
259 0,
|
|
260 NULL },
|
|
261
|
|
262 { ngx_string("server_name"),
|
|
263 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
|
34
|
264 ngx_http_core_server_name,
|
0
|
265 NGX_HTTP_SRV_CONF_OFFSET,
|
|
266 0,
|
|
267 NULL },
|
|
268
|
138
|
269 { ngx_string("types_hash_max_size"),
|
|
270 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
271 ngx_conf_set_num_slot,
|
|
272 NGX_HTTP_LOC_CONF_OFFSET,
|
|
273 offsetof(ngx_http_core_loc_conf_t, types_hash_max_size),
|
|
274 NULL },
|
|
275
|
|
276 { ngx_string("types_hash_bucket_size"),
|
|
277 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
278 ngx_conf_set_num_slot,
|
|
279 NGX_HTTP_LOC_CONF_OFFSET,
|
|
280 offsetof(ngx_http_core_loc_conf_t, types_hash_bucket_size),
|
|
281 NULL },
|
|
282
|
0
|
283 { ngx_string("types"),
|
|
284 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF
|
|
285 |NGX_CONF_BLOCK|NGX_CONF_NOARGS,
|
34
|
286 ngx_http_core_types,
|
0
|
287 NGX_HTTP_LOC_CONF_OFFSET,
|
|
288 0,
|
|
289 NULL },
|
|
290
|
|
291 { ngx_string("default_type"),
|
|
292 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
293 ngx_conf_set_str_slot,
|
|
294 NGX_HTTP_LOC_CONF_OFFSET,
|
|
295 offsetof(ngx_http_core_loc_conf_t, default_type),
|
|
296 NULL },
|
|
297
|
|
298 { ngx_string("root"),
|
58
|
299 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
300 |NGX_CONF_TAKE1,
|
34
|
301 ngx_http_core_root,
|
0
|
302 NGX_HTTP_LOC_CONF_OFFSET,
|
|
303 0,
|
|
304 NULL },
|
|
305
|
|
306 { ngx_string("alias"),
|
|
307 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
34
|
308 ngx_http_core_root,
|
0
|
309 NGX_HTTP_LOC_CONF_OFFSET,
|
|
310 0,
|
|
311 NULL },
|
|
312
|
180
|
313 { ngx_string("limit_except"),
|
|
314 NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_1MORE,
|
|
315 ngx_http_core_limit_except,
|
|
316 NGX_HTTP_LOC_CONF_OFFSET,
|
|
317 0,
|
|
318 NULL },
|
|
319
|
0
|
320 { ngx_string("client_max_body_size"),
|
|
321 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
212
|
322 ngx_conf_set_off_slot,
|
0
|
323 NGX_HTTP_LOC_CONF_OFFSET,
|
|
324 offsetof(ngx_http_core_loc_conf_t, client_max_body_size),
|
|
325 NULL },
|
|
326
|
|
327 { ngx_string("client_body_buffer_size"),
|
|
328 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
329 ngx_conf_set_size_slot,
|
|
330 NGX_HTTP_LOC_CONF_OFFSET,
|
|
331 offsetof(ngx_http_core_loc_conf_t, client_body_buffer_size),
|
|
332 NULL },
|
|
333
|
|
334 { ngx_string("client_body_timeout"),
|
|
335 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
336 ngx_conf_set_msec_slot,
|
|
337 NGX_HTTP_LOC_CONF_OFFSET,
|
|
338 offsetof(ngx_http_core_loc_conf_t, client_body_timeout),
|
|
339 NULL },
|
|
340
|
28
|
341 { ngx_string("client_body_temp_path"),
|
|
342 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
|
|
343 ngx_conf_set_path_slot,
|
|
344 NGX_HTTP_LOC_CONF_OFFSET,
|
|
345 offsetof(ngx_http_core_loc_conf_t, client_body_temp_path),
|
|
346 (void *) ngx_garbage_collector_temp_handler },
|
|
347
|
182
|
348 { ngx_string("client_body_in_file_only"),
|
|
349 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
278
|
350 ngx_conf_set_enum_slot,
|
182
|
351 NGX_HTTP_LOC_CONF_OFFSET,
|
|
352 offsetof(ngx_http_core_loc_conf_t, client_body_in_file_only),
|
278
|
353 &ngx_http_core_request_body_in_file },
|
182
|
354
|
0
|
355 { ngx_string("sendfile"),
|
278
|
356 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
357 |NGX_CONF_TAKE1,
|
0
|
358 ngx_conf_set_flag_slot,
|
|
359 NGX_HTTP_LOC_CONF_OFFSET,
|
|
360 offsetof(ngx_http_core_loc_conf_t, sendfile),
|
|
361 NULL },
|
|
362
|
300
|
363 { ngx_string("sendfile_max_chunk"),
|
|
364 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
365 ngx_conf_set_size_slot,
|
|
366 NGX_HTTP_LOC_CONF_OFFSET,
|
|
367 offsetof(ngx_http_core_loc_conf_t, sendfile_max_chunk),
|
|
368 NULL },
|
|
369
|
0
|
370 { ngx_string("tcp_nopush"),
|
|
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, tcp_nopush),
|
|
375 NULL },
|
|
376
|
2
|
377 { ngx_string("tcp_nodelay"),
|
|
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, tcp_nodelay),
|
|
382 NULL },
|
|
383
|
0
|
384 { ngx_string("send_timeout"),
|
|
385 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
386 ngx_conf_set_msec_slot,
|
|
387 NGX_HTTP_LOC_CONF_OFFSET,
|
|
388 offsetof(ngx_http_core_loc_conf_t, send_timeout),
|
|
389 NULL },
|
|
390
|
|
391 { ngx_string("send_lowat"),
|
|
392 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
393 ngx_conf_set_size_slot,
|
|
394 NGX_HTTP_LOC_CONF_OFFSET,
|
|
395 offsetof(ngx_http_core_loc_conf_t, send_lowat),
|
34
|
396 &ngx_http_core_lowat_post },
|
0
|
397
|
|
398 { ngx_string("postpone_output"),
|
|
399 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
400 ngx_conf_set_size_slot,
|
|
401 NGX_HTTP_LOC_CONF_OFFSET,
|
|
402 offsetof(ngx_http_core_loc_conf_t, postpone_output),
|
|
403 NULL },
|
|
404
|
|
405 { ngx_string("limit_rate"),
|
34
|
406 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
407 |NGX_CONF_TAKE1,
|
0
|
408 ngx_conf_set_size_slot,
|
|
409 NGX_HTTP_LOC_CONF_OFFSET,
|
|
410 offsetof(ngx_http_core_loc_conf_t, limit_rate),
|
|
411 NULL },
|
|
412
|
|
413 { ngx_string("keepalive_timeout"),
|
|
414 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
|
34
|
415 ngx_http_core_keepalive,
|
0
|
416 NGX_HTTP_LOC_CONF_OFFSET,
|
|
417 0,
|
|
418 NULL },
|
|
419
|
362
|
420 { ngx_string("satisfy"),
|
|
421 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
422 ngx_conf_set_enum_slot,
|
|
423 NGX_HTTP_LOC_CONF_OFFSET,
|
|
424 offsetof(ngx_http_core_loc_conf_t, satisfy),
|
|
425 &ngx_http_core_satisfy },
|
|
426
|
92
|
427 { ngx_string("satisfy_any"),
|
|
428 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
429 ngx_conf_set_flag_slot,
|
|
430 NGX_HTTP_LOC_CONF_OFFSET,
|
362
|
431 offsetof(ngx_http_core_loc_conf_t, satisfy),
|
|
432 &ngx_conf_deprecated_satisfy_any },
|
92
|
433
|
58
|
434 { ngx_string("internal"),
|
|
435 NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
|
|
436 ngx_http_core_internal,
|
|
437 NGX_HTTP_LOC_CONF_OFFSET,
|
|
438 0,
|
|
439 NULL },
|
|
440
|
0
|
441 { ngx_string("lingering_time"),
|
|
442 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
443 ngx_conf_set_msec_slot,
|
|
444 NGX_HTTP_LOC_CONF_OFFSET,
|
|
445 offsetof(ngx_http_core_loc_conf_t, lingering_time),
|
|
446 NULL },
|
|
447
|
|
448 { ngx_string("lingering_timeout"),
|
|
449 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
450 ngx_conf_set_msec_slot,
|
|
451 NGX_HTTP_LOC_CONF_OFFSET,
|
|
452 offsetof(ngx_http_core_loc_conf_t, lingering_timeout),
|
|
453 NULL },
|
|
454
|
|
455 { ngx_string("reset_timedout_connection"),
|
|
456 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
457 ngx_conf_set_flag_slot,
|
|
458 NGX_HTTP_LOC_CONF_OFFSET,
|
|
459 offsetof(ngx_http_core_loc_conf_t, reset_timedout_connection),
|
|
460 NULL },
|
|
461
|
362
|
462 { ngx_string("server_name_in_redirect"),
|
|
463 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
464 ngx_conf_set_flag_slot,
|
|
465 NGX_HTTP_LOC_CONF_OFFSET,
|
|
466 offsetof(ngx_http_core_loc_conf_t, server_name_in_redirect),
|
|
467 NULL },
|
|
468
|
70
|
469 { ngx_string("port_in_redirect"),
|
|
470 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
471 ngx_conf_set_flag_slot,
|
|
472 NGX_HTTP_LOC_CONF_OFFSET,
|
|
473 offsetof(ngx_http_core_loc_conf_t, port_in_redirect),
|
|
474 NULL },
|
|
475
|
0
|
476 { ngx_string("msie_padding"),
|
|
477 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
478 ngx_conf_set_flag_slot,
|
|
479 NGX_HTTP_LOC_CONF_OFFSET,
|
|
480 offsetof(ngx_http_core_loc_conf_t, msie_padding),
|
|
481 NULL },
|
|
482
|
228
|
483 { ngx_string("msie_refresh"),
|
|
484 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
485 ngx_conf_set_flag_slot,
|
|
486 NGX_HTTP_LOC_CONF_OFFSET,
|
|
487 offsetof(ngx_http_core_loc_conf_t, msie_refresh),
|
|
488 NULL },
|
|
489
|
76
|
490 { ngx_string("log_not_found"),
|
|
491 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
492 ngx_conf_set_flag_slot,
|
|
493 NGX_HTTP_LOC_CONF_OFFSET,
|
|
494 offsetof(ngx_http_core_loc_conf_t, log_not_found),
|
|
495 NULL },
|
|
496
|
228
|
497 { ngx_string("recursive_error_pages"),
|
|
498 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
499 ngx_conf_set_flag_slot,
|
|
500 NGX_HTTP_LOC_CONF_OFFSET,
|
|
501 offsetof(ngx_http_core_loc_conf_t, recursive_error_pages),
|
|
502 NULL },
|
|
503
|
342
|
504 { ngx_string("server_tokens"),
|
|
505 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
506 ngx_conf_set_flag_slot,
|
|
507 NGX_HTTP_LOC_CONF_OFFSET,
|
|
508 offsetof(ngx_http_core_loc_conf_t, server_tokens),
|
|
509 NULL },
|
|
510
|
0
|
511 { ngx_string("error_page"),
|
58
|
512 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
513 |NGX_CONF_2MORE,
|
34
|
514 ngx_http_core_error_page,
|
0
|
515 NGX_HTTP_LOC_CONF_OFFSET,
|
|
516 0,
|
|
517 NULL },
|
|
518
|
126
|
519 { ngx_string("post_action"),
|
|
520 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
521 |NGX_CONF_TAKE1,
|
|
522 ngx_conf_set_str_slot,
|
|
523 NGX_HTTP_LOC_CONF_OFFSET,
|
|
524 offsetof(ngx_http_core_loc_conf_t, post_action),
|
|
525 NULL },
|
|
526
|
0
|
527 { ngx_string("error_log"),
|
|
528 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
34
|
529 ngx_http_core_error_log,
|
0
|
530 NGX_HTTP_LOC_CONF_OFFSET,
|
|
531 0,
|
|
532 NULL },
|
|
533
|
|
534 { ngx_string("open_file_cache"),
|
332
|
535 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
|
|
536 ngx_http_core_open_file_cache,
|
|
537 NGX_HTTP_LOC_CONF_OFFSET,
|
|
538 offsetof(ngx_http_core_loc_conf_t, open_file_cache),
|
|
539 NULL },
|
|
540
|
358
|
541 { ngx_string("open_file_cache_valid"),
|
|
542 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
543 ngx_conf_set_sec_slot,
|
|
544 NGX_HTTP_LOC_CONF_OFFSET,
|
|
545 offsetof(ngx_http_core_loc_conf_t, open_file_cache_valid),
|
|
546 NULL },
|
|
547
|
332
|
548 { ngx_string("open_file_cache_retest"),
|
|
549 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
550 ngx_conf_set_sec_slot,
|
0
|
551 NGX_HTTP_LOC_CONF_OFFSET,
|
358
|
552 offsetof(ngx_http_core_loc_conf_t, open_file_cache_valid),
|
|
553 &ngx_conf_deprecated_open_file_cache_retest },
|
|
554
|
|
555 { ngx_string("open_file_cache_min_uses"),
|
|
556 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
557 ngx_conf_set_num_slot,
|
|
558 NGX_HTTP_LOC_CONF_OFFSET,
|
|
559 offsetof(ngx_http_core_loc_conf_t, open_file_cache_min_uses),
|
0
|
560 NULL },
|
|
561
|
332
|
562 { ngx_string("open_file_cache_errors"),
|
|
563 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
564 ngx_conf_set_flag_slot,
|
|
565 NGX_HTTP_LOC_CONF_OFFSET,
|
|
566 offsetof(ngx_http_core_loc_conf_t, open_file_cache_errors),
|
|
567 NULL },
|
|
568
|
|
569 { ngx_string("open_file_cache_events"),
|
|
570 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
571 ngx_conf_set_flag_slot,
|
|
572 NGX_HTTP_LOC_CONF_OFFSET,
|
|
573 offsetof(ngx_http_core_loc_conf_t, open_file_cache_events),
|
|
574 NULL },
|
0
|
575
|
348
|
576 { ngx_string("resolver"),
|
|
577 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
578 ngx_http_core_resolver,
|
|
579 NGX_HTTP_LOC_CONF_OFFSET,
|
|
580 0,
|
|
581 NULL },
|
|
582
|
|
583 { ngx_string("resolver_timeout"),
|
|
584 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
585 ngx_conf_set_msec_slot,
|
|
586 NGX_HTTP_LOC_CONF_OFFSET,
|
|
587 offsetof(ngx_http_core_loc_conf_t, resolver_timeout),
|
|
588 NULL },
|
|
589
|
358
|
590 #if (NGX_HTTP_GZIP)
|
|
591
|
|
592 { ngx_string("gzip_vary"),
|
|
593 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
594 ngx_conf_set_flag_slot,
|
|
595 NGX_HTTP_LOC_CONF_OFFSET,
|
|
596 offsetof(ngx_http_core_loc_conf_t, gzip_vary),
|
|
597 NULL },
|
|
598
|
|
599 { ngx_string("gzip_http_version"),
|
|
600 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
601 ngx_conf_set_enum_slot,
|
|
602 NGX_HTTP_LOC_CONF_OFFSET,
|
|
603 offsetof(ngx_http_core_loc_conf_t, gzip_http_version),
|
|
604 &ngx_http_gzip_http_version },
|
|
605
|
|
606 { ngx_string("gzip_proxied"),
|
|
607 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
608 ngx_conf_set_bitmask_slot,
|
|
609 NGX_HTTP_LOC_CONF_OFFSET,
|
|
610 offsetof(ngx_http_core_loc_conf_t, gzip_proxied),
|
|
611 &ngx_http_gzip_proxied_mask },
|
|
612
|
|
613 { ngx_string("gzip_disable"),
|
|
614 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
615 ngx_http_gzip_disable,
|
|
616 NGX_HTTP_LOC_CONF_OFFSET,
|
|
617 0,
|
|
618 NULL },
|
|
619
|
|
620 #endif
|
|
621
|
0
|
622 ngx_null_command
|
|
623 };
|
|
624
|
|
625
|
216
|
626 static ngx_http_module_t ngx_http_core_module_ctx = {
|
58
|
627 ngx_http_core_preconfiguration, /* preconfiguration */
|
122
|
628 NULL, /* postconfiguration */
|
0
|
629
|
|
630 ngx_http_core_create_main_conf, /* create main configuration */
|
|
631 ngx_http_core_init_main_conf, /* init main configuration */
|
|
632
|
|
633 ngx_http_core_create_srv_conf, /* create server configuration */
|
|
634 ngx_http_core_merge_srv_conf, /* merge server configuration */
|
|
635
|
|
636 ngx_http_core_create_loc_conf, /* create location configuration */
|
|
637 ngx_http_core_merge_loc_conf /* merge location configuration */
|
|
638 };
|
|
639
|
|
640
|
|
641 ngx_module_t ngx_http_core_module = {
|
58
|
642 NGX_MODULE_V1,
|
0
|
643 &ngx_http_core_module_ctx, /* module context */
|
|
644 ngx_http_core_commands, /* module directives */
|
|
645 NGX_HTTP_MODULE, /* module type */
|
90
|
646 NULL, /* init master */
|
58
|
647 NULL, /* init module */
|
90
|
648 NULL, /* init process */
|
|
649 NULL, /* init thread */
|
|
650 NULL, /* exit thread */
|
|
651 NULL, /* exit process */
|
|
652 NULL, /* exit master */
|
|
653 NGX_MODULE_V1_PADDING
|
0
|
654 };
|
|
655
|
|
656
|
364
|
657 static ngx_str_t ngx_http_core_get_method = { 3, (u_char *) "GET " };
|
|
658
|
|
659
|
36
|
660 void
|
|
661 ngx_http_handler(ngx_http_request_t *r)
|
0
|
662 {
|
230
|
663 ngx_http_core_main_conf_t *cmcf;
|
|
664
|
32
|
665 r->connection->log->action = NULL;
|
0
|
666
|
|
667 r->connection->unexpected_eof = 0;
|
|
668
|
224
|
669 if (!r->internal) {
|
92
|
670 switch (r->headers_in.connection_type) {
|
|
671 case 0:
|
|
672 if (r->http_version > NGX_HTTP_VERSION_10) {
|
|
673 r->keepalive = 1;
|
|
674 } else {
|
|
675 r->keepalive = 0;
|
|
676 }
|
|
677 break;
|
|
678
|
|
679 case NGX_HTTP_CONNECTION_CLOSE:
|
|
680 r->keepalive = 0;
|
|
681 break;
|
|
682
|
|
683 case NGX_HTTP_CONNECTION_KEEP_ALIVE:
|
0
|
684 r->keepalive = 1;
|
92
|
685 break;
|
|
686 }
|
|
687
|
|
688 if (r->keepalive && r->headers_in.msie && r->method == NGX_HTTP_POST) {
|
|
689
|
|
690 /*
|
230
|
691 * MSIE may wait for some time if an response for
|
|
692 * a POST request was sent over a keepalive connection
|
92
|
693 */
|
|
694
|
0
|
695 r->keepalive = 0;
|
|
696 }
|
92
|
697
|
|
698 if (r->headers_in.content_length_n > 0) {
|
|
699 r->lingering_close = 1;
|
|
700
|
|
701 } else {
|
|
702 r->lingering_close = 0;
|
|
703 }
|
236
|
704
|
230
|
705 r->phase_handler = 0;
|
|
706
|
|
707 } else {
|
|
708 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
|
|
709 r->phase_handler = cmcf->phase_engine.server_rewrite_index;
|
|
710 }
|
|
711
|
236
|
712 if (r->unparsed_uri.len) {
|
|
713 r->valid_unparsed_uri = 1;
|
|
714 }
|
|
715
|
|
716 r->valid_location = 1;
|
358
|
717 r->gzip = 0;
|
236
|
718
|
230
|
719 r->write_event_handler = ngx_http_core_run_phases;
|
34
|
720 ngx_http_core_run_phases(r);
|
0
|
721 }
|
|
722
|
|
723
|
230
|
724 void
|
36
|
725 ngx_http_core_run_phases(ngx_http_request_t *r)
|
0
|
726 {
|
|
727 ngx_int_t rc;
|
230
|
728 ngx_http_phase_handler_t *ph;
|
0
|
729 ngx_http_core_main_conf_t *cmcf;
|
|
730
|
|
731 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
|
|
732
|
230
|
733 ph = cmcf->phase_engine.handlers;
|
|
734
|
|
735 while (ph[r->phase_handler].checker) {
|
|
736
|
|
737 rc = ph[r->phase_handler].checker(r, &ph[r->phase_handler]);
|
|
738
|
|
739 if (rc == NGX_OK) {
|
92
|
740 return;
|
0
|
741 }
|
|
742 }
|
|
743 }
|
|
744
|
|
745
|
36
|
746 ngx_int_t
|
230
|
747 ngx_http_core_generic_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
|
|
748 {
|
|
749 ngx_int_t rc;
|
|
750
|
|
751 /*
|
|
752 * generic phase checker,
|
|
753 * used by the post read, server rewrite, rewrite, and pre-access phases
|
|
754 */
|
|
755
|
|
756 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
757 "generic phase: %ui", r->phase_handler);
|
|
758
|
|
759 rc = ph->handler(r);
|
|
760
|
|
761 if (rc == NGX_OK) {
|
|
762 r->phase_handler = ph->next;
|
|
763 return NGX_AGAIN;
|
|
764 }
|
|
765
|
|
766 if (rc == NGX_DECLINED) {
|
|
767 r->phase_handler++;
|
|
768 return NGX_AGAIN;
|
|
769 }
|
|
770
|
|
771 if (rc == NGX_AGAIN || rc == NGX_DONE) {
|
|
772 return NGX_OK;
|
|
773 }
|
|
774
|
|
775 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
|
|
776
|
|
777 ngx_http_finalize_request(r, rc);
|
|
778
|
|
779 return NGX_OK;
|
|
780 }
|
|
781
|
|
782
|
|
783 ngx_int_t
|
|
784 ngx_http_core_find_config_phase(ngx_http_request_t *r,
|
|
785 ngx_http_phase_handler_t *ph)
|
0
|
786 {
|
328
|
787 u_char *p;
|
|
788 size_t len;
|
380
|
789 ngx_int_t rc, expect;
|
0
|
790 ngx_http_core_loc_conf_t *clcf;
|
|
791 ngx_http_core_srv_conf_t *cscf;
|
|
792
|
38
|
793 r->content_handler = NULL;
|
|
794 r->uri_changed = 0;
|
|
795
|
0
|
796 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
|
797
|
308
|
798 rc = ngx_http_core_find_location(r, &cscf->locations, cscf->regex_start, 0);
|
0
|
799
|
|
800 if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) {
|
230
|
801 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
802 return NGX_OK;
|
0
|
803 }
|
|
804
|
|
805 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
806
|
58
|
807 if (!r->internal && clcf->internal) {
|
230
|
808 ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
|
|
809 return NGX_OK;
|
58
|
810 }
|
|
811
|
104
|
812 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
813 "using configuration \"%s%V\"",
|
|
814 (clcf->noname ? "*" : (clcf->exact_match ? "=" : "")),
|
|
815 &clcf->name);
|
|
816
|
84
|
817 ngx_http_update_location_config(r);
|
0
|
818
|
|
819 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
212
|
820 "http cl:%O max:%O",
|
10
|
821 r->headers_in.content_length_n, clcf->client_max_body_size);
|
0
|
822
|
|
823 if (r->headers_in.content_length_n != -1
|
222
|
824 && !r->discard_body
|
0
|
825 && clcf->client_max_body_size
|
212
|
826 && clcf->client_max_body_size < r->headers_in.content_length_n)
|
0
|
827 {
|
|
828 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
342
|
829 "client intended to send too large body: %O bytes",
|
0
|
830 r->headers_in.content_length_n);
|
|
831
|
230
|
832 ngx_http_finalize_request(r, NGX_HTTP_REQUEST_ENTITY_TOO_LARGE);
|
|
833 return NGX_OK;
|
0
|
834 }
|
|
835
|
380
|
836 if (r->headers_in.expect) {
|
|
837 expect = ngx_http_core_send_continue(r);
|
|
838
|
|
839 if (expect != NGX_OK) {
|
|
840 ngx_http_finalize_request(r, expect);
|
|
841 return NGX_OK;
|
|
842 }
|
|
843 }
|
0
|
844
|
|
845 if (rc == NGX_HTTP_LOCATION_AUTO_REDIRECT) {
|
|
846 r->headers_out.location = ngx_list_push(&r->headers_out.headers);
|
|
847 if (r->headers_out.location == NULL) {
|
230
|
848 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
849 return NGX_OK;
|
0
|
850 }
|
|
851
|
58
|
852 /*
|
|
853 * we do not need to set the r->headers_out.location->hash and
|
|
854 * r->headers_out.location->key fields
|
|
855 */
|
|
856
|
328
|
857 if (r->args.len == 0) {
|
|
858 r->headers_out.location->value = clcf->name;
|
|
859
|
|
860 } else {
|
|
861 len = clcf->name.len + 1 + r->args.len;
|
|
862 p = ngx_palloc(r->pool, len);
|
|
863
|
|
864 if (p == NULL) {
|
|
865 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
866 return NGX_OK;
|
|
867 }
|
|
868
|
|
869 r->headers_out.location->value.len = len;
|
|
870 r->headers_out.location->value.data = p;
|
|
871
|
|
872 p = ngx_cpymem(p, clcf->name.data, clcf->name.len);
|
|
873 *p++ = '?';
|
|
874 ngx_memcpy(p, r->args.data, r->args.len);
|
|
875 }
|
0
|
876
|
230
|
877 ngx_http_finalize_request(r, NGX_HTTP_MOVED_PERMANENTLY);
|
|
878 return NGX_OK;
|
|
879 }
|
|
880
|
|
881 r->phase_handler++;
|
|
882 return NGX_AGAIN;
|
|
883 }
|
|
884
|
|
885
|
|
886 ngx_int_t
|
|
887 ngx_http_core_post_rewrite_phase(ngx_http_request_t *r,
|
|
888 ngx_http_phase_handler_t *ph)
|
|
889 {
|
|
890 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
891 "post rewrite phase: %ui", r->phase_handler);
|
|
892
|
|
893 if (!r->uri_changed) {
|
|
894 r->phase_handler++;
|
|
895 return NGX_AGAIN;
|
|
896 }
|
|
897
|
|
898 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
899 "uri changes: %d", r->uri_changes);
|
|
900
|
|
901 /*
|
|
902 * gcc before 3.3 compiles the broken code for
|
|
903 * if (r->uri_changes-- == 0)
|
|
904 * if the r->uri_changes is defined as
|
|
905 * unsigned uri_changes:4
|
|
906 */
|
|
907
|
|
908 r->uri_changes--;
|
|
909
|
|
910 if (r->uri_changes == 0) {
|
|
911 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
912 "rewrite or internal redirection cycle "
|
|
913 "while processing \"%V\"", &r->uri);
|
|
914
|
|
915 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
916 return NGX_OK;
|
|
917 }
|
|
918
|
|
919 r->phase_handler = ph->next;
|
|
920
|
|
921 return NGX_AGAIN;
|
|
922 }
|
|
923
|
|
924
|
|
925 ngx_int_t
|
|
926 ngx_http_core_access_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
|
|
927 {
|
|
928 ngx_int_t rc;
|
|
929 ngx_http_core_loc_conf_t *clcf;
|
|
930
|
|
931 if (r != r->main) {
|
|
932 r->phase_handler = ph->next;
|
|
933 return NGX_AGAIN;
|
|
934 }
|
|
935
|
|
936 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
937 "access phase: %ui", r->phase_handler);
|
|
938
|
|
939 rc = ph->handler(r);
|
|
940
|
|
941 if (rc == NGX_DECLINED) {
|
|
942 r->phase_handler++;
|
|
943 return NGX_AGAIN;
|
|
944 }
|
|
945
|
|
946 if (rc == NGX_AGAIN || rc == NGX_DONE) {
|
|
947 return NGX_OK;
|
0
|
948 }
|
|
949
|
230
|
950 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
951
|
362
|
952 if (clcf->satisfy == NGX_HTTP_SATISFY_ALL) {
|
230
|
953
|
|
954 if (rc == NGX_OK) {
|
|
955 r->phase_handler++;
|
|
956 return NGX_AGAIN;
|
|
957 }
|
|
958
|
|
959 } else {
|
|
960 if (rc == NGX_OK) {
|
|
961 r->access_code = 0;
|
|
962
|
|
963 if (r->headers_out.www_authenticate) {
|
|
964 r->headers_out.www_authenticate->hash = 0;
|
|
965 }
|
|
966
|
|
967 r->phase_handler = ph->next;
|
|
968 return NGX_AGAIN;
|
|
969 }
|
|
970
|
|
971 if (rc == NGX_HTTP_FORBIDDEN || rc == NGX_HTTP_UNAUTHORIZED) {
|
|
972 r->access_code = rc;
|
|
973
|
|
974 r->phase_handler++;
|
|
975 return NGX_AGAIN;
|
|
976 }
|
|
977 }
|
|
978
|
|
979 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
|
|
980
|
|
981 ngx_http_finalize_request(r, rc);
|
|
982 return NGX_OK;
|
|
983 }
|
|
984
|
|
985
|
|
986 ngx_int_t
|
|
987 ngx_http_core_post_access_phase(ngx_http_request_t *r,
|
|
988 ngx_http_phase_handler_t *ph)
|
|
989 {
|
|
990 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
991 "post access phase: %ui", r->phase_handler);
|
|
992
|
|
993 if (r->access_code) {
|
|
994
|
|
995 if (r->access_code == NGX_HTTP_FORBIDDEN) {
|
|
996 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
997 "access forbidden by rule");
|
|
998 }
|
|
999
|
|
1000 ngx_http_finalize_request(r, r->access_code);
|
|
1001 return NGX_OK;
|
|
1002 }
|
|
1003
|
|
1004 r->phase_handler++;
|
|
1005 return NGX_AGAIN;
|
|
1006 }
|
|
1007
|
|
1008
|
|
1009 ngx_int_t
|
|
1010 ngx_http_core_content_phase(ngx_http_request_t *r,
|
|
1011 ngx_http_phase_handler_t *ph)
|
|
1012 {
|
248
|
1013 size_t root;
|
230
|
1014 ngx_int_t rc;
|
|
1015 ngx_str_t path;
|
|
1016
|
|
1017 if (r->content_handler) {
|
|
1018 r->write_event_handler = ngx_http_request_empty_handler;
|
|
1019 ngx_http_finalize_request(r, r->content_handler(r));
|
|
1020 return NGX_OK;
|
|
1021 }
|
|
1022
|
|
1023 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1024 "content phase: %ui", r->phase_handler);
|
|
1025
|
|
1026 rc = ph->handler(r);
|
|
1027
|
|
1028 if (rc == NGX_DONE) {
|
|
1029 return NGX_OK;
|
|
1030 }
|
|
1031
|
|
1032 if (rc != NGX_DECLINED) {
|
|
1033 ngx_http_finalize_request(r, rc);
|
|
1034 return NGX_OK;
|
|
1035 }
|
|
1036
|
|
1037 /* rc == NGX_DECLINED */
|
|
1038
|
|
1039 ph++;
|
|
1040
|
|
1041 if (ph->checker) {
|
|
1042 r->phase_handler++;
|
|
1043 return NGX_AGAIN;
|
|
1044 }
|
|
1045
|
|
1046 /* no content handler was found */
|
|
1047
|
|
1048 if (r->uri.data[r->uri.len - 1] == '/' && !r->zero_in_uri) {
|
|
1049
|
248
|
1050 if (ngx_http_map_uri_to_path(r, &path, &root, 0) != NULL) {
|
230
|
1051 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
340
|
1052 "directory index of \"%s\" is forbidden", path.data);
|
230
|
1053 }
|
|
1054
|
|
1055 ngx_http_finalize_request(r, NGX_HTTP_FORBIDDEN);
|
|
1056 return NGX_OK;
|
|
1057 }
|
|
1058
|
|
1059 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no handler found");
|
|
1060
|
|
1061 ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
|
84
|
1062 return NGX_OK;
|
|
1063 }
|
|
1064
|
|
1065
|
|
1066 void
|
|
1067 ngx_http_update_location_config(ngx_http_request_t *r)
|
|
1068 {
|
|
1069 ngx_http_core_loc_conf_t *clcf;
|
|
1070
|
|
1071 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1072
|
180
|
1073 if (r->method & clcf->limit_except) {
|
|
1074 r->loc_conf = clcf->limit_except_loc_conf;
|
|
1075 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1076 }
|
|
1077
|
192
|
1078 if (r == r->main) {
|
294
|
1079 r->connection->log->file = clcf->err_log->file;
|
|
1080
|
192
|
1081 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
|
|
1082 r->connection->log->log_level = clcf->err_log->log_level;
|
|
1083 }
|
84
|
1084 }
|
|
1085
|
|
1086 if ((ngx_io.flags & NGX_IO_SENDFILE) && clcf->sendfile) {
|
|
1087 r->connection->sendfile = 1;
|
|
1088
|
|
1089 } else {
|
|
1090 r->connection->sendfile = 0;
|
|
1091 }
|
|
1092
|
182
|
1093 if (clcf->client_body_in_file_only) {
|
|
1094 r->request_body_in_file_only = 1;
|
|
1095 r->request_body_in_persistent_file = 1;
|
278
|
1096 r->request_body_in_clean_file =
|
|
1097 clcf->client_body_in_file_only == NGX_HTTP_REQUEST_BODY_FILE_CLEAN;
|
186
|
1098 r->request_body_file_log_level = NGX_LOG_NOTICE;
|
|
1099
|
|
1100 } else {
|
|
1101 r->request_body_file_log_level = NGX_LOG_WARN;
|
182
|
1102 }
|
|
1103
|
84
|
1104 if (r->keepalive && clcf->keepalive_timeout == 0) {
|
|
1105 r->keepalive = 0;
|
|
1106 }
|
|
1107
|
|
1108 if (!clcf->tcp_nopush) {
|
|
1109 /* disable TCP_NOPUSH/TCP_CORK use */
|
|
1110 r->connection->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;
|
|
1111 }
|
|
1112
|
162
|
1113 if (r->limit_rate == 0) {
|
|
1114 r->limit_rate = clcf->limit_rate;
|
|
1115 }
|
76
|
1116
|
0
|
1117 if (clcf->handler) {
|
|
1118 r->content_handler = clcf->handler;
|
|
1119 }
|
|
1120 }
|
|
1121
|
|
1122
|
36
|
1123 static ngx_int_t
|
|
1124 ngx_http_core_find_location(ngx_http_request_t *r,
|
308
|
1125 ngx_array_t *locations, ngx_uint_t regex_start, size_t len)
|
0
|
1126 {
|
|
1127 ngx_int_t n, rc;
|
326
|
1128 ngx_uint_t i, found;
|
0
|
1129 ngx_http_core_loc_conf_t *clcf, **clcfp;
|
326
|
1130 #if (NGX_PCRE)
|
|
1131 ngx_uint_t noregex;
|
|
1132 #endif
|
0
|
1133
|
104
|
1134 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1135 "find location for \"%V\"", &r->uri);
|
0
|
1136
|
|
1137 found = 0;
|
326
|
1138 #if (NGX_PCRE)
|
16
|
1139 noregex = 0;
|
326
|
1140 #endif
|
0
|
1141
|
|
1142 clcfp = locations->elts;
|
|
1143 for (i = 0; i < locations->nelts; i++) {
|
|
1144
|
324
|
1145 if (clcfp[i]->noname
|
4
|
1146 #if (NGX_PCRE)
|
324
|
1147 || clcfp[i]->regex
|
0
|
1148 #endif
|
324
|
1149 || clcfp[i]->named)
|
|
1150 {
|
34
|
1151 break;
|
|
1152 }
|
|
1153
|
0
|
1154 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
10
|
1155 "find location: %s\"%V\"",
|
|
1156 clcfp[i]->exact_match ? "= " : "", &clcfp[i]->name);
|
0
|
1157
|
|
1158 if (clcfp[i]->auto_redirect
|
|
1159 && r->uri.len == clcfp[i]->name.len - 1
|
|
1160 && ngx_strncmp(r->uri.data, clcfp[i]->name.data,
|
274
|
1161 clcfp[i]->name.len - 1)
|
|
1162 == 0)
|
0
|
1163 {
|
|
1164 /* the locations are lexicographically sorted */
|
|
1165
|
|
1166 r->loc_conf = clcfp[i]->loc_conf;
|
|
1167
|
|
1168 return NGX_HTTP_LOCATION_AUTO_REDIRECT;
|
|
1169 }
|
|
1170
|
|
1171 if (r->uri.len < clcfp[i]->name.len) {
|
|
1172 continue;
|
|
1173 }
|
|
1174
|
|
1175 n = ngx_strncmp(r->uri.data, clcfp[i]->name.data, clcfp[i]->name.len);
|
|
1176
|
|
1177 if (n < 0) {
|
|
1178 /* the locations are lexicographically sorted */
|
|
1179 break;
|
|
1180 }
|
|
1181
|
|
1182 if (n == 0) {
|
34
|
1183 if (clcfp[i]->exact_match) {
|
|
1184
|
|
1185 if (r->uri.len == clcfp[i]->name.len) {
|
|
1186 r->loc_conf = clcfp[i]->loc_conf;
|
|
1187 return NGX_HTTP_LOCATION_EXACT;
|
|
1188 }
|
|
1189
|
|
1190 continue;
|
0
|
1191 }
|
|
1192
|
|
1193 if (len > clcfp[i]->name.len) {
|
|
1194 /* the previous match is longer */
|
|
1195 break;
|
|
1196 }
|
|
1197
|
326
|
1198 found = 1;
|
|
1199
|
0
|
1200 r->loc_conf = clcfp[i]->loc_conf;
|
326
|
1201 #if (NGX_PCRE)
|
16
|
1202 noregex = clcfp[i]->noregex;
|
326
|
1203 #endif
|
0
|
1204 }
|
|
1205 }
|
|
1206
|
|
1207 if (found) {
|
|
1208 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1209
|
308
|
1210 if (clcf->locations) {
|
|
1211 rc = ngx_http_core_find_location(r, clcf->locations,
|
|
1212 clcf->regex_start, len);
|
0
|
1213
|
|
1214 if (rc != NGX_OK) {
|
|
1215 return rc;
|
|
1216 }
|
|
1217 }
|
|
1218 }
|
|
1219
|
4
|
1220 #if (NGX_PCRE)
|
0
|
1221
|
16
|
1222 if (noregex) {
|
|
1223 return NGX_HTTP_LOCATION_NOREGEX;
|
|
1224 }
|
|
1225
|
0
|
1226 /* regex matches */
|
|
1227
|
308
|
1228 for (i = regex_start; i < locations->nelts; i++) {
|
0
|
1229
|
324
|
1230 if (!clcfp[i]->regex) {
|
34
|
1231 break;
|
|
1232 }
|
|
1233
|
0
|
1234 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
10
|
1235 "find location: ~ \"%V\"", &clcfp[i]->name);
|
0
|
1236
|
|
1237 n = ngx_regex_exec(clcfp[i]->regex, &r->uri, NULL, 0);
|
|
1238
|
30
|
1239 if (n == NGX_REGEX_NO_MATCHED) {
|
0
|
1240 continue;
|
|
1241 }
|
|
1242
|
|
1243 if (n < 0) {
|
|
1244 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
|
1245 ngx_regex_exec_n
|
10
|
1246 " failed: %d on \"%V\" using \"%V\"",
|
|
1247 n, &r->uri, &clcfp[i]->name);
|
0
|
1248 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
1249 }
|
|
1250
|
|
1251 /* match */
|
|
1252
|
|
1253 r->loc_conf = clcfp[i]->loc_conf;
|
|
1254
|
|
1255 return NGX_HTTP_LOCATION_REGEX;
|
|
1256 }
|
|
1257
|
4
|
1258 #endif /* NGX_PCRE */
|
0
|
1259
|
|
1260 return NGX_OK;
|
|
1261 }
|
|
1262
|
|
1263
|
380
|
1264 static ngx_int_t
|
|
1265 ngx_http_core_send_continue(ngx_http_request_t *r)
|
|
1266 {
|
|
1267 ngx_int_t n;
|
|
1268 ngx_str_t *expect;
|
|
1269
|
|
1270 if (r->expect_tested) {
|
|
1271 return NGX_OK;
|
|
1272 }
|
|
1273
|
|
1274 r->expect_tested = 1;
|
|
1275
|
|
1276 expect = &r->headers_in.expect->value;
|
|
1277
|
|
1278 if (expect->len != sizeof("100-continue") - 1
|
|
1279 || ngx_strncasecmp(expect->data, (u_char *) "100-continue",
|
|
1280 sizeof("100-continue") - 1)
|
|
1281 != 0)
|
|
1282 {
|
|
1283 return NGX_OK;
|
|
1284 }
|
|
1285
|
|
1286 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1287 "send 100 Continue");
|
|
1288
|
|
1289 n = r->connection->send(r->connection,
|
|
1290 (u_char *) "HTTP/1.1 100 Continue" CRLF CRLF,
|
|
1291 sizeof("HTTP/1.1 100 Continue" CRLF CRLF) - 1);
|
|
1292
|
|
1293 if (n == sizeof("HTTP/1.1 100 Continue" CRLF CRLF) - 1) {
|
|
1294 return NGX_OK;
|
|
1295 }
|
|
1296
|
|
1297 /* we assume that such small packet should be send successfully */
|
|
1298
|
|
1299 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
1300 }
|
|
1301
|
|
1302
|
36
|
1303 ngx_int_t
|
|
1304 ngx_http_set_content_type(ngx_http_request_t *r)
|
0
|
1305 {
|
34
|
1306 u_char c, *p, *exten;
|
138
|
1307 ngx_str_t *type;
|
198
|
1308 ngx_uint_t i, hash;
|
0
|
1309 ngx_http_core_loc_conf_t *clcf;
|
|
1310
|
222
|
1311 if (r->headers_out.content_type.len) {
|
|
1312 return NGX_OK;
|
|
1313 }
|
|
1314
|
0
|
1315 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1316
|
|
1317 if (r->exten.len) {
|
34
|
1318
|
198
|
1319 hash = 0;
|
|
1320
|
|
1321 for (i = 0; i < r->exten.len; i++) {
|
|
1322 c = r->exten.data[i];
|
|
1323
|
|
1324 if (c >= 'A' && c <= 'Z') {
|
|
1325
|
50
|
1326 p = ngx_palloc(r->pool, r->exten.len);
|
|
1327 if (p == NULL) {
|
34
|
1328 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
1329 }
|
|
1330
|
198
|
1331 hash = 0;
|
34
|
1332 exten = p;
|
|
1333
|
|
1334 for (i = 0; i < r->exten.len; i++) {
|
198
|
1335 c = ngx_tolower(r->exten.data[i]);
|
|
1336 hash = ngx_hash(hash, c);
|
|
1337 *p++ = c;
|
34
|
1338 }
|
|
1339
|
|
1340 r->exten.data = exten;
|
198
|
1341
|
|
1342 break;
|
34
|
1343 }
|
|
1344
|
198
|
1345 hash = ngx_hash(hash, c);
|
34
|
1346 }
|
|
1347
|
198
|
1348 type = ngx_hash_find(&clcf->types_hash, hash,
|
138
|
1349 r->exten.data, r->exten.len);
|
|
1350
|
|
1351 if (type) {
|
206
|
1352 r->headers_out.content_type_len = type->len;
|
138
|
1353 r->headers_out.content_type = *type;
|
206
|
1354
|
138
|
1355 return NGX_OK;
|
0
|
1356 }
|
|
1357 }
|
|
1358
|
206
|
1359 r->headers_out.content_type_len = clcf->default_type.len;
|
138
|
1360 r->headers_out.content_type = clcf->default_type;
|
0
|
1361
|
|
1362 return NGX_OK;
|
|
1363 }
|
|
1364
|
|
1365
|
36
|
1366 ngx_int_t
|
|
1367 ngx_http_set_exten(ngx_http_request_t *r)
|
0
|
1368 {
|
|
1369 ngx_int_t i;
|
|
1370
|
|
1371 r->exten.len = 0;
|
|
1372 r->exten.data = NULL;
|
|
1373
|
|
1374 for (i = r->uri.len - 1; i > 1; i--) {
|
|
1375 if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {
|
198
|
1376
|
0
|
1377 r->exten.len = r->uri.len - i - 1;
|
198
|
1378 r->exten.data = &r->uri.data[i + 1];
|
0
|
1379
|
|
1380 break;
|
|
1381
|
|
1382 } else if (r->uri.data[i] == '/') {
|
|
1383 break;
|
|
1384 }
|
|
1385 }
|
|
1386
|
|
1387 return NGX_OK;
|
|
1388 }
|
|
1389
|
|
1390
|
36
|
1391 ngx_int_t
|
106
|
1392 ngx_http_send_header(ngx_http_request_t *r)
|
|
1393 {
|
|
1394 if (r->err_status) {
|
|
1395 r->headers_out.status = r->err_status;
|
|
1396 r->headers_out.status_line.len = 0;
|
|
1397 }
|
|
1398
|
|
1399 return ngx_http_top_header_filter(r);
|
|
1400 }
|
|
1401
|
|
1402
|
|
1403 ngx_int_t
|
|
1404 ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
|
1405 {
|
|
1406 ngx_int_t rc;
|
|
1407
|
132
|
1408 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1409 "http output filter \"%V?%V\"", &r->uri, &r->args);
|
106
|
1410
|
|
1411 rc = ngx_http_top_body_filter(r, in);
|
|
1412
|
|
1413 if (rc == NGX_ERROR) {
|
|
1414 /* NGX_ERROR may be returned by any filter */
|
132
|
1415 r->connection->error = 1;
|
106
|
1416 }
|
|
1417
|
|
1418 return rc;
|
|
1419 }
|
|
1420
|
|
1421
|
|
1422 u_char *
|
|
1423 ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,
|
248
|
1424 size_t *root_length, size_t reserved)
|
106
|
1425 {
|
172
|
1426 u_char *last;
|
|
1427 size_t alias;
|
|
1428 ngx_http_core_loc_conf_t *clcf;
|
106
|
1429
|
|
1430 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1431
|
|
1432 alias = clcf->alias ? clcf->name.len : 0;
|
|
1433
|
152
|
1434 if (alias && !r->valid_location) {
|
|
1435 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
|
1436 "\"alias\" could not be used in location \"%V\" "
|
|
1437 "where URI was rewritten", &clcf->name);
|
|
1438 return NULL;
|
|
1439 }
|
|
1440
|
172
|
1441 reserved += r->uri.len - alias + 1;
|
|
1442
|
144
|
1443 if (clcf->root_lengths == NULL) {
|
|
1444
|
248
|
1445 *root_length = clcf->root.len;
|
144
|
1446
|
172
|
1447 path->len = clcf->root.len + reserved;
|
144
|
1448
|
|
1449 path->data = ngx_palloc(r->pool, path->len);
|
|
1450 if (path->data == NULL) {
|
|
1451 return NULL;
|
|
1452 }
|
|
1453
|
|
1454 last = ngx_copy(path->data, clcf->root.data, clcf->root.len);
|
172
|
1455
|
|
1456 } else {
|
216
|
1457 if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved,
|
220
|
1458 clcf->root_values->elts)
|
216
|
1459 == NULL)
|
|
1460 {
|
|
1461 return NULL;
|
|
1462 }
|
|
1463
|
324
|
1464 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, path, 0)== NGX_ERROR)
|
|
1465 {
|
172
|
1466 return NULL;
|
|
1467 }
|
|
1468
|
248
|
1469 *root_length = path->len - reserved;
|
|
1470 last = path->data + *root_length;
|
144
|
1471 }
|
|
1472
|
172
|
1473 last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1);
|
106
|
1474
|
|
1475 return last;
|
|
1476 }
|
|
1477
|
|
1478
|
|
1479 ngx_int_t
|
88
|
1480 ngx_http_auth_basic_user(ngx_http_request_t *r)
|
|
1481 {
|
|
1482 ngx_str_t auth, encoded;
|
|
1483 ngx_uint_t len;
|
|
1484
|
|
1485 if (r->headers_in.user.len == 0 && r->headers_in.user.data != NULL) {
|
|
1486 return NGX_DECLINED;
|
|
1487 }
|
|
1488
|
|
1489 if (r->headers_in.authorization == NULL) {
|
|
1490 r->headers_in.user.data = (u_char *) "";
|
|
1491 return NGX_DECLINED;
|
|
1492 }
|
|
1493
|
|
1494 encoded = r->headers_in.authorization->value;
|
|
1495
|
|
1496 if (encoded.len < sizeof("Basic ") - 1
|
286
|
1497 || ngx_strncasecmp(encoded.data, (u_char *) "Basic ",
|
|
1498 sizeof("Basic ") - 1)
|
|
1499 != 0)
|
88
|
1500 {
|
|
1501 r->headers_in.user.data = (u_char *) "";
|
|
1502 return NGX_DECLINED;
|
|
1503 }
|
|
1504
|
|
1505 encoded.len -= sizeof("Basic ") - 1;
|
|
1506 encoded.data += sizeof("Basic ") - 1;
|
|
1507
|
|
1508 while (encoded.len && encoded.data[0] == ' ') {
|
|
1509 encoded.len--;
|
|
1510 encoded.data++;
|
|
1511 }
|
|
1512
|
|
1513 if (encoded.len == 0) {
|
|
1514 r->headers_in.user.data = (u_char *) "";
|
|
1515 return NGX_DECLINED;
|
|
1516 }
|
126
|
1517
|
88
|
1518 auth.len = ngx_base64_decoded_length(encoded.len);
|
126
|
1519 auth.data = ngx_palloc(r->pool, auth.len + 1);
|
88
|
1520 if (auth.data == NULL) {
|
|
1521 return NGX_ERROR;
|
|
1522 }
|
|
1523
|
|
1524 if (ngx_decode_base64(&auth, &encoded) != NGX_OK) {
|
|
1525 r->headers_in.user.data = (u_char *) "";
|
|
1526 return NGX_DECLINED;
|
|
1527 }
|
126
|
1528
|
88
|
1529 auth.data[auth.len] = '\0';
|
126
|
1530
|
|
1531 for (len = 0; len < auth.len; len++) {
|
88
|
1532 if (auth.data[len] == ':') {
|
|
1533 break;
|
|
1534 }
|
|
1535 }
|
126
|
1536
|
122
|
1537 if (len == 0 || len == auth.len) {
|
88
|
1538 r->headers_in.user.data = (u_char *) "";
|
|
1539 return NGX_DECLINED;
|
|
1540 }
|
|
1541
|
|
1542 r->headers_in.user.len = len;
|
|
1543 r->headers_in.user.data = auth.data;
|
|
1544 r->headers_in.passwd.len = auth.len - len - 1;
|
|
1545 r->headers_in.passwd.data = &auth.data[len + 1];
|
|
1546
|
|
1547 return NGX_OK;
|
|
1548 }
|
|
1549
|
|
1550
|
362
|
1551 ngx_int_t
|
|
1552 ngx_http_server_addr(ngx_http_request_t *r, ngx_str_t *s)
|
|
1553 {
|
|
1554 socklen_t len;
|
|
1555 ngx_connection_t *c;
|
|
1556 struct sockaddr_in sin;
|
|
1557
|
|
1558 /* AF_INET only */
|
|
1559
|
|
1560 c = r->connection;
|
|
1561
|
|
1562 if (r->in_addr == 0) {
|
|
1563 len = sizeof(struct sockaddr_in);
|
|
1564 if (getsockname(c->fd, (struct sockaddr *) &sin, &len) == -1) {
|
|
1565 ngx_connection_error(c, ngx_socket_errno, "getsockname() failed");
|
|
1566 return NGX_ERROR;
|
|
1567 }
|
|
1568
|
|
1569 r->in_addr = sin.sin_addr.s_addr;
|
|
1570 }
|
|
1571
|
|
1572 if (s == NULL) {
|
|
1573 return NGX_OK;
|
|
1574 }
|
|
1575
|
|
1576 s->len = ngx_inet_ntop(c->listening->family, &r->in_addr,
|
|
1577 s->data, INET_ADDRSTRLEN);
|
|
1578
|
|
1579 return NGX_OK;
|
|
1580 }
|
|
1581
|
|
1582
|
358
|
1583 #if (NGX_HTTP_GZIP)
|
|
1584
|
|
1585 ngx_int_t
|
|
1586 ngx_http_gzip_ok(ngx_http_request_t *r)
|
|
1587 {
|
|
1588 time_t date, expires;
|
|
1589 ngx_uint_t p;
|
|
1590 ngx_array_t *cc;
|
|
1591 ngx_table_elt_t *e, *d;
|
|
1592 ngx_http_core_loc_conf_t *clcf;
|
|
1593
|
|
1594 if (r->gzip == 1) {
|
|
1595 return NGX_OK;
|
|
1596 }
|
|
1597
|
|
1598 if (r->gzip == 2) {
|
|
1599 return NGX_DECLINED;
|
|
1600 }
|
|
1601
|
|
1602 r->gzip = 2;
|
|
1603
|
|
1604 if (r != r->main
|
|
1605 || r->headers_in.accept_encoding == NULL
|
|
1606 || ngx_strcasestrn(r->headers_in.accept_encoding->value.data,
|
|
1607 "gzip", 4 - 1)
|
|
1608 == NULL
|
|
1609
|
|
1610 /*
|
|
1611 * if the URL (without the "http://" prefix) is longer than 253 bytes,
|
|
1612 * then MSIE 4.x can not handle the compressed stream - it waits
|
|
1613 * too long, hangs up or crashes
|
|
1614 */
|
|
1615
|
|
1616 || (r->headers_in.msie4 && r->unparsed_uri.len > 200))
|
|
1617 {
|
|
1618 return NGX_DECLINED;
|
|
1619 }
|
|
1620
|
|
1621 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1622
|
|
1623 if (r->http_version < clcf->gzip_http_version) {
|
|
1624 return NGX_DECLINED;
|
|
1625 }
|
|
1626
|
|
1627 if (r->headers_in.via == NULL) {
|
|
1628 goto ok;
|
|
1629 }
|
|
1630
|
|
1631 p = clcf->gzip_proxied;
|
|
1632
|
|
1633 if (p & NGX_HTTP_GZIP_PROXIED_OFF) {
|
|
1634 return NGX_DECLINED;
|
|
1635 }
|
|
1636
|
|
1637 if (p & NGX_HTTP_GZIP_PROXIED_ANY) {
|
|
1638 goto ok;
|
|
1639 }
|
|
1640
|
|
1641 if (r->headers_in.authorization && (p & NGX_HTTP_GZIP_PROXIED_AUTH)) {
|
|
1642 goto ok;
|
|
1643 }
|
|
1644
|
|
1645 e = r->headers_out.expires;
|
|
1646
|
|
1647 if (e) {
|
|
1648
|
|
1649 if (!(p & NGX_HTTP_GZIP_PROXIED_EXPIRED)) {
|
|
1650 return NGX_DECLINED;
|
|
1651 }
|
|
1652
|
|
1653 expires = ngx_http_parse_time(e->value.data, e->value.len);
|
|
1654 if (expires == NGX_ERROR) {
|
|
1655 return NGX_DECLINED;
|
|
1656 }
|
|
1657
|
|
1658 d = r->headers_out.date;
|
|
1659
|
|
1660 if (d) {
|
|
1661 date = ngx_http_parse_time(d->value.data, d->value.len);
|
|
1662 if (date == NGX_ERROR) {
|
|
1663 return NGX_DECLINED;
|
|
1664 }
|
|
1665
|
|
1666 } else {
|
|
1667 date = ngx_time();
|
|
1668 }
|
|
1669
|
|
1670 if (expires < date) {
|
|
1671 goto ok;
|
|
1672 }
|
|
1673
|
|
1674 return NGX_DECLINED;
|
|
1675 }
|
|
1676
|
|
1677 cc = &r->headers_out.cache_control;
|
|
1678
|
|
1679 if (cc->elts) {
|
|
1680
|
|
1681 if ((p & NGX_HTTP_GZIP_PROXIED_NO_CACHE)
|
|
1682 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_cache,
|
|
1683 NULL)
|
|
1684 >= 0)
|
|
1685 {
|
|
1686 goto ok;
|
|
1687 }
|
|
1688
|
|
1689 if ((p & NGX_HTTP_GZIP_PROXIED_NO_STORE)
|
|
1690 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_store,
|
|
1691 NULL)
|
|
1692 >= 0)
|
|
1693 {
|
|
1694 goto ok;
|
|
1695 }
|
|
1696
|
|
1697 if ((p & NGX_HTTP_GZIP_PROXIED_PRIVATE)
|
|
1698 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_private,
|
|
1699 NULL)
|
|
1700 >= 0)
|
|
1701 {
|
|
1702 goto ok;
|
|
1703 }
|
|
1704
|
|
1705 return NGX_DECLINED;
|
|
1706 }
|
|
1707
|
|
1708 if ((p & NGX_HTTP_GZIP_PROXIED_NO_LM) && r->headers_out.last_modified) {
|
|
1709 return NGX_DECLINED;
|
|
1710 }
|
|
1711
|
|
1712 if ((p & NGX_HTTP_GZIP_PROXIED_NO_ETAG) && r->headers_out.etag) {
|
|
1713 return NGX_DECLINED;
|
|
1714 }
|
|
1715
|
|
1716 ok:
|
|
1717
|
|
1718 #if (NGX_PCRE)
|
|
1719
|
|
1720 if (clcf->gzip_disable && r->headers_in.user_agent) {
|
|
1721
|
362
|
1722 if (ngx_regex_exec_array(clcf->gzip_disable,
|
358
|
1723 &r->headers_in.user_agent->value,
|
|
1724 r->connection->log)
|
|
1725 != NGX_DECLINED)
|
|
1726 {
|
|
1727 return NGX_DECLINED;
|
|
1728 }
|
|
1729 }
|
|
1730
|
|
1731 #endif
|
|
1732
|
|
1733 r->gzip = 1;
|
|
1734
|
|
1735 return NGX_OK;
|
|
1736 }
|
|
1737
|
|
1738 #endif
|
|
1739
|
|
1740
|
88
|
1741 ngx_int_t
|
58
|
1742 ngx_http_subrequest(ngx_http_request_t *r,
|
244
|
1743 ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **psr,
|
248
|
1744 ngx_http_post_subrequest_t *ps, ngx_uint_t flags)
|
58
|
1745 {
|
132
|
1746 ngx_connection_t *c;
|
58
|
1747 ngx_http_request_t *sr;
|
214
|
1748 ngx_http_log_ctx_t *ctx;
|
58
|
1749 ngx_http_core_srv_conf_t *cscf;
|
|
1750 ngx_http_postponed_request_t *pr, *p;
|
|
1751
|
206
|
1752 r->main->subrequests--;
|
|
1753
|
|
1754 if (r->main->subrequests == 0) {
|
|
1755 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
228
|
1756 "subrequests cycle while processing \"%V\"", uri);
|
256
|
1757 r->main->subrequests = 1;
|
206
|
1758 return NGX_ERROR;
|
|
1759 }
|
|
1760
|
58
|
1761 sr = ngx_pcalloc(r->pool, sizeof(ngx_http_request_t));
|
|
1762 if (sr == NULL) {
|
194
|
1763 return NGX_ERROR;
|
58
|
1764 }
|
|
1765
|
|
1766 sr->signature = NGX_HTTP_MODULE;
|
132
|
1767
|
|
1768 c = r->connection;
|
|
1769 sr->connection = c;
|
58
|
1770
|
|
1771 sr->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
|
|
1772 if (sr->ctx == NULL) {
|
194
|
1773 return NGX_ERROR;
|
58
|
1774 }
|
|
1775
|
|
1776 if (ngx_list_init(&sr->headers_out.headers, r->pool, 20,
|
130
|
1777 sizeof(ngx_table_elt_t))
|
|
1778 == NGX_ERROR)
|
58
|
1779 {
|
194
|
1780 return NGX_ERROR;
|
58
|
1781 }
|
|
1782
|
|
1783 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
|
1784 sr->main_conf = cscf->ctx->main_conf;
|
|
1785 sr->srv_conf = cscf->ctx->srv_conf;
|
|
1786 sr->loc_conf = cscf->ctx->loc_conf;
|
|
1787
|
|
1788 sr->pool = r->pool;
|
|
1789
|
|
1790 sr->headers_in = r->headers_in;
|
|
1791
|
126
|
1792 ngx_http_clear_content_length(sr);
|
|
1793 ngx_http_clear_accept_ranges(sr);
|
|
1794 ngx_http_clear_last_modified(sr);
|
58
|
1795
|
|
1796 sr->request_body = r->request_body;
|
|
1797
|
|
1798 sr->method = NGX_HTTP_GET;
|
|
1799 sr->http_version = r->http_version;
|
|
1800
|
|
1801 sr->request_line = r->request_line;
|
|
1802 sr->uri = *uri;
|
122
|
1803
|
58
|
1804 if (args) {
|
|
1805 sr->args = *args;
|
|
1806 }
|
122
|
1807
|
132
|
1808 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
|
1809 "http subrequest \"%V?%V\"", uri, &sr->args);
|
|
1810
|
248
|
1811 sr->zero_in_uri = (flags & NGX_HTTP_ZERO_IN_URI) != 0;
|
|
1812 sr->subrequest_in_memory = (flags & NGX_HTTP_SUBREQUEST_IN_MEMORY) != 0;
|
122
|
1813
|
58
|
1814 sr->unparsed_uri = r->unparsed_uri;
|
364
|
1815 sr->method_name = ngx_http_core_get_method;
|
58
|
1816 sr->http_protocol = r->http_protocol;
|
|
1817
|
|
1818 if (ngx_http_set_exten(sr) != NGX_OK) {
|
194
|
1819 return NGX_ERROR;
|
58
|
1820 }
|
|
1821
|
102
|
1822 sr->main = r->main;
|
58
|
1823 sr->parent = r;
|
248
|
1824 sr->post_subrequest = ps;
|
58
|
1825 sr->read_event_handler = ngx_http_request_empty_handler;
|
|
1826 sr->write_event_handler = ngx_http_request_empty_handler;
|
|
1827
|
132
|
1828 if (c->data == r) {
|
|
1829 c->data = sr;
|
58
|
1830 }
|
|
1831
|
|
1832 sr->in_addr = r->in_addr;
|
|
1833 sr->port = r->port;
|
|
1834 sr->port_text = r->port_text;
|
|
1835
|
|
1836 sr->variables = r->variables;
|
|
1837
|
|
1838 sr->log_handler = r->log_handler;
|
|
1839
|
|
1840 pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t));
|
|
1841 if (pr == NULL) {
|
194
|
1842 return NGX_ERROR;
|
58
|
1843 }
|
|
1844
|
|
1845 pr->request = sr;
|
|
1846 pr->out = NULL;
|
|
1847 pr->next = NULL;
|
|
1848
|
|
1849 if (r->postponed) {
|
|
1850 for (p = r->postponed; p->next; p = p->next) { /* void */ }
|
|
1851 p->next = pr;
|
|
1852
|
|
1853 } else {
|
|
1854 r->postponed = pr;
|
|
1855 }
|
|
1856
|
214
|
1857 ctx = c->log->data;
|
|
1858 ctx->current_request = sr;
|
|
1859
|
58
|
1860 sr->internal = 1;
|
146
|
1861 sr->fast_subrequest = 1;
|
58
|
1862
|
92
|
1863 sr->discard_body = r->discard_body;
|
62
|
1864 sr->main_filter_need_in_memory = r->main_filter_need_in_memory;
|
|
1865
|
200
|
1866 sr->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1;
|
|
1867
|
58
|
1868 ngx_http_handler(sr);
|
|
1869
|
132
|
1870 if (!c->destroyed) {
|
|
1871 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
|
1872 "http subrequest done \"%V?%V\"", uri, &sr->args);
|
194
|
1873
|
256
|
1874 r->main->subrequests++;
|
|
1875
|
244
|
1876 *psr = sr;
|
|
1877
|
194
|
1878 if (sr->fast_subrequest) {
|
|
1879 sr->fast_subrequest = 0;
|
|
1880
|
|
1881 if (sr->done) {
|
|
1882 return NGX_OK;
|
|
1883 }
|
|
1884 }
|
|
1885
|
|
1886 return NGX_AGAIN;
|
132
|
1887 }
|
58
|
1888
|
248
|
1889 return NGX_DONE;
|
58
|
1890 }
|
|
1891
|
|
1892
|
|
1893 ngx_int_t
|
36
|
1894 ngx_http_internal_redirect(ngx_http_request_t *r,
|
|
1895 ngx_str_t *uri, ngx_str_t *args)
|
0
|
1896 {
|
36
|
1897 ngx_http_core_srv_conf_t *cscf;
|
|
1898
|
226
|
1899 r->uri_changes--;
|
|
1900
|
|
1901 if (r->uri_changes == 0) {
|
|
1902 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
228
|
1903 "rewrite or internal redirection cycle "
|
|
1904 "while internal redirect to \"%V\"", uri);
|
|
1905
|
226
|
1906 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
1907 return NGX_DONE;
|
|
1908 }
|
|
1909
|
10
|
1910 r->uri = *uri;
|
0
|
1911
|
|
1912 if (args) {
|
10
|
1913 r->args = *args;
|
58
|
1914
|
|
1915 } else {
|
|
1916 r->args.len = 0;
|
|
1917 r->args.data = NULL;
|
0
|
1918 }
|
|
1919
|
132
|
1920 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1921 "internal redirect: \"%V?%V\"", uri, &r->args);
|
|
1922
|
0
|
1923 if (ngx_http_set_exten(r) != NGX_OK) {
|
226
|
1924 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
1925 return NGX_DONE;
|
0
|
1926 }
|
|
1927
|
224
|
1928 /* clear the modules contexts */
|
|
1929 ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
|
0
|
1930
|
36
|
1931 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
|
1932 r->loc_conf = cscf->ctx->loc_conf;
|
|
1933
|
84
|
1934 ngx_http_update_location_config(r);
|
|
1935
|
58
|
1936 r->internal = 1;
|
|
1937
|
0
|
1938 ngx_http_handler(r);
|
|
1939
|
|
1940 return NGX_DONE;
|
|
1941 }
|
|
1942
|
|
1943
|
324
|
1944 ngx_int_t
|
|
1945 ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name)
|
|
1946 {
|
|
1947 ngx_uint_t i;
|
|
1948 ngx_http_core_srv_conf_t *cscf;
|
|
1949 ngx_http_core_loc_conf_t **clcfp;
|
|
1950 ngx_http_core_main_conf_t *cmcf;
|
|
1951
|
|
1952 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
|
1953
|
|
1954 clcfp = cscf->locations.elts;
|
|
1955
|
|
1956 for (i = cscf->named_start; i < cscf->locations.nelts; i++) {
|
|
1957
|
|
1958 if (name->len != clcfp[i]->name.len
|
|
1959 || ngx_strncmp(name->data, clcfp[i]->name.data, name->len) != 0)
|
|
1960 {
|
|
1961 continue;
|
|
1962 }
|
|
1963
|
|
1964 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1965 "named location: %V \"%V?%V\"", name, &r->uri, &r->args);
|
|
1966
|
|
1967 r->internal = 1;
|
366
|
1968 r->content_handler = NULL;
|
324
|
1969 r->loc_conf = clcfp[i]->loc_conf;
|
|
1970
|
|
1971 ngx_http_update_location_config(r);
|
|
1972
|
|
1973 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
|
|
1974
|
|
1975 r->phase_handler = cmcf->phase_engine.location_rewrite_index;
|
366
|
1976
|
324
|
1977 ngx_http_core_run_phases(r);
|
|
1978
|
|
1979 return NGX_DONE;
|
|
1980 }
|
|
1981
|
|
1982 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
342
|
1983 "could not find named location \"%V\"", name);
|
324
|
1984
|
|
1985 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
1986 return NGX_DONE;
|
|
1987 }
|
|
1988
|
|
1989
|
118
|
1990 ngx_http_cleanup_t *
|
|
1991 ngx_http_cleanup_add(ngx_http_request_t *r, size_t size)
|
0
|
1992 {
|
118
|
1993 ngx_http_cleanup_t *cln;
|
|
1994
|
|
1995 r = r->main;
|
|
1996
|
|
1997 cln = ngx_palloc(r->pool, sizeof(ngx_http_cleanup_t));
|
|
1998 if (cln == NULL) {
|
|
1999 return NULL;
|
0
|
2000 }
|
|
2001
|
118
|
2002 if (size) {
|
|
2003 cln->data = ngx_palloc(r->pool, size);
|
|
2004 if (cln->data == NULL) {
|
|
2005 return NULL;
|
|
2006 }
|
|
2007
|
|
2008 } else {
|
|
2009 cln->data = NULL;
|
|
2010 }
|
|
2011
|
|
2012 cln->handler = NULL;
|
|
2013 cln->next = r->cleanup;
|
|
2014
|
|
2015 r->cleanup = cln;
|
|
2016
|
|
2017 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2018 "http cleanup add: %p", cln);
|
|
2019
|
|
2020 return cln;
|
0
|
2021 }
|
|
2022
|
|
2023
|
36
|
2024 static char *
|
|
2025 ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
0
|
2026 {
|
308
|
2027 char *rv;
|
|
2028 void *mconf;
|
310
|
2029 ngx_uint_t i;
|
308
|
2030 ngx_conf_t pcf;
|
|
2031 ngx_http_module_t *module;
|
|
2032 ngx_http_conf_ctx_t *ctx, *http_ctx;
|
|
2033 ngx_http_core_srv_conf_t *cscf, **cscfp;
|
324
|
2034 ngx_http_core_loc_conf_t **clcfp;
|
310
|
2035 ngx_http_core_main_conf_t *cmcf;
|
36
|
2036
|
50
|
2037 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
|
|
2038 if (ctx == NULL) {
|
36
|
2039 return NGX_CONF_ERROR;
|
|
2040 }
|
0
|
2041
|
|
2042 http_ctx = cf->ctx;
|
|
2043 ctx->main_conf = http_ctx->main_conf;
|
|
2044
|
|
2045 /* the server{}'s srv_conf */
|
|
2046
|
36
|
2047 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
2048 if (ctx->srv_conf == NULL) {
|
|
2049 return NGX_CONF_ERROR;
|
|
2050 }
|
0
|
2051
|
|
2052 /* the server{}'s loc_conf */
|
|
2053
|
36
|
2054 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
2055 if (ctx->loc_conf == NULL) {
|
|
2056 return NGX_CONF_ERROR;
|
|
2057 }
|
0
|
2058
|
310
|
2059 for (i = 0; ngx_modules[i]; i++) {
|
|
2060 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
|
0
|
2061 continue;
|
|
2062 }
|
|
2063
|
310
|
2064 module = ngx_modules[i]->ctx;
|
0
|
2065
|
|
2066 if (module->create_srv_conf) {
|
50
|
2067 mconf = module->create_srv_conf(cf);
|
|
2068 if (mconf == NULL) {
|
36
|
2069 return NGX_CONF_ERROR;
|
|
2070 }
|
|
2071
|
310
|
2072 ctx->srv_conf[ngx_modules[i]->ctx_index] = mconf;
|
0
|
2073 }
|
|
2074
|
|
2075 if (module->create_loc_conf) {
|
50
|
2076 mconf = module->create_loc_conf(cf);
|
|
2077 if (mconf == NULL) {
|
36
|
2078 return NGX_CONF_ERROR;
|
|
2079 }
|
|
2080
|
310
|
2081 ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
|
0
|
2082 }
|
|
2083 }
|
|
2084
|
36
|
2085
|
|
2086 /* the server configuration context */
|
0
|
2087
|
|
2088 cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
|
|
2089 cscf->ctx = ctx;
|
|
2090
|
36
|
2091
|
0
|
2092 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
|
36
|
2093
|
50
|
2094 cscfp = ngx_array_push(&cmcf->servers);
|
|
2095 if (cscfp == NULL) {
|
36
|
2096 return NGX_CONF_ERROR;
|
|
2097 }
|
|
2098
|
0
|
2099 *cscfp = cscf;
|
|
2100
|
36
|
2101
|
0
|
2102 /* parse inside server{} */
|
|
2103
|
70
|
2104 pcf = *cf;
|
0
|
2105 cf->ctx = ctx;
|
|
2106 cf->cmd_type = NGX_HTTP_SRV_CONF;
|
34
|
2107
|
0
|
2108 rv = ngx_conf_parse(cf, NULL);
|
34
|
2109
|
70
|
2110 *cf = pcf;
|
0
|
2111
|
|
2112 if (rv != NGX_CONF_OK) {
|
|
2113 return rv;
|
|
2114 }
|
|
2115
|
302
|
2116 ngx_sort(cscf->locations.elts, (size_t) cscf->locations.nelts,
|
|
2117 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations);
|
0
|
2118
|
324
|
2119 clcfp = cscf->locations.elts;
|
|
2120
|
310
|
2121 #if (NGX_PCRE)
|
|
2122
|
308
|
2123 cscf->regex_start = cscf->locations.nelts;
|
|
2124
|
|
2125 for (i = 0; i < cscf->locations.nelts; i++) {
|
|
2126 if (clcfp[i]->regex) {
|
|
2127 cscf->regex_start = i;
|
|
2128 break;
|
|
2129 }
|
|
2130 }
|
|
2131
|
310
|
2132 #endif
|
|
2133
|
324
|
2134 cscf->named_start = cscf->locations.nelts;
|
|
2135
|
|
2136 for (i = 0; i < cscf->locations.nelts; i++) {
|
|
2137 if (clcfp[i]->named) {
|
|
2138 cscf->named_start = i;
|
|
2139 break;
|
|
2140 }
|
|
2141 }
|
|
2142
|
0
|
2143 return rv;
|
|
2144 }
|
|
2145
|
|
2146
|
36
|
2147 static char *
|
|
2148 ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
0
|
2149 {
|
|
2150 char *rv;
|
310
|
2151 ngx_uint_t i;
|
0
|
2152 ngx_str_t *value;
|
34
|
2153 ngx_conf_t save;
|
0
|
2154 ngx_http_module_t *module;
|
|
2155 ngx_http_conf_ctx_t *ctx, *pctx;
|
|
2156 ngx_http_core_srv_conf_t *cscf;
|
|
2157 ngx_http_core_loc_conf_t *clcf, *pclcf, **clcfp;
|
|
2158
|
50
|
2159 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
|
|
2160 if (ctx == NULL) {
|
0
|
2161 return NGX_CONF_ERROR;
|
|
2162 }
|
|
2163
|
|
2164 pctx = cf->ctx;
|
|
2165 ctx->main_conf = pctx->main_conf;
|
|
2166 ctx->srv_conf = pctx->srv_conf;
|
|
2167
|
|
2168 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
2169 if (ctx->loc_conf == NULL) {
|
|
2170 return NGX_CONF_ERROR;
|
|
2171 }
|
|
2172
|
310
|
2173 for (i = 0; ngx_modules[i]; i++) {
|
|
2174 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
|
0
|
2175 continue;
|
|
2176 }
|
|
2177
|
310
|
2178 module = ngx_modules[i]->ctx;
|
0
|
2179
|
|
2180 if (module->create_loc_conf) {
|
310
|
2181 ctx->loc_conf[ngx_modules[i]->ctx_index] =
|
0
|
2182 module->create_loc_conf(cf);
|
310
|
2183 if (ctx->loc_conf[ngx_modules[i]->ctx_index] == NULL) {
|
0
|
2184 return NGX_CONF_ERROR;
|
|
2185 }
|
|
2186 }
|
|
2187 }
|
|
2188
|
|
2189 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
|
|
2190 clcf->loc_conf = ctx->loc_conf;
|
|
2191
|
|
2192 value = cf->args->elts;
|
|
2193
|
|
2194 if (cf->args->nelts == 3) {
|
|
2195 if (value[1].len == 1 && value[1].data[0] == '=') {
|
12
|
2196 clcf->name = value[2];
|
0
|
2197 clcf->exact_match = 1;
|
|
2198
|
16
|
2199 } else if (value[1].len == 2
|
|
2200 && value[1].data[0] == '^'
|
|
2201 && value[1].data[1] == '~')
|
|
2202 {
|
|
2203 clcf->name = value[2];
|
|
2204 clcf->noregex = 1;
|
|
2205
|
0
|
2206 } else if ((value[1].len == 1 && value[1].data[0] == '~')
|
|
2207 || (value[1].len == 2
|
|
2208 && value[1].data[0] == '~'
|
|
2209 && value[1].data[1] == '*'))
|
|
2210 {
|
4
|
2211 #if (NGX_PCRE)
|
356
|
2212 ngx_str_t err;
|
|
2213 u_char errstr[NGX_MAX_CONF_ERRSTR];
|
|
2214
|
0
|
2215 err.len = NGX_MAX_CONF_ERRSTR;
|
|
2216 err.data = errstr;
|
|
2217
|
|
2218 clcf->regex = ngx_regex_compile(&value[2],
|
|
2219 value[1].len == 2 ? NGX_REGEX_CASELESS: 0,
|
|
2220 cf->pool, &err);
|
|
2221
|
|
2222 if (clcf->regex == NULL) {
|
|
2223 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
|
|
2224 return NGX_CONF_ERROR;
|
|
2225 }
|
|
2226
|
|
2227 clcf->name = value[2];
|
|
2228 #else
|
|
2229 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
2230 "the using of the regex \"%V\" "
|
|
2231 "requires PCRE library", &value[2]);
|
0
|
2232 return NGX_CONF_ERROR;
|
|
2233 #endif
|
|
2234
|
|
2235 } else {
|
|
2236 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
2237 "invalid location modifier \"%V\"", &value[1]);
|
0
|
2238 return NGX_CONF_ERROR;
|
|
2239 }
|
|
2240
|
|
2241 } else {
|
324
|
2242
|
12
|
2243 clcf->name = value[1];
|
324
|
2244
|
|
2245 if (value[1].data[0] == '@') {
|
|
2246 clcf->named = 1;
|
|
2247 }
|
0
|
2248 }
|
|
2249
|
|
2250 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
|
|
2251
|
|
2252 if (pclcf->name.len == 0) {
|
|
2253 cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
|
50
|
2254
|
|
2255 clcfp = ngx_array_push(&cscf->locations);
|
|
2256 if (clcfp == NULL) {
|
0
|
2257 return NGX_CONF_ERROR;
|
|
2258 }
|
|
2259
|
|
2260 } else {
|
34
|
2261 #if 0
|
0
|
2262 clcf->prev_location = pclcf;
|
34
|
2263 #endif
|
0
|
2264
|
|
2265 if (pclcf->exact_match) {
|
|
2266 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
2267 "location \"%V\" could not be inside "
|
|
2268 "the exact location \"%V\"",
|
|
2269 &clcf->name, &pclcf->name);
|
0
|
2270 return NGX_CONF_ERROR;
|
|
2271 }
|
|
2272
|
324
|
2273 if (pclcf->named) {
|
|
2274 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2275 "location \"%V\" could not be inside "
|
|
2276 "the named location \"%V\"",
|
|
2277 &clcf->name, &pclcf->name);
|
|
2278 return NGX_CONF_ERROR;
|
|
2279 }
|
|
2280
|
4
|
2281 #if (NGX_PCRE)
|
0
|
2282 if (clcf->regex == NULL
|
|
2283 && ngx_strncmp(clcf->name.data, pclcf->name.data, pclcf->name.len)
|
302
|
2284 != 0)
|
0
|
2285 #else
|
|
2286 if (ngx_strncmp(clcf->name.data, pclcf->name.data, pclcf->name.len)
|
302
|
2287 != 0)
|
0
|
2288 #endif
|
|
2289 {
|
|
2290 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
2291 "location \"%V\" is outside location \"%V\"",
|
|
2292 &clcf->name, &pclcf->name);
|
0
|
2293 return NGX_CONF_ERROR;
|
|
2294 }
|
|
2295
|
308
|
2296 if (pclcf->locations == NULL) {
|
|
2297 pclcf->locations = ngx_array_create(cf->pool, 2, sizeof(void *));
|
|
2298
|
|
2299 if (pclcf->locations == NULL) {
|
50
|
2300 return NGX_CONF_ERROR;
|
|
2301 }
|
0
|
2302 }
|
|
2303
|
308
|
2304 clcfp = ngx_array_push(pclcf->locations);
|
50
|
2305 if (clcfp == NULL) {
|
0
|
2306 return NGX_CONF_ERROR;
|
|
2307 }
|
|
2308 }
|
|
2309
|
|
2310 *clcfp = clcf;
|
|
2311
|
34
|
2312 save = *cf;
|
0
|
2313 cf->ctx = ctx;
|
|
2314 cf->cmd_type = NGX_HTTP_LOC_CONF;
|
34
|
2315
|
0
|
2316 rv = ngx_conf_parse(cf, NULL);
|
34
|
2317
|
|
2318 *cf = save;
|
|
2319
|
|
2320 if (rv != NGX_CONF_OK) {
|
|
2321 return rv;
|
|
2322 }
|
|
2323
|
308
|
2324 if (clcf->locations == NULL) {
|
|
2325 return rv;
|
|
2326 }
|
|
2327
|
|
2328 ngx_sort(clcf->locations->elts, (size_t) clcf->locations->nelts,
|
302
|
2329 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations);
|
0
|
2330
|
310
|
2331 #if (NGX_PCRE)
|
|
2332
|
308
|
2333 clcf->regex_start = clcf->locations->nelts;
|
|
2334 clcfp = clcf->locations->elts;
|
|
2335
|
|
2336 for (i = 0; i < clcf->locations->nelts; i++) {
|
|
2337 if (clcfp[i]->regex) {
|
|
2338 clcf->regex_start = i;
|
|
2339 break;
|
|
2340 }
|
|
2341 }
|
|
2342
|
310
|
2343 #endif
|
|
2344
|
0
|
2345 return rv;
|
|
2346 }
|
|
2347
|
|
2348
|
372
|
2349 static ngx_int_t
|
36
|
2350 ngx_http_core_cmp_locations(const void *one, const void *two)
|
34
|
2351 {
|
|
2352 ngx_int_t rc;
|
|
2353 ngx_http_core_loc_conf_t *first, *second;
|
|
2354
|
|
2355 first = *(ngx_http_core_loc_conf_t **) one;
|
|
2356 second = *(ngx_http_core_loc_conf_t **) two;
|
|
2357
|
324
|
2358 if (first->named && !second->named) {
|
|
2359 /* shift named locations to the end */
|
|
2360 return 1;
|
|
2361 }
|
|
2362
|
|
2363 if (!first->named && second->named) {
|
|
2364 /* shift named locations to the end */
|
|
2365 return -1;
|
|
2366 }
|
|
2367
|
|
2368 if (first->named && second->named) {
|
|
2369 return ngx_strcmp(first->name.data, second->name.data);
|
|
2370 }
|
|
2371
|
34
|
2372 if (first->noname && !second->noname) {
|
|
2373 /* shift no named locations to the end */
|
|
2374 return 1;
|
|
2375 }
|
|
2376
|
|
2377 if (!first->noname && second->noname) {
|
|
2378 /* shift no named locations to the end */
|
|
2379 return -1;
|
|
2380 }
|
|
2381
|
|
2382 if (first->noname || second->noname) {
|
|
2383 /* do not sort no named locations */
|
|
2384 return 0;
|
|
2385 }
|
|
2386
|
|
2387 #if (NGX_PCRE)
|
|
2388
|
|
2389 if (first->regex && !second->regex) {
|
|
2390 /* shift the regex matches to the end */
|
|
2391 return 1;
|
|
2392 }
|
|
2393
|
|
2394 if (!first->regex && second->regex) {
|
|
2395 /* shift the regex matches to the end */
|
|
2396 return -1;
|
|
2397 }
|
|
2398
|
|
2399 if (first->regex || second->regex) {
|
|
2400 /* do not sort the regex matches */
|
|
2401 return 0;
|
|
2402 }
|
|
2403
|
|
2404 #endif
|
|
2405
|
|
2406 rc = ngx_strcmp(first->name.data, second->name.data);
|
|
2407
|
|
2408 if (rc == 0 && second->exact_match) {
|
|
2409 /* an exact match must be before the same inclusive one */
|
|
2410 return 1;
|
|
2411 }
|
|
2412
|
372
|
2413 return rc;
|
34
|
2414 }
|
|
2415
|
|
2416
|
36
|
2417 static char *
|
|
2418 ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
2419 {
|
186
|
2420 ngx_http_core_loc_conf_t *lcf = conf;
|
|
2421
|
0
|
2422 char *rv;
|
34
|
2423 ngx_conf_t save;
|
0
|
2424
|
186
|
2425 if (lcf->types == NULL) {
|
|
2426 lcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t));
|
|
2427 if (lcf->types == NULL) {
|
|
2428 return NGX_CONF_ERROR;
|
|
2429 }
|
|
2430 }
|
|
2431
|
34
|
2432 save = *cf;
|
|
2433 cf->handler = ngx_http_core_type;
|
0
|
2434 cf->handler_conf = conf;
|
34
|
2435
|
0
|
2436 rv = ngx_conf_parse(cf, NULL);
|
34
|
2437
|
|
2438 *cf = save;
|
0
|
2439
|
|
2440 return rv;
|
|
2441 }
|
|
2442
|
|
2443
|
36
|
2444 static char *
|
|
2445 ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
|
0
|
2446 {
|
|
2447 ngx_http_core_loc_conf_t *lcf = conf;
|
|
2448
|
294
|
2449 ngx_str_t *value, *content_type, *old, file;
|
138
|
2450 ngx_uint_t i, n;
|
|
2451 ngx_hash_key_t *type;
|
0
|
2452
|
294
|
2453 value = cf->args->elts;
|
|
2454
|
|
2455 if (ngx_strcmp(value[0].data, "include") == 0) {
|
|
2456 file = value[1];
|
|
2457
|
324
|
2458 if (ngx_conf_full_name(cf->cycle, &file, 1) == NGX_ERROR){
|
294
|
2459 return NGX_CONF_ERROR;
|
|
2460 }
|
|
2461
|
|
2462 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
|
|
2463
|
|
2464 return ngx_conf_parse(cf, &file);
|
|
2465 }
|
|
2466
|
138
|
2467 content_type = ngx_palloc(cf->pool, sizeof(ngx_str_t));
|
|
2468 if (content_type == NULL) {
|
|
2469 return NGX_CONF_ERROR;
|
0
|
2470 }
|
|
2471
|
138
|
2472 *content_type = value[0];
|
0
|
2473
|
|
2474 for (i = 1; i < cf->args->nelts; i++) {
|
138
|
2475
|
|
2476 for (n = 0; n < value[i].len; n++) {
|
|
2477 value[i].data[n] = ngx_tolower(value[i].data[n]);
|
|
2478 }
|
|
2479
|
|
2480 type = lcf->types->elts;
|
|
2481 for (n = 0; n < lcf->types->nelts; n++) {
|
|
2482 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) {
|
|
2483 old = type[n].value;
|
|
2484 type[n].value = content_type;
|
|
2485
|
|
2486 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
2487 "duplicate extention \"%V\", "
|
|
2488 "content type: \"%V\", "
|
|
2489 "old content type: \"%V\"",
|
|
2490 &value[i], content_type, old);
|
|
2491 continue;
|
|
2492 }
|
|
2493 }
|
|
2494
|
|
2495
|
|
2496 type = ngx_array_push(lcf->types);
|
50
|
2497 if (type == NULL) {
|
0
|
2498 return NGX_CONF_ERROR;
|
|
2499 }
|
|
2500
|
138
|
2501 type->key = value[i];
|
|
2502 type->key_hash = ngx_hash_key(value[i].data, value[i].len);
|
|
2503 type->value = content_type;
|
0
|
2504 }
|
|
2505
|
|
2506 return NGX_CONF_OK;
|
|
2507 }
|
|
2508
|
|
2509
|
58
|
2510 static ngx_int_t
|
|
2511 ngx_http_core_preconfiguration(ngx_conf_t *cf)
|
|
2512 {
|
|
2513 return ngx_http_variables_add_core_vars(cf);
|
|
2514 }
|
|
2515
|
|
2516
|
36
|
2517 static void *
|
|
2518 ngx_http_core_create_main_conf(ngx_conf_t *cf)
|
0
|
2519 {
|
34
|
2520 ngx_http_core_main_conf_t *cmcf;
|
|
2521
|
50
|
2522 cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t));
|
|
2523 if (cmcf == NULL) {
|
34
|
2524 return NGX_CONF_ERROR;
|
|
2525 }
|
0
|
2526
|
48
|
2527 if (ngx_array_init(&cmcf->servers, cf->pool, 4,
|
118
|
2528 sizeof(ngx_http_core_srv_conf_t *))
|
200
|
2529 != NGX_OK)
|
34
|
2530 {
|
|
2531 return NGX_CONF_ERROR;
|
|
2532 }
|
0
|
2533
|
142
|
2534 cmcf->server_names_hash_max_size = NGX_CONF_UNSET_UINT;
|
|
2535 cmcf->server_names_hash_bucket_size = NGX_CONF_UNSET_UINT;
|
26
|
2536
|
160
|
2537 cmcf->variables_hash_max_size = NGX_CONF_UNSET_UINT;
|
|
2538 cmcf->variables_hash_bucket_size = NGX_CONF_UNSET_UINT;
|
|
2539
|
0
|
2540 return cmcf;
|
|
2541 }
|
|
2542
|
|
2543
|
36
|
2544 static char *
|
|
2545 ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf)
|
0
|
2546 {
|
|
2547 ngx_http_core_main_conf_t *cmcf = conf;
|
|
2548
|
142
|
2549 if (cmcf->server_names_hash_max_size == NGX_CONF_UNSET_UINT) {
|
|
2550 cmcf->server_names_hash_max_size = 512;
|
26
|
2551 }
|
|
2552
|
142
|
2553 if (cmcf->server_names_hash_bucket_size == NGX_CONF_UNSET_UINT) {
|
|
2554 cmcf->server_names_hash_bucket_size = ngx_cacheline_size;
|
26
|
2555 }
|
0
|
2556
|
142
|
2557 cmcf->server_names_hash_bucket_size =
|
|
2558 ngx_align(cmcf->server_names_hash_bucket_size, ngx_cacheline_size);
|
|
2559
|
160
|
2560
|
|
2561 if (cmcf->variables_hash_max_size == NGX_CONF_UNSET_UINT) {
|
|
2562 cmcf->variables_hash_max_size = 512;
|
|
2563 }
|
|
2564
|
|
2565 if (cmcf->variables_hash_bucket_size == NGX_CONF_UNSET_UINT) {
|
|
2566 cmcf->variables_hash_bucket_size = 64;
|
|
2567 }
|
|
2568
|
|
2569 cmcf->variables_hash_bucket_size =
|
|
2570 ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size);
|
|
2571
|
0
|
2572 return NGX_CONF_OK;
|
|
2573 }
|
|
2574
|
|
2575
|
36
|
2576 static void *
|
|
2577 ngx_http_core_create_srv_conf(ngx_conf_t *cf)
|
0
|
2578 {
|
|
2579 ngx_http_core_srv_conf_t *cscf;
|
|
2580
|
50
|
2581 cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t));
|
|
2582 if (cscf == NULL) {
|
36
|
2583 return NGX_CONF_ERROR;
|
|
2584 }
|
|
2585
|
0
|
2586 /*
|
36
|
2587 * set by ngx_pcalloc():
|
28
|
2588 *
|
|
2589 * conf->client_large_buffers.num = 0;
|
|
2590 */
|
0
|
2591
|
48
|
2592 if (ngx_array_init(&cscf->locations, cf->pool, 4, sizeof(void *))
|
142
|
2593 == NGX_ERROR)
|
36
|
2594 {
|
|
2595 return NGX_CONF_ERROR;
|
|
2596 }
|
|
2597
|
48
|
2598 if (ngx_array_init(&cscf->listen, cf->pool, 4, sizeof(ngx_http_listen_t))
|
142
|
2599 == NGX_ERROR)
|
36
|
2600 {
|
|
2601 return NGX_CONF_ERROR;
|
|
2602 }
|
|
2603
|
230
|
2604 if (ngx_array_init(&cscf->server_names, cf->temp_pool, 4,
|
142
|
2605 sizeof(ngx_http_server_name_t))
|
|
2606 == NGX_ERROR)
|
36
|
2607 {
|
|
2608 return NGX_CONF_ERROR;
|
|
2609 }
|
0
|
2610
|
|
2611 cscf->connection_pool_size = NGX_CONF_UNSET_SIZE;
|
|
2612 cscf->request_pool_size = NGX_CONF_UNSET_SIZE;
|
|
2613 cscf->client_header_timeout = NGX_CONF_UNSET_MSEC;
|
|
2614 cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE;
|
158
|
2615 cscf->optimize_server_names = NGX_CONF_UNSET;
|
60
|
2616 cscf->ignore_invalid_headers = NGX_CONF_UNSET;
|
342
|
2617 cscf->merge_slashes = NGX_CONF_UNSET;
|
0
|
2618
|
|
2619 return cscf;
|
|
2620 }
|
|
2621
|
|
2622
|
36
|
2623 static char *
|
|
2624 ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
0
|
2625 {
|
|
2626 ngx_http_core_srv_conf_t *prev = parent;
|
|
2627 ngx_http_core_srv_conf_t *conf = child;
|
|
2628
|
142
|
2629 ngx_http_listen_t *ls;
|
|
2630 ngx_http_server_name_t *sn;
|
0
|
2631
|
|
2632 /* TODO: it does not merge, it inits only */
|
|
2633
|
|
2634 if (conf->listen.nelts == 0) {
|
50
|
2635 ls = ngx_array_push(&conf->listen);
|
|
2636 if (ls == NULL) {
|
36
|
2637 return NGX_CONF_ERROR;
|
|
2638 }
|
|
2639
|
72
|
2640 ngx_memzero(ls, sizeof(ngx_http_listen_t));
|
|
2641
|
36
|
2642 ls->addr = INADDR_ANY;
|
10
|
2643 #if (NGX_WIN32)
|
36
|
2644 ls->port = 80;
|
0
|
2645 #else
|
|
2646 /* STUB: getuid() should be cached */
|
36
|
2647 ls->port = (getuid() == 0) ? 80 : 8000;
|
0
|
2648 #endif
|
36
|
2649 ls->family = AF_INET;
|
118
|
2650
|
326
|
2651 ls->conf.backlog = NGX_LISTEN_BACKLOG;
|
118
|
2652 ls->conf.rcvbuf = -1;
|
|
2653 ls->conf.sndbuf = -1;
|
0
|
2654 }
|
|
2655
|
154
|
2656 if (conf->server_name.data == NULL) {
|
376
|
2657 conf->server_name = cf->cycle->hostname;
|
154
|
2658
|
50
|
2659 sn = ngx_array_push(&conf->server_names);
|
|
2660 if (sn == NULL) {
|
36
|
2661 return NGX_CONF_ERROR;
|
|
2662 }
|
|
2663
|
342
|
2664 #if (NGX_PCRE)
|
|
2665 sn->regex = NULL;
|
|
2666 #endif
|
|
2667 sn->core_srv_conf = conf;
|
154
|
2668 sn->name.len = conf->server_name.len;
|
|
2669 sn->name.data = conf->server_name.data;
|
0
|
2670 }
|
|
2671
|
|
2672 ngx_conf_merge_size_value(conf->connection_pool_size,
|
|
2673 prev->connection_pool_size, 256);
|
|
2674 ngx_conf_merge_size_value(conf->request_pool_size,
|
|
2675 prev->request_pool_size, 4096);
|
|
2676 ngx_conf_merge_msec_value(conf->client_header_timeout,
|
|
2677 prev->client_header_timeout, 60000);
|
|
2678 ngx_conf_merge_size_value(conf->client_header_buffer_size,
|
|
2679 prev->client_header_buffer_size, 1024);
|
|
2680 ngx_conf_merge_bufs_value(conf->large_client_header_buffers,
|
|
2681 prev->large_client_header_buffers,
|
|
2682 4, ngx_pagesize);
|
|
2683
|
|
2684 if (conf->large_client_header_buffers.size < conf->connection_pool_size) {
|
|
2685 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2686 "the \"large_client_header_buffers\" size must be "
|
|
2687 "equal to or bigger than \"connection_pool_size\"");
|
|
2688 return NGX_CONF_ERROR;
|
|
2689 }
|
|
2690
|
158
|
2691 ngx_conf_merge_value(conf->optimize_server_names,
|
|
2692 prev->optimize_server_names, 1);
|
152
|
2693
|
60
|
2694 ngx_conf_merge_value(conf->ignore_invalid_headers,
|
|
2695 prev->ignore_invalid_headers, 1);
|
|
2696
|
342
|
2697 ngx_conf_merge_value(conf->merge_slashes, prev->merge_slashes, 1);
|
|
2698
|
0
|
2699 return NGX_CONF_OK;
|
|
2700 }
|
|
2701
|
|
2702
|
36
|
2703 static void *
|
|
2704 ngx_http_core_create_loc_conf(ngx_conf_t *cf)
|
0
|
2705 {
|
34
|
2706 ngx_http_core_loc_conf_t *lcf;
|
0
|
2707
|
50
|
2708 lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t));
|
|
2709 if (lcf == NULL) {
|
36
|
2710 return NGX_CONF_ERROR;
|
|
2711 }
|
0
|
2712
|
28
|
2713 /*
|
|
2714 * set by ngx_pcalloc():
|
|
2715 *
|
126
|
2716 * lcf->root = { 0, NULL };
|
180
|
2717 * lcf->limit_except = 0;
|
126
|
2718 * lcf->post_action = { 0, NULL };
|
28
|
2719 * lcf->types = NULL;
|
126
|
2720 * lcf->default_type = { 0, NULL };
|
28
|
2721 * lcf->err_log = NULL;
|
|
2722 * lcf->error_pages = NULL;
|
|
2723 * lcf->client_body_path = NULL;
|
|
2724 * lcf->regex = NULL;
|
|
2725 * lcf->exact_match = 0;
|
|
2726 * lcf->auto_redirect = 0;
|
|
2727 * lcf->alias = 0;
|
358
|
2728 * lcf->gzip_proxied = 0;
|
28
|
2729 */
|
0
|
2730
|
212
|
2731 lcf->client_max_body_size = NGX_CONF_UNSET;
|
0
|
2732 lcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE;
|
|
2733 lcf->client_body_timeout = NGX_CONF_UNSET_MSEC;
|
362
|
2734 lcf->satisfy = NGX_CONF_UNSET_UINT;
|
58
|
2735 lcf->internal = NGX_CONF_UNSET;
|
182
|
2736 lcf->client_body_in_file_only = NGX_CONF_UNSET;
|
0
|
2737 lcf->sendfile = NGX_CONF_UNSET;
|
300
|
2738 lcf->sendfile_max_chunk = NGX_CONF_UNSET_SIZE;
|
0
|
2739 lcf->tcp_nopush = NGX_CONF_UNSET;
|
2
|
2740 lcf->tcp_nodelay = NGX_CONF_UNSET;
|
0
|
2741 lcf->send_timeout = NGX_CONF_UNSET_MSEC;
|
|
2742 lcf->send_lowat = NGX_CONF_UNSET_SIZE;
|
|
2743 lcf->postpone_output = NGX_CONF_UNSET_SIZE;
|
|
2744 lcf->limit_rate = NGX_CONF_UNSET_SIZE;
|
|
2745 lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
|
|
2746 lcf->keepalive_header = NGX_CONF_UNSET;
|
|
2747 lcf->lingering_time = NGX_CONF_UNSET_MSEC;
|
|
2748 lcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
|
348
|
2749 lcf->resolver_timeout = NGX_CONF_UNSET_MSEC;
|
0
|
2750 lcf->reset_timedout_connection = NGX_CONF_UNSET;
|
362
|
2751 lcf->server_name_in_redirect = NGX_CONF_UNSET;
|
70
|
2752 lcf->port_in_redirect = NGX_CONF_UNSET;
|
0
|
2753 lcf->msie_padding = NGX_CONF_UNSET;
|
228
|
2754 lcf->msie_refresh = NGX_CONF_UNSET;
|
76
|
2755 lcf->log_not_found = NGX_CONF_UNSET;
|
228
|
2756 lcf->recursive_error_pages = NGX_CONF_UNSET;
|
342
|
2757 lcf->server_tokens = NGX_CONF_UNSET;
|
138
|
2758 lcf->types_hash_max_size = NGX_CONF_UNSET_UINT;
|
|
2759 lcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT;
|
358
|
2760
|
332
|
2761 lcf->open_file_cache = NGX_CONF_UNSET_PTR;
|
358
|
2762 lcf->open_file_cache_valid = NGX_CONF_UNSET;
|
|
2763 lcf->open_file_cache_min_uses = NGX_CONF_UNSET_UINT;
|
332
|
2764 lcf->open_file_cache_errors = NGX_CONF_UNSET;
|
|
2765 lcf->open_file_cache_events = NGX_CONF_UNSET;
|
0
|
2766
|
358
|
2767 #if (NGX_HTTP_GZIP)
|
|
2768 lcf->gzip_vary = NGX_CONF_UNSET;
|
|
2769 lcf->gzip_http_version = NGX_CONF_UNSET_UINT;
|
362
|
2770 #if (NGX_PCRE)
|
358
|
2771 lcf->gzip_disable = NGX_CONF_UNSET_PTR;
|
|
2772 #endif
|
362
|
2773 #endif
|
358
|
2774
|
0
|
2775 return lcf;
|
|
2776 }
|
|
2777
|
|
2778
|
138
|
2779 static ngx_str_t ngx_http_core_text_html_type = ngx_string("text/html");
|
|
2780 static ngx_str_t ngx_http_core_image_gif_type = ngx_string("image/gif");
|
|
2781 static ngx_str_t ngx_http_core_image_jpeg_type = ngx_string("image/jpeg");
|
|
2782
|
|
2783 static ngx_hash_key_t ngx_http_core_default_types[] = {
|
|
2784 { ngx_string("html"), 0, &ngx_http_core_text_html_type },
|
|
2785 { ngx_string("gif"), 0, &ngx_http_core_image_gif_type },
|
|
2786 { ngx_string("jpg"), 0, &ngx_http_core_image_jpeg_type },
|
|
2787 { ngx_null_string, 0, NULL }
|
0
|
2788 };
|
|
2789
|
|
2790
|
36
|
2791 static char *
|
138
|
2792 ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
0
|
2793 {
|
|
2794 ngx_http_core_loc_conf_t *prev = parent;
|
|
2795 ngx_http_core_loc_conf_t *conf = child;
|
|
2796
|
36
|
2797 ngx_uint_t i;
|
138
|
2798 ngx_hash_key_t *type;
|
|
2799 ngx_hash_init_t types_hash;
|
0
|
2800
|
152
|
2801 if (conf->root.data == NULL) {
|
|
2802
|
174
|
2803 conf->alias = prev->alias;
|
152
|
2804 conf->root = prev->root;
|
|
2805 conf->root_lengths = prev->root_lengths;
|
|
2806 conf->root_values = prev->root_values;
|
|
2807
|
|
2808 if (prev->root.data == NULL) {
|
|
2809 conf->root.len = sizeof("html") - 1;
|
|
2810 conf->root.data = (u_char *) "html";
|
|
2811
|
324
|
2812 if (ngx_conf_full_name(cf->cycle, &conf->root, 0) == NGX_ERROR) {
|
152
|
2813 return NGX_CONF_ERROR;
|
|
2814 }
|
|
2815 }
|
0
|
2816 }
|
|
2817
|
126
|
2818 if (conf->post_action.data == NULL) {
|
|
2819 conf->post_action = prev->post_action;
|
|
2820 }
|
|
2821
|
212
|
2822 ngx_conf_merge_uint_value(conf->types_hash_max_size,
|
|
2823 prev->types_hash_max_size, 1024);
|
|
2824
|
|
2825 ngx_conf_merge_uint_value(conf->types_hash_bucket_size,
|
|
2826 prev->types_hash_bucket_size,
|
|
2827 ngx_cacheline_size);
|
138
|
2828
|
|
2829 conf->types_hash_bucket_size = ngx_align(conf->types_hash_bucket_size,
|
|
2830 ngx_cacheline_size);
|
|
2831
|
|
2832 /*
|
|
2833 * the special handling the "types" directive in the "http" section
|
|
2834 * to inherit the http's conf->types_hash to all servers
|
|
2835 */
|
|
2836
|
|
2837 if (prev->types && prev->types_hash.buckets == NULL) {
|
|
2838
|
|
2839 types_hash.hash = &prev->types_hash;
|
|
2840 types_hash.key = ngx_hash_key_lc;
|
|
2841 types_hash.max_size = conf->types_hash_max_size;
|
|
2842 types_hash.bucket_size = conf->types_hash_bucket_size;
|
144
|
2843 types_hash.name = "types_hash";
|
138
|
2844 types_hash.pool = cf->pool;
|
|
2845 types_hash.temp_pool = NULL;
|
|
2846
|
|
2847 if (ngx_hash_init(&types_hash, prev->types->elts, prev->types->nelts)
|
|
2848 != NGX_OK)
|
|
2849 {
|
|
2850 return NGX_CONF_ERROR;
|
|
2851 }
|
|
2852 }
|
|
2853
|
0
|
2854 if (conf->types == NULL) {
|
138
|
2855 conf->types = prev->types;
|
|
2856 conf->types_hash = prev->types_hash;
|
|
2857 }
|
|
2858
|
|
2859 if (conf->types == NULL) {
|
|
2860 conf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_hash_key_t));
|
|
2861 if (conf->types == NULL) {
|
|
2862 return NGX_CONF_ERROR;
|
|
2863 }
|
|
2864
|
|
2865 for (i = 0; ngx_http_core_default_types[i].key.len; i++) {
|
|
2866 type = ngx_array_push(conf->types);
|
|
2867 if (type == NULL) {
|
36
|
2868 return NGX_CONF_ERROR;
|
|
2869 }
|
0
|
2870
|
138
|
2871 type->key = ngx_http_core_default_types[i].key;
|
|
2872 type->key_hash =
|
|
2873 ngx_hash_key_lc(ngx_http_core_default_types[i].key.data,
|
|
2874 ngx_http_core_default_types[i].key.len);
|
|
2875 type->value = ngx_http_core_default_types[i].value;
|
|
2876 }
|
|
2877 }
|
|
2878
|
|
2879 if (conf->types_hash.buckets == NULL) {
|
|
2880
|
|
2881 types_hash.hash = &conf->types_hash;
|
|
2882 types_hash.key = ngx_hash_key_lc;
|
|
2883 types_hash.max_size = conf->types_hash_max_size;
|
|
2884 types_hash.bucket_size = conf->types_hash_bucket_size;
|
144
|
2885 types_hash.name = "mime_types_hash";
|
138
|
2886 types_hash.pool = cf->pool;
|
|
2887 types_hash.temp_pool = NULL;
|
|
2888
|
|
2889 if (ngx_hash_init(&types_hash, conf->types->elts, conf->types->nelts)
|
|
2890 != NGX_OK)
|
|
2891 {
|
|
2892 return NGX_CONF_ERROR;
|
0
|
2893 }
|
|
2894 }
|
|
2895
|
|
2896 if (conf->err_log == NULL) {
|
|
2897 if (prev->err_log) {
|
|
2898 conf->err_log = prev->err_log;
|
|
2899 } else {
|
|
2900 conf->err_log = cf->cycle->new_log;
|
|
2901 }
|
|
2902 }
|
|
2903
|
|
2904 if (conf->error_pages == NULL && prev->error_pages) {
|
|
2905 conf->error_pages = prev->error_pages;
|
|
2906 }
|
|
2907
|
|
2908 ngx_conf_merge_str_value(conf->default_type,
|
36
|
2909 prev->default_type, "text/plain");
|
0
|
2910
|
212
|
2911 ngx_conf_merge_off_value(conf->client_max_body_size,
|
0
|
2912 prev->client_max_body_size, 1 * 1024 * 1024);
|
|
2913 ngx_conf_merge_size_value(conf->client_body_buffer_size,
|
|
2914 prev->client_body_buffer_size,
|
|
2915 (size_t) 2 * ngx_pagesize);
|
|
2916 ngx_conf_merge_msec_value(conf->client_body_timeout,
|
|
2917 prev->client_body_timeout, 60000);
|
58
|
2918
|
362
|
2919 ngx_conf_merge_uint_value(conf->satisfy, prev->satisfy,
|
|
2920 NGX_HTTP_SATISFY_ALL);
|
58
|
2921 ngx_conf_merge_value(conf->internal, prev->internal, 0);
|
182
|
2922 ngx_conf_merge_value(conf->client_body_in_file_only,
|
|
2923 prev->client_body_in_file_only, 0);
|
0
|
2924 ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
|
300
|
2925 ngx_conf_merge_size_value(conf->sendfile_max_chunk,
|
|
2926 prev->sendfile_max_chunk, 0);
|
0
|
2927 ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0);
|
228
|
2928 ngx_conf_merge_value(conf->tcp_nodelay, prev->tcp_nodelay, 1);
|
58
|
2929
|
0
|
2930 ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000);
|
|
2931 ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0);
|
|
2932 ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output,
|
|
2933 1460);
|
|
2934 ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0);
|
|
2935 ngx_conf_merge_msec_value(conf->keepalive_timeout,
|
|
2936 prev->keepalive_timeout, 75000);
|
|
2937 ngx_conf_merge_sec_value(conf->keepalive_header,
|
|
2938 prev->keepalive_header, 0);
|
|
2939 ngx_conf_merge_msec_value(conf->lingering_time,
|
|
2940 prev->lingering_time, 30000);
|
|
2941 ngx_conf_merge_msec_value(conf->lingering_timeout,
|
|
2942 prev->lingering_timeout, 5000);
|
348
|
2943 ngx_conf_merge_msec_value(conf->resolver_timeout,
|
|
2944 prev->resolver_timeout, 30000);
|
|
2945
|
|
2946 if (conf->resolver == NULL) {
|
366
|
2947
|
|
2948 if (prev->resolver == NULL) {
|
|
2949
|
|
2950 /*
|
|
2951 * create dummy resolver in http {} context
|
|
2952 * to inherit it in all servers
|
|
2953 */
|
|
2954
|
|
2955 prev->resolver = ngx_resolver_create(cf, NULL);
|
|
2956 if (prev->resolver == NULL) {
|
364
|
2957 return NGX_CONF_ERROR;
|
354
|
2958 }
|
|
2959 }
|
376
|
2960
|
366
|
2961 conf->resolver = prev->resolver;
|
348
|
2962 }
|
0
|
2963
|
28
|
2964 ngx_conf_merge_path_value(conf->client_body_temp_path,
|
|
2965 prev->client_body_temp_path,
|
|
2966 NGX_HTTP_CLIENT_TEMP_PATH, 0, 0, 0,
|
|
2967 ngx_garbage_collector_temp_handler, cf);
|
|
2968
|
0
|
2969 ngx_conf_merge_value(conf->reset_timedout_connection,
|
36
|
2970 prev->reset_timedout_connection, 0);
|
362
|
2971 ngx_conf_merge_value(conf->server_name_in_redirect,
|
|
2972 prev->server_name_in_redirect, 1);
|
70
|
2973 ngx_conf_merge_value(conf->port_in_redirect, prev->port_in_redirect, 1);
|
0
|
2974 ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1);
|
228
|
2975 ngx_conf_merge_value(conf->msie_refresh, prev->msie_refresh, 0);
|
76
|
2976 ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1);
|
228
|
2977 ngx_conf_merge_value(conf->recursive_error_pages,
|
|
2978 prev->recursive_error_pages, 0);
|
342
|
2979 ngx_conf_merge_value(conf->server_tokens, prev->server_tokens, 1);
|
0
|
2980
|
332
|
2981 ngx_conf_merge_ptr_value(conf->open_file_cache,
|
358
|
2982 prev->open_file_cache, NULL);
|
|
2983
|
|
2984 ngx_conf_merge_sec_value(conf->open_file_cache_valid,
|
|
2985 prev->open_file_cache_valid, 60);
|
|
2986
|
|
2987 ngx_conf_merge_uint_value(conf->open_file_cache_min_uses,
|
|
2988 prev->open_file_cache_min_uses, 1);
|
332
|
2989
|
|
2990 ngx_conf_merge_sec_value(conf->open_file_cache_errors,
|
358
|
2991 prev->open_file_cache_errors, 0);
|
332
|
2992
|
|
2993 ngx_conf_merge_sec_value(conf->open_file_cache_events,
|
358
|
2994 prev->open_file_cache_events, 0);
|
|
2995 #if (NGX_HTTP_GZIP)
|
|
2996
|
|
2997 ngx_conf_merge_value(conf->gzip_vary, prev->gzip_vary, 0);
|
|
2998 ngx_conf_merge_uint_value(conf->gzip_http_version, prev->gzip_http_version,
|
|
2999 NGX_HTTP_VERSION_11);
|
|
3000 ngx_conf_merge_bitmask_value(conf->gzip_proxied, prev->gzip_proxied,
|
|
3001 (NGX_CONF_BITMASK_SET|NGX_HTTP_GZIP_PROXIED_OFF));
|
|
3002
|
362
|
3003 #if (NGX_PCRE)
|
358
|
3004 ngx_conf_merge_ptr_value(conf->gzip_disable, prev->gzip_disable, NULL);
|
362
|
3005 #endif
|
358
|
3006
|
|
3007 #endif
|
0
|
3008
|
|
3009 return NGX_CONF_OK;
|
|
3010 }
|
|
3011
|
|
3012
|
72
|
3013 /* AF_INET only */
|
|
3014
|
36
|
3015 static char *
|
|
3016 ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
3017 {
|
|
3018 ngx_http_core_srv_conf_t *scf = conf;
|
|
3019
|
252
|
3020 ngx_str_t *value, size;
|
|
3021 ngx_url_t u;
|
|
3022 ngx_uint_t n;
|
|
3023 ngx_http_listen_t *ls;
|
0
|
3024
|
|
3025 /*
|
|
3026 * TODO: check duplicate 'listen' directives,
|
|
3027 * add resolved name to server names ???
|
|
3028 */
|
|
3029
|
72
|
3030 value = cf->args->elts;
|
126
|
3031
|
252
|
3032 ngx_memzero(&u, sizeof(ngx_url_t));
|
|
3033
|
|
3034 u.url = value[1];
|
|
3035 u.listen = 1;
|
266
|
3036 u.default_port = 80;
|
252
|
3037
|
340
|
3038 if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
|
252
|
3039 if (u.err) {
|
|
3040 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3041 "%s in \"%V\" of the \"listen\" directive",
|
|
3042 u.err, &u.url);
|
|
3043 }
|
|
3044
|
126
|
3045 return NGX_CONF_ERROR;
|
72
|
3046 }
|
|
3047
|
50
|
3048 ls = ngx_array_push(&scf->listen);
|
|
3049 if (ls == NULL) {
|
0
|
3050 return NGX_CONF_ERROR;
|
|
3051 }
|
|
3052
|
72
|
3053 ngx_memzero(ls, sizeof(ngx_http_listen_t));
|
0
|
3054
|
|
3055 ls->family = AF_INET;
|
252
|
3056 ls->addr = u.addr.in_addr;
|
266
|
3057 ls->port = u.port;
|
336
|
3058 ls->file_name = cf->conf_file->file.name.data;
|
0
|
3059 ls->line = cf->conf_file->line;
|
326
|
3060 ls->conf.backlog = NGX_LISTEN_BACKLOG;
|
112
|
3061 ls->conf.rcvbuf = -1;
|
|
3062 ls->conf.sndbuf = -1;
|
72
|
3063
|
180
|
3064 n = ngx_inet_ntop(AF_INET, &ls->addr, ls->conf.addr, INET_ADDRSTRLEN + 6);
|
|
3065 ngx_sprintf(&ls->conf.addr[n], ":%ui", ls->port);
|
|
3066
|
72
|
3067 if (cf->args->nelts == 2) {
|
|
3068 return NGX_CONF_OK;
|
|
3069 }
|
|
3070
|
|
3071 if (ngx_strcmp(value[2].data, "default") == 0) {
|
|
3072 ls->conf.default_server = 1;
|
|
3073 n = 3;
|
138
|
3074
|
72
|
3075 } else {
|
|
3076 n = 2;
|
0
|
3077 }
|
|
3078
|
72
|
3079 for ( /* void */ ; n < cf->args->nelts; n++) {
|
|
3080
|
|
3081 if (ls->conf.default_server == 0) {
|
|
3082 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3083 "\"%V\" parameter can be specified for "
|
|
3084 "the default \"listen\" directive only",
|
|
3085 &value[n]);
|
|
3086 return NGX_CONF_ERROR;
|
|
3087 }
|
|
3088
|
|
3089 if (ngx_strcmp(value[n].data, "bind") == 0) {
|
|
3090 ls->conf.bind = 1;
|
|
3091 continue;
|
|
3092 }
|
|
3093
|
112
|
3094 if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) {
|
|
3095 ls->conf.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8);
|
72
|
3096 ls->conf.bind = 1;
|
|
3097
|
|
3098 if (ls->conf.backlog == NGX_ERROR || ls->conf.backlog == 0) {
|
|
3099 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3100 "invalid backlog \"%V\"", &value[n]);
|
|
3101 return NGX_CONF_ERROR;
|
|
3102 }
|
|
3103
|
|
3104 continue;
|
|
3105 }
|
|
3106
|
112
|
3107 if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) {
|
|
3108 size.len = value[n].len - 7;
|
|
3109 size.data = value[n].data + 7;
|
|
3110
|
|
3111 ls->conf.rcvbuf = ngx_parse_size(&size);
|
|
3112 ls->conf.bind = 1;
|
|
3113
|
|
3114 if (ls->conf.rcvbuf == NGX_ERROR) {
|
|
3115 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3116 "invalid rcvbuf \"%V\"", &value[n]);
|
|
3117 return NGX_CONF_ERROR;
|
|
3118 }
|
|
3119
|
|
3120 continue;
|
|
3121 }
|
|
3122
|
|
3123 if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) {
|
|
3124 size.len = value[n].len - 7;
|
|
3125 size.data = value[n].data + 7;
|
|
3126
|
|
3127 ls->conf.sndbuf = ngx_parse_size(&size);
|
|
3128 ls->conf.bind = 1;
|
|
3129
|
|
3130 if (ls->conf.sndbuf == NGX_ERROR) {
|
|
3131 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3132 "invalid sndbuf \"%V\"", &value[n]);
|
|
3133 return NGX_CONF_ERROR;
|
|
3134 }
|
|
3135
|
|
3136 continue;
|
|
3137 }
|
|
3138
|
|
3139 if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) {
|
72
|
3140 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
|
112
|
3141 ls->conf.accept_filter = (char *) &value[n].data[14];
|
72
|
3142 ls->conf.bind = 1;
|
|
3143 #else
|
|
3144 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3145 "accept filters \"%V\" are not supported "
|
|
3146 "on this platform, ignored",
|
|
3147 &value[n]);
|
|
3148 #endif
|
|
3149 continue;
|
|
3150 }
|
|
3151
|
|
3152 if (ngx_strcmp(value[n].data, "deferred") == 0) {
|
|
3153 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
|
|
3154 ls->conf.deferred_accept = 1;
|
|
3155 ls->conf.bind = 1;
|
|
3156 #else
|
|
3157 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3158 "the deferred accept is not supported "
|
|
3159 "on this platform, ignored");
|
|
3160 #endif
|
|
3161 continue;
|
|
3162 }
|
0
|
3163
|
|
3164 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
72
|
3165 "the invalid \"%V\" parameter", &value[n]);
|
0
|
3166 return NGX_CONF_ERROR;
|
|
3167 }
|
|
3168
|
|
3169 return NGX_CONF_OK;
|
|
3170 }
|
|
3171
|
|
3172
|
36
|
3173 static char *
|
|
3174 ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
3175 {
|
142
|
3176 ngx_http_core_srv_conf_t *cscf = conf;
|
|
3177
|
|
3178 u_char ch;
|
|
3179 ngx_str_t *value, name;
|
|
3180 ngx_uint_t i;
|
|
3181 ngx_http_server_name_t *sn;
|
0
|
3182
|
|
3183 value = cf->args->elts;
|
|
3184
|
142
|
3185 ch = value[1].data[0];
|
|
3186
|
|
3187 if (cscf->server_name.data == NULL && value[1].len) {
|
|
3188 name = value[1];
|
|
3189
|
|
3190 if (ch == '.') {
|
|
3191 name.len--;
|
|
3192 name.data++;
|
|
3193 }
|
|
3194
|
|
3195 cscf->server_name.len = name.len;
|
|
3196 cscf->server_name.data = ngx_pstrdup(cf->pool, &name);
|
|
3197 if (cscf->server_name.data == NULL) {
|
|
3198 return NGX_CONF_ERROR;
|
|
3199 }
|
|
3200 }
|
|
3201
|
|
3202 for (i = 1; i < cf->args->nelts; i++) {
|
|
3203
|
|
3204 ch = value[i].data[0];
|
|
3205
|
|
3206 if (value[i].len == 0
|
|
3207 || (ch == '*' && (value[i].len < 3 || value[i].data[1] != '.'))
|
|
3208 || (ch == '.' && value[i].len < 2))
|
|
3209 {
|
|
3210 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3211 "server name \"%V\" is invalid", &value[i]);
|
|
3212 return NGX_CONF_ERROR;
|
|
3213 }
|
|
3214
|
294
|
3215 if (ngx_strchr(value[i].data, '/')) {
|
|
3216 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
3217 "server name \"%V\" has strange symbols",
|
|
3218 &value[i]);
|
|
3219 }
|
|
3220
|
362
|
3221 if (value[i].len == 1 && ch == '*') {
|
|
3222 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3223 "\"server_name *\" is unsupported, use "
|
|
3224 "\"server_name_in_redirect off\" instead");
|
|
3225 return NGX_CONF_ERROR;
|
|
3226 }
|
|
3227
|
142
|
3228 sn = ngx_array_push(&cscf->server_names);
|
50
|
3229 if (sn == NULL) {
|
4
|
3230 return NGX_CONF_ERROR;
|
|
3231 }
|
0
|
3232
|
326
|
3233 #if (NGX_PCRE)
|
|
3234 sn->regex = NULL;
|
|
3235 #endif
|
|
3236 sn->core_srv_conf = cscf;
|
358
|
3237 sn->name = value[i];
|
326
|
3238
|
|
3239 if (value[i].data[0] != '~') {
|
|
3240 continue;
|
|
3241 }
|
|
3242
|
|
3243 #if (NGX_PCRE)
|
356
|
3244 {
|
|
3245 ngx_str_t err;
|
|
3246 u_char errstr[NGX_MAX_CONF_ERRSTR];
|
|
3247
|
326
|
3248 err.len = NGX_MAX_CONF_ERRSTR;
|
|
3249 err.data = errstr;
|
|
3250
|
|
3251 value[i].len--;
|
|
3252 value[i].data++;
|
|
3253
|
376
|
3254 sn->regex = ngx_regex_compile(&value[i], 0, cf->pool, &err);
|
326
|
3255
|
|
3256 if (sn->regex == NULL) {
|
|
3257 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
|
|
3258 return NGX_CONF_ERROR;
|
|
3259 }
|
|
3260
|
358
|
3261 sn->name = value[i];
|
356
|
3262 }
|
326
|
3263 #else
|
|
3264 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3265 "the using of the regex \"%V\" "
|
|
3266 "requires PCRE library", &value[i]);
|
|
3267
|
|
3268 return NGX_CONF_ERROR;
|
|
3269 #endif
|
0
|
3270 }
|
|
3271
|
|
3272 return NGX_CONF_OK;
|
|
3273 }
|
|
3274
|
|
3275
|
36
|
3276 static char *
|
|
3277 ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
3278 {
|
|
3279 ngx_http_core_loc_conf_t *lcf = conf;
|
|
3280
|
144
|
3281 ngx_str_t *value;
|
|
3282 ngx_uint_t alias, n;
|
|
3283 ngx_http_script_compile_t sc;
|
0
|
3284
|
|
3285 alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0;
|
|
3286
|
|
3287 if (lcf->root.data) {
|
|
3288
|
|
3289 /* the (ngx_uint_t) cast is required by gcc 2.7.2.3 */
|
|
3290
|
|
3291 if ((ngx_uint_t) lcf->alias == alias) {
|
|
3292 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
3293 "\"%V\" directive is duplicate",
|
|
3294 &cmd->name);
|
0
|
3295 } else {
|
|
3296 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
3297 "\"%V\" directive is duplicate, "
|
0
|
3298 "\"%s\" directive is specified before",
|
10
|
3299 &cmd->name, lcf->alias ? "alias" : "root");
|
0
|
3300 }
|
|
3301
|
|
3302 return NGX_CONF_ERROR;
|
|
3303 }
|
|
3304
|
324
|
3305 if (lcf->named && alias) {
|
|
3306 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3307 "the \"alias\" directive may not be used "
|
|
3308 "inside named location");
|
|
3309
|
|
3310 return NGX_CONF_ERROR;
|
|
3311 }
|
|
3312
|
308
|
3313 #if (NGX_PCRE)
|
|
3314
|
|
3315 if (lcf->regex && alias) {
|
|
3316 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3317 "the \"alias\" directive may not be used "
|
|
3318 "inside location given by regular expression");
|
|
3319
|
|
3320 return NGX_CONF_ERROR;
|
|
3321 }
|
|
3322
|
|
3323 #endif
|
|
3324
|
0
|
3325 value = cf->args->elts;
|
|
3326
|
294
|
3327 if (ngx_strstr(value[1].data, "$document_root")
|
|
3328 || ngx_strstr(value[1].data, "${document_root}"))
|
|
3329 {
|
|
3330 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3331 "the $document_root variable may not be used "
|
|
3332 "in the \"%V\" directive",
|
|
3333 &cmd->name);
|
|
3334
|
|
3335 return NGX_CONF_ERROR;
|
|
3336 }
|
|
3337
|
0
|
3338 lcf->alias = alias;
|
|
3339 lcf->root = value[1];
|
|
3340
|
|
3341 if (!alias && lcf->root.data[lcf->root.len - 1] == '/') {
|
|
3342 lcf->root.len--;
|
|
3343 }
|
|
3344
|
216
|
3345 if (lcf->root.data[0] != '$') {
|
324
|
3346 if (ngx_conf_full_name(cf->cycle, &lcf->root, 0) == NGX_ERROR) {
|
216
|
3347 return NGX_CONF_ERROR;
|
|
3348 }
|
152
|
3349 }
|
|
3350
|
|
3351 n = ngx_http_script_variables_count(&lcf->root);
|
144
|
3352
|
|
3353 if (n == 0) {
|
|
3354 return NGX_CONF_OK;
|
|
3355 }
|
|
3356
|
|
3357 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
3358
|
|
3359 sc.cf = cf;
|
152
|
3360 sc.source = &lcf->root;
|
144
|
3361 sc.lengths = &lcf->root_lengths;
|
|
3362 sc.values = &lcf->root_values;
|
|
3363 sc.variables = n;
|
|
3364 sc.complete_lengths = 1;
|
|
3365 sc.complete_values = 1;
|
|
3366
|
|
3367 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
3368 return NGX_CONF_ERROR;
|
|
3369 }
|
|
3370
|
0
|
3371 return NGX_CONF_OK;
|
|
3372 }
|
|
3373
|
|
3374
|
180
|
3375 static ngx_http_method_name_t ngx_methods_names[] = {
|
286
|
3376 { (u_char *) "GET", (uint32_t) ~NGX_HTTP_GET },
|
|
3377 { (u_char *) "HEAD", (uint32_t) ~NGX_HTTP_HEAD },
|
|
3378 { (u_char *) "POST", (uint32_t) ~NGX_HTTP_POST },
|
|
3379 { (u_char *) "PUT", (uint32_t) ~NGX_HTTP_PUT },
|
|
3380 { (u_char *) "DELETE", (uint32_t) ~NGX_HTTP_DELETE },
|
|
3381 { (u_char *) "MKCOL", (uint32_t) ~NGX_HTTP_MKCOL },
|
|
3382 { (u_char *) "COPY", (uint32_t) ~NGX_HTTP_COPY },
|
|
3383 { (u_char *) "MOVE", (uint32_t) ~NGX_HTTP_MOVE },
|
|
3384 { (u_char *) "OPTIONS", (uint32_t) ~NGX_HTTP_OPTIONS },
|
|
3385 { (u_char *) "PROPFIND" , (uint32_t) ~NGX_HTTP_PROPFIND },
|
|
3386 { (u_char *) "PROPPATCH", (uint32_t) ~NGX_HTTP_PROPPATCH },
|
|
3387 { (u_char *) "LOCK", (uint32_t) ~NGX_HTTP_LOCK },
|
|
3388 { (u_char *) "UNLOCK", (uint32_t) ~NGX_HTTP_UNLOCK },
|
180
|
3389 { NULL, 0 }
|
|
3390 };
|
|
3391
|
|
3392
|
|
3393 static char *
|
|
3394 ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
3395 {
|
|
3396 ngx_http_core_loc_conf_t *clcf = conf;
|
|
3397
|
|
3398 char *rv;
|
|
3399 void *mconf;
|
|
3400 ngx_str_t *value;
|
|
3401 ngx_uint_t i;
|
|
3402 ngx_conf_t save;
|
|
3403 ngx_http_module_t *module;
|
|
3404 ngx_http_conf_ctx_t *ctx, *pctx;
|
|
3405 ngx_http_method_name_t *name;
|
|
3406 ngx_http_core_loc_conf_t *lcf, **clcfp;
|
|
3407
|
|
3408 if (clcf->limit_except) {
|
|
3409 return "duplicate";
|
|
3410 }
|
|
3411
|
|
3412 clcf->limit_except = 0xffffffff;
|
|
3413
|
|
3414 value = cf->args->elts;
|
|
3415
|
|
3416 for (i = 1; i < cf->args->nelts; i++) {
|
|
3417 for (name = ngx_methods_names; name->name; name++) {
|
|
3418
|
|
3419 if (ngx_strcasecmp(value[i].data, name->name) == 0) {
|
|
3420 clcf->limit_except &= name->method;
|
|
3421 goto next;
|
|
3422 }
|
|
3423 }
|
|
3424
|
|
3425 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3426 "invalid method \"%V\"", &value[i]);
|
|
3427 return NGX_CONF_ERROR;
|
|
3428
|
|
3429 next:
|
|
3430 continue;
|
|
3431 }
|
|
3432
|
|
3433 if (!(clcf->limit_except & NGX_HTTP_GET)) {
|
|
3434 clcf->limit_except &= (uint32_t) ~NGX_HTTP_HEAD;
|
|
3435 }
|
|
3436
|
|
3437 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
|
|
3438 if (ctx == NULL) {
|
|
3439 return NGX_CONF_ERROR;
|
|
3440 }
|
|
3441
|
|
3442 pctx = cf->ctx;
|
|
3443 ctx->main_conf = pctx->main_conf;
|
|
3444 ctx->srv_conf = pctx->srv_conf;
|
|
3445
|
|
3446 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
3447 if (ctx->loc_conf == NULL) {
|
|
3448 return NGX_CONF_ERROR;
|
|
3449 }
|
|
3450
|
|
3451 for (i = 0; ngx_modules[i]; i++) {
|
|
3452 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
|
|
3453 continue;
|
|
3454 }
|
|
3455
|
|
3456 module = ngx_modules[i]->ctx;
|
|
3457
|
|
3458 if (module->create_loc_conf) {
|
|
3459
|
|
3460 mconf = module->create_loc_conf(cf);
|
|
3461 if (mconf == NULL) {
|
|
3462 return NGX_CONF_ERROR;
|
|
3463 }
|
|
3464
|
|
3465 ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
|
|
3466 }
|
|
3467 }
|
|
3468
|
|
3469
|
|
3470 lcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
|
|
3471 clcf->limit_except_loc_conf = ctx->loc_conf;
|
|
3472 lcf->loc_conf = ctx->loc_conf;
|
|
3473 lcf->name = clcf->name;
|
|
3474 lcf->noname = 1;
|
|
3475
|
308
|
3476 if (clcf->locations == NULL) {
|
|
3477 clcf->locations = ngx_array_create(cf->pool, 2, sizeof(void *));
|
|
3478 if (clcf->locations == NULL) {
|
180
|
3479 return NGX_CONF_ERROR;
|
|
3480 }
|
|
3481 }
|
|
3482
|
308
|
3483 clcfp = ngx_array_push(clcf->locations);
|
180
|
3484 if (clcfp == NULL) {
|
|
3485 return NGX_CONF_ERROR;
|
|
3486 }
|
|
3487
|
|
3488 *clcfp = lcf;
|
|
3489
|
|
3490
|
|
3491 save = *cf;
|
|
3492 cf->ctx = ctx;
|
|
3493 cf->cmd_type = NGX_HTTP_LMT_CONF;
|
|
3494
|
|
3495 rv = ngx_conf_parse(cf, NULL);
|
|
3496
|
|
3497 *cf = save;
|
|
3498
|
|
3499 return rv;
|
|
3500 }
|
|
3501
|
|
3502
|
36
|
3503 static char *
|
|
3504 ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
3505 {
|
|
3506 ngx_http_core_loc_conf_t *lcf = conf;
|
|
3507
|
372
|
3508 u_char *args;
|
222
|
3509 ngx_int_t overwrite;
|
|
3510 ngx_str_t *value, uri;
|
|
3511 ngx_uint_t i, n, nvar;
|
|
3512 ngx_array_t *uri_lengths, *uri_values;
|
|
3513 ngx_http_err_page_t *err;
|
|
3514 ngx_http_script_compile_t sc;
|
0
|
3515
|
|
3516 if (lcf->error_pages == NULL) {
|
36
|
3517 lcf->error_pages = ngx_array_create(cf->pool, 4,
|
0
|
3518 sizeof(ngx_http_err_page_t));
|
|
3519 if (lcf->error_pages == NULL) {
|
|
3520 return NGX_CONF_ERROR;
|
|
3521 }
|
|
3522 }
|
|
3523
|
|
3524 value = cf->args->elts;
|
|
3525
|
|
3526 i = cf->args->nelts - 2;
|
|
3527
|
|
3528 if (value[i].data[0] == '=') {
|
|
3529 if (i == 1) {
|
|
3530 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
3531 "invalid value \"%V\"", &value[i]);
|
0
|
3532 return NGX_CONF_ERROR;
|
|
3533 }
|
|
3534
|
104
|
3535 if (value[i].len > 1) {
|
|
3536 overwrite = ngx_atoi(&value[i].data[1], value[i].len - 1);
|
|
3537
|
|
3538 if (overwrite == NGX_ERROR) {
|
|
3539 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3540 "invalid value \"%V\"", &value[i]);
|
|
3541 return NGX_CONF_ERROR;
|
|
3542 }
|
|
3543
|
|
3544 } else {
|
|
3545 overwrite = 0;
|
0
|
3546 }
|
|
3547
|
|
3548 n = 2;
|
|
3549
|
|
3550 } else {
|
104
|
3551 overwrite = -1;
|
0
|
3552 n = 1;
|
|
3553 }
|
|
3554
|
222
|
3555 uri = value[cf->args->nelts - 1];
|
|
3556 uri_lengths = NULL;
|
|
3557 uri_values = NULL;
|
|
3558
|
|
3559 nvar = ngx_http_script_variables_count(&uri);
|
|
3560
|
|
3561 if (nvar) {
|
|
3562 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
3563
|
|
3564 sc.cf = cf;
|
|
3565 sc.source = &uri;
|
|
3566 sc.lengths = &uri_lengths;
|
|
3567 sc.values = &uri_values;
|
|
3568 sc.variables = nvar;
|
|
3569 sc.complete_lengths = 1;
|
|
3570 sc.complete_values = 1;
|
|
3571
|
|
3572 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
3573 return NGX_CONF_ERROR;
|
|
3574 }
|
|
3575 }
|
|
3576
|
372
|
3577 args = (u_char *) ngx_strchr(uri.data, '?');
|
|
3578
|
0
|
3579 for (i = 1; i < cf->args->nelts - n; i++) {
|
50
|
3580 err = ngx_array_push(lcf->error_pages);
|
|
3581 if (err == NULL) {
|
0
|
3582 return NGX_CONF_ERROR;
|
|
3583 }
|
|
3584
|
|
3585 err->status = ngx_atoi(value[i].data, value[i].len);
|
36
|
3586
|
236
|
3587 if (err->status == NGX_ERROR || err->status == 499) {
|
0
|
3588 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
3589 "invalid value \"%V\"", &value[i]);
|
0
|
3590 return NGX_CONF_ERROR;
|
|
3591 }
|
|
3592
|
|
3593 if (err->status < 400 || err->status > 599) {
|
|
3594 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
3595 "value \"%V\" must be between 400 and 599",
|
|
3596 &value[i]);
|
0
|
3597 return NGX_CONF_ERROR;
|
|
3598 }
|
|
3599
|
366
|
3600 if (overwrite >= 0) {
|
|
3601 err->overwrite = overwrite;
|
|
3602
|
|
3603 } else {
|
|
3604 switch (err->status) {
|
|
3605 case NGX_HTTP_TO_HTTPS:
|
|
3606 case NGX_HTTPS_CERT_ERROR:
|
|
3607 case NGX_HTTPS_NO_CERT:
|
|
3608 err->overwrite = NGX_HTTP_BAD_REQUEST;
|
|
3609 break;
|
|
3610
|
|
3611 default:
|
|
3612 err->overwrite = err->status;
|
|
3613 break;
|
|
3614 }
|
|
3615 }
|
104
|
3616
|
372
|
3617 if (args) {
|
|
3618 err->uri.len = args - uri.data;
|
|
3619 err->uri.data = uri.data;
|
|
3620 args++;
|
|
3621 err->args.len = (uri.data + uri.len) - args;
|
|
3622 err->args.data = args;
|
|
3623
|
|
3624 } else {
|
|
3625 err->uri = uri;
|
|
3626 err->args.len = 0;
|
|
3627 err->args.data = NULL;
|
|
3628 }
|
|
3629
|
222
|
3630 err->uri_lengths = uri_lengths;
|
|
3631 err->uri_values = uri_values;
|
0
|
3632 }
|
|
3633
|
|
3634 return NGX_CONF_OK;
|
|
3635 }
|
|
3636
|
|
3637
|
36
|
3638 static char *
|
332
|
3639 ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
3640 {
|
|
3641 ngx_http_core_loc_conf_t *lcf = conf;
|
|
3642
|
|
3643 time_t inactive;
|
|
3644 ngx_str_t *value, s;
|
|
3645 ngx_int_t max;
|
|
3646 ngx_uint_t i;
|
|
3647
|
|
3648 if (lcf->open_file_cache != NGX_CONF_UNSET_PTR) {
|
|
3649 return "is duplicate";
|
|
3650 }
|
|
3651
|
|
3652 value = cf->args->elts;
|
|
3653
|
|
3654 max = 0;
|
|
3655 inactive = 60;
|
|
3656
|
|
3657 for (i = 1; i < cf->args->nelts; i++) {
|
|
3658
|
|
3659 if (ngx_strncmp(value[i].data, "max=", 4) == 0) {
|
|
3660
|
|
3661 max = ngx_atoi(value[i].data + 4, value[i].len - 4);
|
|
3662 if (max == NGX_ERROR) {
|
|
3663 return NGX_CONF_ERROR;
|
|
3664 }
|
|
3665
|
|
3666 continue;
|
|
3667 }
|
|
3668
|
|
3669 if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) {
|
|
3670
|
|
3671 s.len = value[i].len - 9;
|
|
3672 s.data = value[i].data + 9;
|
|
3673
|
|
3674 inactive = ngx_parse_time(&s, 1);
|
|
3675 if (inactive < 0) {
|
|
3676 return NGX_CONF_ERROR;
|
|
3677 }
|
|
3678
|
|
3679 continue;
|
|
3680 }
|
|
3681
|
|
3682 if (ngx_strcmp(value[i].data, "off") == 0) {
|
|
3683
|
|
3684 lcf->open_file_cache = NULL;
|
|
3685
|
|
3686 continue;
|
|
3687 }
|
|
3688
|
|
3689 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3690 "invalid \"open_file_cache\" parameter \"%V\"",
|
|
3691 &value[i]);
|
|
3692 return NGX_CONF_ERROR;
|
|
3693 }
|
|
3694
|
|
3695 if (lcf->open_file_cache == NULL) {
|
|
3696 return NGX_CONF_OK;
|
|
3697 }
|
|
3698
|
|
3699 if (max == 0) {
|
|
3700 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3701 "\"open_file_cache\" must have \"max\" parameter");
|
|
3702 return NGX_CONF_ERROR;
|
|
3703 }
|
|
3704
|
|
3705 lcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive);
|
|
3706 if (lcf->open_file_cache) {
|
|
3707 return NGX_CONF_OK;
|
|
3708 }
|
|
3709
|
|
3710 return NGX_CONF_ERROR;
|
|
3711 }
|
|
3712
|
|
3713
|
|
3714 static char *
|
58
|
3715 ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
3716 {
|
|
3717 ngx_http_core_loc_conf_t *lcf = conf;
|
|
3718
|
|
3719 lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args);
|
|
3720 if (lcf->err_log == NULL) {
|
|
3721 return NGX_CONF_ERROR;
|
|
3722 }
|
|
3723
|
|
3724 return ngx_set_error_log_levels(cf, lcf->err_log);
|
|
3725 }
|
|
3726
|
|
3727
|
|
3728 static char *
|
36
|
3729 ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
3730 {
|
|
3731 ngx_http_core_loc_conf_t *lcf = conf;
|
|
3732
|
|
3733 ngx_str_t *value;
|
|
3734
|
|
3735 if (lcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) {
|
|
3736 return "is duplicate";
|
|
3737 }
|
|
3738
|
|
3739 value = cf->args->elts;
|
|
3740
|
|
3741 lcf->keepalive_timeout = ngx_parse_time(&value[1], 0);
|
36
|
3742
|
0
|
3743 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) {
|
|
3744 return "invalid value";
|
|
3745 }
|
|
3746
|
|
3747 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) {
|
|
3748 return "value must be less than 597 hours";
|
|
3749 }
|
|
3750
|
|
3751 if (cf->args->nelts == 2) {
|
|
3752 return NGX_CONF_OK;
|
|
3753 }
|
|
3754
|
|
3755 lcf->keepalive_header = ngx_parse_time(&value[2], 1);
|
36
|
3756
|
0
|
3757 if (lcf->keepalive_header == NGX_ERROR) {
|
|
3758 return "invalid value";
|
|
3759 }
|
|
3760
|
|
3761 if (lcf->keepalive_header == NGX_PARSE_LARGE_TIME) {
|
|
3762 return "value must be less than 68 years";
|
|
3763 }
|
|
3764
|
|
3765 return NGX_CONF_OK;
|
|
3766 }
|
|
3767
|
|
3768
|
36
|
3769 static char *
|
58
|
3770 ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
3771 {
|
|
3772 ngx_http_core_loc_conf_t *lcf = conf;
|
|
3773
|
58
|
3774 if (lcf->internal != NGX_CONF_UNSET) {
|
|
3775 return "is duplicate";
|
0
|
3776 }
|
|
3777
|
58
|
3778 lcf->internal = 1;
|
|
3779
|
|
3780 return NGX_CONF_OK;
|
0
|
3781 }
|
|
3782
|
|
3783
|
36
|
3784 static char *
|
348
|
3785 ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
3786 {
|
|
3787 ngx_http_core_loc_conf_t *clcf = conf;
|
|
3788
|
|
3789 ngx_url_t u;
|
|
3790 ngx_str_t *value;
|
|
3791
|
366
|
3792 if (clcf->resolver) {
|
|
3793 return "is duplicate";
|
|
3794 }
|
|
3795
|
348
|
3796 value = cf->args->elts;
|
|
3797
|
354
|
3798 ngx_memzero(&u, sizeof(ngx_url_t));
|
|
3799
|
348
|
3800 u.host = value[1];
|
|
3801 u.port = 53;
|
|
3802
|
|
3803 if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
|
|
3804 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V: %s", &u.host, u.err);
|
|
3805 return NGX_CONF_ERROR;
|
|
3806 }
|
|
3807
|
366
|
3808 clcf->resolver = ngx_resolver_create(cf, &u.addrs[0]);
|
348
|
3809 if (clcf->resolver == NULL) {
|
|
3810 return NGX_OK;
|
|
3811 }
|
|
3812
|
|
3813 return NGX_CONF_OK;
|
|
3814 }
|
|
3815
|
|
3816
|
358
|
3817 #if (NGX_HTTP_GZIP)
|
|
3818
|
|
3819 static char *
|
|
3820 ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
3821 {
|
|
3822 #if (NGX_PCRE)
|
|
3823 ngx_http_core_loc_conf_t *clcf = conf;
|
|
3824
|
|
3825 ngx_str_t err, *value;
|
|
3826 ngx_uint_t i;
|
|
3827 ngx_regex_elt_t *re;
|
|
3828 u_char errstr[NGX_MAX_CONF_ERRSTR];
|
|
3829
|
|
3830 if (clcf->gzip_disable == NGX_CONF_UNSET_PTR) {
|
|
3831 clcf->gzip_disable = ngx_array_create(cf->pool, 2,
|
|
3832 sizeof(ngx_regex_elt_t));
|
|
3833 if (clcf->gzip_disable == NULL) {
|
|
3834 return NGX_CONF_ERROR;
|
|
3835 }
|
|
3836 }
|
|
3837
|
|
3838 value = cf->args->elts;
|
|
3839
|
|
3840 err.len = NGX_MAX_CONF_ERRSTR;
|
|
3841 err.data = errstr;
|
|
3842
|
|
3843 for (i = 1; i < cf->args->nelts; i++) {
|
|
3844
|
|
3845 re = ngx_array_push(clcf->gzip_disable);
|
|
3846 if (re == NULL) {
|
|
3847 return NGX_CONF_ERROR;
|
|
3848 }
|
|
3849
|
|
3850 re->regex = ngx_regex_compile(&value[i], NGX_REGEX_CASELESS, cf->pool,
|
|
3851 &err);
|
|
3852
|
|
3853 if (re->regex == NULL) {
|
|
3854 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
|
|
3855 return NGX_CONF_ERROR;
|
|
3856 }
|
|
3857
|
|
3858 re->name = value[i].data;
|
|
3859 }
|
|
3860
|
|
3861 return NGX_CONF_OK;
|
|
3862
|
|
3863 #else
|
|
3864 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3865 "\"gzip_disable\" requires PCRE library");
|
|
3866
|
|
3867 return NGX_CONF_ERROR;
|
|
3868 #endif
|
|
3869 }
|
|
3870
|
|
3871 #endif
|
|
3872
|
|
3873
|
348
|
3874 static char *
|
36
|
3875 ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data)
|
0
|
3876 {
|
22
|
3877 #if (NGX_FREEBSD)
|
2
|
3878 ssize_t *np = data;
|
0
|
3879
|
222
|
3880 if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) {
|
0
|
3881 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3882 "\"send_lowat\" must be less than %d "
|
|
3883 "(sysctl net.inet.tcp.sendspace)",
|
|
3884 ngx_freebsd_net_inet_tcp_sendspace);
|
|
3885
|
|
3886 return NGX_CONF_ERROR;
|
|
3887 }
|
|
3888
|
18
|
3889 #elif !(NGX_HAVE_SO_SNDLOWAT)
|
22
|
3890 ssize_t *np = data;
|
0
|
3891
|
|
3892 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
3893 "\"send_lowat\" is not supported, ignored");
|
|
3894
|
2
|
3895 *np = 0;
|
|
3896
|
0
|
3897 #endif
|
|
3898
|
|
3899 return NGX_CONF_OK;
|
|
3900 }
|
300
|
3901
|
|
3902
|
|
3903 static char *
|
|
3904 ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data)
|
|
3905 {
|
|
3906 size_t *sp = data;
|
|
3907
|
|
3908 if (*sp < NGX_MIN_POOL_SIZE) {
|
|
3909 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3910 "pool must be no less than %uz", NGX_MIN_POOL_SIZE);
|
|
3911
|
|
3912 return NGX_CONF_ERROR;
|
|
3913 }
|
|
3914
|
|
3915 return NGX_CONF_OK;
|
|
3916 }
|