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