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