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