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