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