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