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