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