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