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
|
672
|
1243 if (reserve > allocated || !allocated) {
|
430
|
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
|
674
|
2602 r->write_event_handler = ngx_http_core_run_phases;
|
430
|
2603 ngx_http_core_run_phases(r);
|
|
2604
|
|
2605 return NGX_DONE;
|
324
|
2606 }
|
|
2607 }
|
|
2608
|
|
2609 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
342
|
2610 "could not find named location \"%V\"", name);
|
324
|
2611
|
|
2612 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
378
|
2613
|
324
|
2614 return NGX_DONE;
|
|
2615 }
|
|
2616
|
|
2617
|
118
|
2618 ngx_http_cleanup_t *
|
|
2619 ngx_http_cleanup_add(ngx_http_request_t *r, size_t size)
|
0
|
2620 {
|
118
|
2621 ngx_http_cleanup_t *cln;
|
|
2622
|
|
2623 r = r->main;
|
|
2624
|
|
2625 cln = ngx_palloc(r->pool, sizeof(ngx_http_cleanup_t));
|
|
2626 if (cln == NULL) {
|
|
2627 return NULL;
|
0
|
2628 }
|
|
2629
|
118
|
2630 if (size) {
|
|
2631 cln->data = ngx_palloc(r->pool, size);
|
|
2632 if (cln->data == NULL) {
|
|
2633 return NULL;
|
|
2634 }
|
|
2635
|
|
2636 } else {
|
|
2637 cln->data = NULL;
|
|
2638 }
|
|
2639
|
|
2640 cln->handler = NULL;
|
|
2641 cln->next = r->cleanup;
|
|
2642
|
|
2643 r->cleanup = cln;
|
|
2644
|
|
2645 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2646 "http cleanup add: %p", cln);
|
|
2647
|
|
2648 return cln;
|
0
|
2649 }
|
|
2650
|
|
2651
|
664
|
2652 ngx_int_t
|
|
2653 ngx_http_set_disable_symlinks(ngx_http_request_t *r,
|
|
2654 ngx_http_core_loc_conf_t *clcf, ngx_str_t *path, ngx_open_file_info_t *of)
|
|
2655 {
|
|
2656 #if (NGX_HAVE_OPENAT)
|
|
2657 u_char *p;
|
|
2658 ngx_str_t from;
|
|
2659
|
|
2660 of->disable_symlinks = clcf->disable_symlinks;
|
|
2661
|
|
2662 if (clcf->disable_symlinks_from == NULL) {
|
|
2663 return NGX_OK;
|
|
2664 }
|
|
2665
|
|
2666 if (ngx_http_complex_value(r, clcf->disable_symlinks_from, &from)
|
|
2667 != NGX_OK)
|
|
2668 {
|
|
2669 return NGX_ERROR;
|
|
2670 }
|
|
2671
|
|
2672 if (from.len == 0
|
|
2673 || from.len > path->len
|
|
2674 || ngx_memcmp(path->data, from.data, from.len) != 0)
|
|
2675 {
|
|
2676 return NGX_OK;
|
|
2677 }
|
|
2678
|
|
2679 if (from.len == path->len) {
|
|
2680 of->disable_symlinks = NGX_DISABLE_SYMLINKS_OFF;
|
|
2681 return NGX_OK;
|
|
2682 }
|
|
2683
|
|
2684 p = path->data + from.len;
|
|
2685
|
|
2686 if (*p == '/') {
|
|
2687 of->disable_symlinks_from = from.len;
|
|
2688 return NGX_OK;
|
|
2689 }
|
|
2690
|
|
2691 p--;
|
|
2692
|
|
2693 if (*p == '/') {
|
|
2694 of->disable_symlinks_from = from.len - 1;
|
|
2695 }
|
|
2696 #endif
|
|
2697
|
|
2698 return NGX_OK;
|
|
2699 }
|
|
2700
|
|
2701
|
674
|
2702 ngx_int_t
|
|
2703 ngx_http_get_forwarded_addr(ngx_http_request_t *r, ngx_addr_t *addr,
|
|
2704 u_char *xff, size_t xfflen, ngx_array_t *proxies, int recursive)
|
|
2705 {
|
|
2706 u_char *p;
|
|
2707 in_addr_t inaddr;
|
|
2708 ngx_addr_t paddr;
|
|
2709 ngx_cidr_t *cidr;
|
|
2710 ngx_uint_t family, i;
|
|
2711 #if (NGX_HAVE_INET6)
|
|
2712 ngx_uint_t n;
|
|
2713 struct in6_addr *inaddr6;
|
|
2714 #endif
|
|
2715
|
|
2716 #if (NGX_SUPPRESS_WARN)
|
|
2717 inaddr = 0;
|
|
2718 #if (NGX_HAVE_INET6)
|
|
2719 inaddr6 = NULL;
|
|
2720 #endif
|
|
2721 #endif
|
|
2722
|
|
2723 family = addr->sockaddr->sa_family;
|
|
2724
|
|
2725 if (family == AF_INET) {
|
|
2726 inaddr = ((struct sockaddr_in *) addr->sockaddr)->sin_addr.s_addr;
|
|
2727 }
|
|
2728
|
|
2729 #if (NGX_HAVE_INET6)
|
|
2730 else if (family == AF_INET6) {
|
|
2731 inaddr6 = &((struct sockaddr_in6 *) addr->sockaddr)->sin6_addr;
|
|
2732
|
|
2733 if (IN6_IS_ADDR_V4MAPPED(inaddr6)) {
|
|
2734 family = AF_INET;
|
|
2735 inaddr = *(in_addr_t *) &inaddr6->s6_addr[12];
|
|
2736 }
|
|
2737 }
|
|
2738 #endif
|
|
2739
|
|
2740 for (cidr = proxies->elts, i = 0; i < proxies->nelts; i++) {
|
|
2741 if (cidr[i].family != family) {
|
|
2742 goto next;
|
|
2743 }
|
|
2744
|
|
2745 switch (family) {
|
|
2746
|
|
2747 #if (NGX_HAVE_INET6)
|
|
2748 case AF_INET6:
|
|
2749 for (n = 0; n < 16; n++) {
|
|
2750 if ((inaddr6->s6_addr[n] & cidr[i].u.in6.mask.s6_addr[n])
|
|
2751 != cidr[i].u.in6.addr.s6_addr[n])
|
|
2752 {
|
|
2753 goto next;
|
|
2754 }
|
|
2755 }
|
|
2756 break;
|
|
2757 #endif
|
|
2758
|
|
2759 #if (NGX_HAVE_UNIX_DOMAIN)
|
|
2760 case AF_UNIX:
|
|
2761 break;
|
|
2762 #endif
|
|
2763
|
|
2764 default: /* AF_INET */
|
|
2765 if ((inaddr & cidr[i].u.in.mask) != cidr[i].u.in.addr) {
|
|
2766 goto next;
|
|
2767 }
|
|
2768 break;
|
|
2769 }
|
|
2770
|
|
2771 for (p = xff + xfflen - 1; p > xff; p--, xfflen--) {
|
|
2772 if (*p != ' ' && *p != ',') {
|
|
2773 break;
|
|
2774 }
|
|
2775 }
|
|
2776
|
|
2777 for ( /* void */ ; p > xff; p--) {
|
|
2778 if (*p == ' ' || *p == ',') {
|
|
2779 p++;
|
|
2780 break;
|
|
2781 }
|
|
2782 }
|
|
2783
|
|
2784 if (ngx_parse_addr(r->pool, &paddr, p, xfflen - (p - xff)) != NGX_OK) {
|
|
2785 return NGX_DECLINED;
|
|
2786 }
|
|
2787
|
|
2788 *addr = paddr;
|
|
2789
|
|
2790 if (recursive && p > xff) {
|
|
2791 (void) ngx_http_get_forwarded_addr(r, addr, xff, p - 1 - xff,
|
|
2792 proxies, 1);
|
|
2793 }
|
|
2794
|
|
2795 return NGX_OK;
|
|
2796
|
|
2797 next:
|
|
2798 continue;
|
|
2799 }
|
|
2800
|
|
2801 return NGX_DECLINED;
|
|
2802 }
|
|
2803
|
|
2804
|
36
|
2805 static char *
|
|
2806 ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
0
|
2807 {
|
308
|
2808 char *rv;
|
|
2809 void *mconf;
|
310
|
2810 ngx_uint_t i;
|
308
|
2811 ngx_conf_t pcf;
|
|
2812 ngx_http_module_t *module;
|
602
|
2813 struct sockaddr_in *sin;
|
308
|
2814 ngx_http_conf_ctx_t *ctx, *http_ctx;
|
602
|
2815 ngx_http_listen_opt_t lsopt;
|
308
|
2816 ngx_http_core_srv_conf_t *cscf, **cscfp;
|
310
|
2817 ngx_http_core_main_conf_t *cmcf;
|
36
|
2818
|
50
|
2819 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
|
|
2820 if (ctx == NULL) {
|
36
|
2821 return NGX_CONF_ERROR;
|
|
2822 }
|
0
|
2823
|
|
2824 http_ctx = cf->ctx;
|
|
2825 ctx->main_conf = http_ctx->main_conf;
|
|
2826
|
|
2827 /* the server{}'s srv_conf */
|
|
2828
|
36
|
2829 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
2830 if (ctx->srv_conf == NULL) {
|
|
2831 return NGX_CONF_ERROR;
|
|
2832 }
|
0
|
2833
|
|
2834 /* the server{}'s loc_conf */
|
|
2835
|
36
|
2836 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
2837 if (ctx->loc_conf == NULL) {
|
|
2838 return NGX_CONF_ERROR;
|
|
2839 }
|
0
|
2840
|
310
|
2841 for (i = 0; ngx_modules[i]; i++) {
|
|
2842 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
|
0
|
2843 continue;
|
|
2844 }
|
|
2845
|
310
|
2846 module = ngx_modules[i]->ctx;
|
0
|
2847
|
|
2848 if (module->create_srv_conf) {
|
50
|
2849 mconf = module->create_srv_conf(cf);
|
|
2850 if (mconf == NULL) {
|
36
|
2851 return NGX_CONF_ERROR;
|
|
2852 }
|
|
2853
|
310
|
2854 ctx->srv_conf[ngx_modules[i]->ctx_index] = mconf;
|
0
|
2855 }
|
|
2856
|
|
2857 if (module->create_loc_conf) {
|
50
|
2858 mconf = module->create_loc_conf(cf);
|
|
2859 if (mconf == NULL) {
|
36
|
2860 return NGX_CONF_ERROR;
|
|
2861 }
|
|
2862
|
310
|
2863 ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
|
0
|
2864 }
|
|
2865 }
|
|
2866
|
36
|
2867
|
|
2868 /* the server configuration context */
|
0
|
2869
|
|
2870 cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
|
|
2871 cscf->ctx = ctx;
|
|
2872
|
36
|
2873
|
0
|
2874 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
|
36
|
2875
|
50
|
2876 cscfp = ngx_array_push(&cmcf->servers);
|
|
2877 if (cscfp == NULL) {
|
36
|
2878 return NGX_CONF_ERROR;
|
|
2879 }
|
|
2880
|
0
|
2881 *cscfp = cscf;
|
|
2882
|
36
|
2883
|
0
|
2884 /* parse inside server{} */
|
|
2885
|
70
|
2886 pcf = *cf;
|
0
|
2887 cf->ctx = ctx;
|
|
2888 cf->cmd_type = NGX_HTTP_SRV_CONF;
|
34
|
2889
|
0
|
2890 rv = ngx_conf_parse(cf, NULL);
|
34
|
2891
|
70
|
2892 *cf = pcf;
|
0
|
2893
|
602
|
2894 if (rv == NGX_CONF_OK && !cscf->listen) {
|
|
2895 ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t));
|
|
2896
|
|
2897 sin = &lsopt.u.sockaddr_in;
|
|
2898
|
|
2899 sin->sin_family = AF_INET;
|
|
2900 #if (NGX_WIN32)
|
|
2901 sin->sin_port = htons(80);
|
|
2902 #else
|
|
2903 sin->sin_port = htons((getuid() == 0) ? 80 : 8000);
|
|
2904 #endif
|
|
2905 sin->sin_addr.s_addr = INADDR_ANY;
|
|
2906
|
|
2907 lsopt.socklen = sizeof(struct sockaddr_in);
|
|
2908
|
|
2909 lsopt.backlog = NGX_LISTEN_BACKLOG;
|
|
2910 lsopt.rcvbuf = -1;
|
|
2911 lsopt.sndbuf = -1;
|
|
2912 #if (NGX_HAVE_SETFIB)
|
|
2913 lsopt.setfib = -1;
|
|
2914 #endif
|
|
2915 lsopt.wildcard = 1;
|
|
2916
|
|
2917 (void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.addr,
|
|
2918 NGX_SOCKADDR_STRLEN, 1);
|
|
2919
|
|
2920 if (ngx_http_add_listen(cf, cscf, &lsopt) != NGX_OK) {
|
|
2921 return NGX_CONF_ERROR;
|
|
2922 }
|
|
2923 }
|
|
2924
|
0
|
2925 return rv;
|
|
2926 }
|
|
2927
|
|
2928
|
36
|
2929 static char *
|
|
2930 ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
0
|
2931 {
|
|
2932 char *rv;
|
430
|
2933 u_char *mod;
|
|
2934 size_t len;
|
|
2935 ngx_str_t *value, *name;
|
310
|
2936 ngx_uint_t i;
|
34
|
2937 ngx_conf_t save;
|
0
|
2938 ngx_http_module_t *module;
|
|
2939 ngx_http_conf_ctx_t *ctx, *pctx;
|
378
|
2940 ngx_http_core_loc_conf_t *clcf, *pclcf;
|
0
|
2941
|
50
|
2942 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
|
|
2943 if (ctx == NULL) {
|
0
|
2944 return NGX_CONF_ERROR;
|
|
2945 }
|
|
2946
|
|
2947 pctx = cf->ctx;
|
|
2948 ctx->main_conf = pctx->main_conf;
|
|
2949 ctx->srv_conf = pctx->srv_conf;
|
|
2950
|
|
2951 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
2952 if (ctx->loc_conf == NULL) {
|
|
2953 return NGX_CONF_ERROR;
|
|
2954 }
|
|
2955
|
310
|
2956 for (i = 0; ngx_modules[i]; i++) {
|
|
2957 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
|
0
|
2958 continue;
|
|
2959 }
|
|
2960
|
310
|
2961 module = ngx_modules[i]->ctx;
|
0
|
2962
|
|
2963 if (module->create_loc_conf) {
|
310
|
2964 ctx->loc_conf[ngx_modules[i]->ctx_index] =
|
0
|
2965 module->create_loc_conf(cf);
|
310
|
2966 if (ctx->loc_conf[ngx_modules[i]->ctx_index] == NULL) {
|
0
|
2967 return NGX_CONF_ERROR;
|
|
2968 }
|
|
2969 }
|
|
2970 }
|
|
2971
|
|
2972 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
|
|
2973 clcf->loc_conf = ctx->loc_conf;
|
|
2974
|
|
2975 value = cf->args->elts;
|
|
2976
|
|
2977 if (cf->args->nelts == 3) {
|
430
|
2978
|
|
2979 len = value[1].len;
|
|
2980 mod = value[1].data;
|
|
2981 name = &value[2];
|
|
2982
|
|
2983 if (len == 1 && mod[0] == '=') {
|
|
2984
|
|
2985 clcf->name = *name;
|
0
|
2986 clcf->exact_match = 1;
|
|
2987
|
430
|
2988 } else if (len == 2 && mod[0] == '^' && mod[1] == '~') {
|
|
2989
|
|
2990 clcf->name = *name;
|
16
|
2991 clcf->noregex = 1;
|
|
2992
|
430
|
2993 } else if (len == 1 && mod[0] == '~') {
|
|
2994
|
|
2995 if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
|
0
|
2996 return NGX_CONF_ERROR;
|
|
2997 }
|
|
2998
|
430
|
2999 } else if (len == 2 && mod[0] == '~' && mod[1] == '*') {
|
|
3000
|
|
3001 if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
|
|
3002 return NGX_CONF_ERROR;
|
|
3003 }
|
0
|
3004
|
|
3005 } else {
|
|
3006 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
3007 "invalid location modifier \"%V\"", &value[1]);
|
0
|
3008 return NGX_CONF_ERROR;
|
|
3009 }
|
|
3010
|
|
3011 } else {
|
324
|
3012
|
430
|
3013 name = &value[1];
|
|
3014
|
|
3015 if (name->data[0] == '=') {
|
|
3016
|
|
3017 clcf->name.len = name->len - 1;
|
|
3018 clcf->name.data = name->data + 1;
|
|
3019 clcf->exact_match = 1;
|
|
3020
|
|
3021 } else if (name->data[0] == '^' && name->data[1] == '~') {
|
|
3022
|
|
3023 clcf->name.len = name->len - 2;
|
|
3024 clcf->name.data = name->data + 2;
|
|
3025 clcf->noregex = 1;
|
|
3026
|
|
3027 } else if (name->data[0] == '~') {
|
|
3028
|
|
3029 name->len--;
|
|
3030 name->data++;
|
|
3031
|
|
3032 if (name->data[0] == '*') {
|
|
3033
|
|
3034 name->len--;
|
|
3035 name->data++;
|
|
3036
|
|
3037 if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
|
|
3038 return NGX_CONF_ERROR;
|
|
3039 }
|
|
3040
|
|
3041 } else {
|
|
3042 if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
|
|
3043 return NGX_CONF_ERROR;
|
|
3044 }
|
|
3045 }
|
|
3046
|
|
3047 } else {
|
|
3048
|
|
3049 clcf->name = *name;
|
|
3050
|
|
3051 if (name->data[0] == '@') {
|
|
3052 clcf->named = 1;
|
|
3053 }
|
324
|
3054 }
|
0
|
3055 }
|
|
3056
|
|
3057 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
|
|
3058
|
378
|
3059 if (pclcf->name.len) {
|
|
3060
|
|
3061 /* nested location */
|
|
3062
|
34
|
3063 #if 0
|
0
|
3064 clcf->prev_location = pclcf;
|
34
|
3065 #endif
|
0
|
3066
|
|
3067 if (pclcf->exact_match) {
|
|
3068 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
640
|
3069 "location \"%V\" cannot be inside "
|
10
|
3070 "the exact location \"%V\"",
|
|
3071 &clcf->name, &pclcf->name);
|
0
|
3072 return NGX_CONF_ERROR;
|
|
3073 }
|
|
3074
|
324
|
3075 if (pclcf->named) {
|
|
3076 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
640
|
3077 "location \"%V\" cannot be inside "
|
324
|
3078 "the named location \"%V\"",
|
|
3079 &clcf->name, &pclcf->name);
|
|
3080 return NGX_CONF_ERROR;
|
|
3081 }
|
|
3082
|
378
|
3083 if (clcf->named) {
|
|
3084 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
640
|
3085 "named location \"%V\" can be "
|
|
3086 "on the server level only",
|
378
|
3087 &clcf->name);
|
|
3088 return NGX_CONF_ERROR;
|
|
3089 }
|
|
3090
|
430
|
3091 len = pclcf->name.len;
|
|
3092
|
4
|
3093 #if (NGX_PCRE)
|
0
|
3094 if (clcf->regex == NULL
|
430
|
3095 && ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0)
|
0
|
3096 #else
|
430
|
3097 if (ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0)
|
0
|
3098 #endif
|
|
3099 {
|
|
3100 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
3101 "location \"%V\" is outside location \"%V\"",
|
|
3102 &clcf->name, &pclcf->name);
|
0
|
3103 return NGX_CONF_ERROR;
|
|
3104 }
|
|
3105 }
|
|
3106
|
378
|
3107 if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
|
|
3108 return NGX_CONF_ERROR;
|
|
3109 }
|
0
|
3110
|
34
|
3111 save = *cf;
|
0
|
3112 cf->ctx = ctx;
|
|
3113 cf->cmd_type = NGX_HTTP_LOC_CONF;
|
34
|
3114
|
0
|
3115 rv = ngx_conf_parse(cf, NULL);
|
34
|
3116
|
|
3117 *cf = save;
|
|
3118
|
0
|
3119 return rv;
|
|
3120 }
|
|
3121
|
|
3122
|
430
|
3123 static ngx_int_t
|
|
3124 ngx_http_core_regex_location(ngx_conf_t *cf, ngx_http_core_loc_conf_t *clcf,
|
|
3125 ngx_str_t *regex, ngx_uint_t caseless)
|
|
3126 {
|
|
3127 #if (NGX_PCRE)
|
546
|
3128 ngx_regex_compile_t rc;
|
|
3129 u_char errstr[NGX_MAX_CONF_ERRSTR];
|
|
3130
|
|
3131 ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
|
|
3132
|
|
3133 rc.pattern = *regex;
|
|
3134 rc.err.len = NGX_MAX_CONF_ERRSTR;
|
|
3135 rc.err.data = errstr;
|
430
|
3136
|
508
|
3137 #if (NGX_HAVE_CASELESS_FILESYSTEM)
|
546
|
3138 rc.options = NGX_REGEX_CASELESS;
|
558
|
3139 #else
|
|
3140 rc.options = caseless;
|
508
|
3141 #endif
|
|
3142
|
546
|
3143 clcf->regex = ngx_http_regex_compile(cf, &rc);
|
430
|
3144 if (clcf->regex == NULL) {
|
|
3145 return NGX_ERROR;
|
|
3146 }
|
|
3147
|
|
3148 clcf->name = *regex;
|
|
3149
|
|
3150 return NGX_OK;
|
|
3151
|
|
3152 #else
|
|
3153
|
|
3154 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
640
|
3155 "using regex \"%V\" requires PCRE library",
|
430
|
3156 regex);
|
|
3157 return NGX_ERROR;
|
|
3158
|
|
3159 #endif
|
|
3160 }
|
|
3161
|
|
3162
|
36
|
3163 static char *
|
|
3164 ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
3165 {
|
546
|
3166 ngx_http_core_loc_conf_t *clcf = conf;
|
186
|
3167
|
0
|
3168 char *rv;
|
34
|
3169 ngx_conf_t save;
|
0
|
3170
|
546
|
3171 if (clcf->types == NULL) {
|
|
3172 clcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t));
|
|
3173 if (clcf->types == NULL) {
|
186
|
3174 return NGX_CONF_ERROR;
|
|
3175 }
|
|
3176 }
|
|
3177
|
34
|
3178 save = *cf;
|
|
3179 cf->handler = ngx_http_core_type;
|
0
|
3180 cf->handler_conf = conf;
|
34
|
3181
|
0
|
3182 rv = ngx_conf_parse(cf, NULL);
|
34
|
3183
|
|
3184 *cf = save;
|
0
|
3185
|
|
3186 return rv;
|
|
3187 }
|
|
3188
|
|
3189
|
36
|
3190 static char *
|
|
3191 ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
|
0
|
3192 {
|
546
|
3193 ngx_http_core_loc_conf_t *clcf = conf;
|
0
|
3194
|
294
|
3195 ngx_str_t *value, *content_type, *old, file;
|
392
|
3196 ngx_uint_t i, n, hash;
|
138
|
3197 ngx_hash_key_t *type;
|
0
|
3198
|
294
|
3199 value = cf->args->elts;
|
|
3200
|
|
3201 if (ngx_strcmp(value[0].data, "include") == 0) {
|
644
|
3202 if (cf->args->nelts != 2) {
|
|
3203 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3204 "invalid number of arguments"
|
|
3205 " in \"include\" directive");
|
|
3206 return NGX_CONF_ERROR;
|
|
3207 }
|
294
|
3208 file = value[1];
|
|
3209
|
454
|
3210 if (ngx_conf_full_name(cf->cycle, &file, 1) != NGX_OK) {
|
294
|
3211 return NGX_CONF_ERROR;
|
|
3212 }
|
|
3213
|
|
3214 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
|
|
3215
|
|
3216 return ngx_conf_parse(cf, &file);
|
|
3217 }
|
|
3218
|
138
|
3219 content_type = ngx_palloc(cf->pool, sizeof(ngx_str_t));
|
|
3220 if (content_type == NULL) {
|
|
3221 return NGX_CONF_ERROR;
|
0
|
3222 }
|
|
3223
|
138
|
3224 *content_type = value[0];
|
0
|
3225
|
|
3226 for (i = 1; i < cf->args->nelts; i++) {
|
138
|
3227
|
392
|
3228 hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len);
|
138
|
3229
|
546
|
3230 type = clcf->types->elts;
|
|
3231 for (n = 0; n < clcf->types->nelts; n++) {
|
138
|
3232 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) {
|
|
3233 old = type[n].value;
|
|
3234 type[n].value = content_type;
|
|
3235
|
|
3236 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
640
|
3237 "duplicate extension \"%V\", "
|
138
|
3238 "content type: \"%V\", "
|
640
|
3239 "previous content type: \"%V\"",
|
138
|
3240 &value[i], content_type, old);
|
644
|
3241 goto next;
|
138
|
3242 }
|
|
3243 }
|
|
3244
|
|
3245
|
546
|
3246 type = ngx_array_push(clcf->types);
|
50
|
3247 if (type == NULL) {
|
0
|
3248 return NGX_CONF_ERROR;
|
|
3249 }
|
|
3250
|
138
|
3251 type->key = value[i];
|
392
|
3252 type->key_hash = hash;
|
138
|
3253 type->value = content_type;
|
644
|
3254
|
|
3255 next:
|
|
3256 continue;
|
0
|
3257 }
|
|
3258
|
|
3259 return NGX_CONF_OK;
|
|
3260 }
|
|
3261
|
|
3262
|
58
|
3263 static ngx_int_t
|
|
3264 ngx_http_core_preconfiguration(ngx_conf_t *cf)
|
|
3265 {
|
|
3266 return ngx_http_variables_add_core_vars(cf);
|
|
3267 }
|
|
3268
|
|
3269
|
36
|
3270 static void *
|
|
3271 ngx_http_core_create_main_conf(ngx_conf_t *cf)
|
0
|
3272 {
|
34
|
3273 ngx_http_core_main_conf_t *cmcf;
|
|
3274
|
50
|
3275 cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t));
|
|
3276 if (cmcf == NULL) {
|
496
|
3277 return NULL;
|
34
|
3278 }
|
0
|
3279
|
48
|
3280 if (ngx_array_init(&cmcf->servers, cf->pool, 4,
|
118
|
3281 sizeof(ngx_http_core_srv_conf_t *))
|
200
|
3282 != NGX_OK)
|
34
|
3283 {
|
496
|
3284 return NULL;
|
34
|
3285 }
|
0
|
3286
|
142
|
3287 cmcf->server_names_hash_max_size = NGX_CONF_UNSET_UINT;
|
|
3288 cmcf->server_names_hash_bucket_size = NGX_CONF_UNSET_UINT;
|
26
|
3289
|
160
|
3290 cmcf->variables_hash_max_size = NGX_CONF_UNSET_UINT;
|
|
3291 cmcf->variables_hash_bucket_size = NGX_CONF_UNSET_UINT;
|
|
3292
|
0
|
3293 return cmcf;
|
|
3294 }
|
|
3295
|
|
3296
|
36
|
3297 static char *
|
|
3298 ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf)
|
0
|
3299 {
|
|
3300 ngx_http_core_main_conf_t *cmcf = conf;
|
|
3301
|
142
|
3302 if (cmcf->server_names_hash_max_size == NGX_CONF_UNSET_UINT) {
|
|
3303 cmcf->server_names_hash_max_size = 512;
|
26
|
3304 }
|
|
3305
|
142
|
3306 if (cmcf->server_names_hash_bucket_size == NGX_CONF_UNSET_UINT) {
|
|
3307 cmcf->server_names_hash_bucket_size = ngx_cacheline_size;
|
26
|
3308 }
|
0
|
3309
|
142
|
3310 cmcf->server_names_hash_bucket_size =
|
|
3311 ngx_align(cmcf->server_names_hash_bucket_size, ngx_cacheline_size);
|
|
3312
|
160
|
3313
|
|
3314 if (cmcf->variables_hash_max_size == NGX_CONF_UNSET_UINT) {
|
|
3315 cmcf->variables_hash_max_size = 512;
|
|
3316 }
|
|
3317
|
|
3318 if (cmcf->variables_hash_bucket_size == NGX_CONF_UNSET_UINT) {
|
|
3319 cmcf->variables_hash_bucket_size = 64;
|
|
3320 }
|
|
3321
|
|
3322 cmcf->variables_hash_bucket_size =
|
|
3323 ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size);
|
|
3324
|
548
|
3325 if (cmcf->ncaptures) {
|
|
3326 cmcf->ncaptures = (cmcf->ncaptures + 1) * 3;
|
|
3327 }
|
|
3328
|
0
|
3329 return NGX_CONF_OK;
|
|
3330 }
|
|
3331
|
|
3332
|
36
|
3333 static void *
|
|
3334 ngx_http_core_create_srv_conf(ngx_conf_t *cf)
|
0
|
3335 {
|
|
3336 ngx_http_core_srv_conf_t *cscf;
|
|
3337
|
50
|
3338 cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t));
|
|
3339 if (cscf == NULL) {
|
496
|
3340 return NULL;
|
36
|
3341 }
|
|
3342
|
0
|
3343 /*
|
36
|
3344 * set by ngx_pcalloc():
|
28
|
3345 *
|
|
3346 * conf->client_large_buffers.num = 0;
|
|
3347 */
|
0
|
3348
|
230
|
3349 if (ngx_array_init(&cscf->server_names, cf->temp_pool, 4,
|
142
|
3350 sizeof(ngx_http_server_name_t))
|
454
|
3351 != NGX_OK)
|
36
|
3352 {
|
496
|
3353 return NULL;
|
36
|
3354 }
|
0
|
3355
|
|
3356 cscf->connection_pool_size = NGX_CONF_UNSET_SIZE;
|
|
3357 cscf->request_pool_size = NGX_CONF_UNSET_SIZE;
|
|
3358 cscf->client_header_timeout = NGX_CONF_UNSET_MSEC;
|
|
3359 cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE;
|
60
|
3360 cscf->ignore_invalid_headers = NGX_CONF_UNSET;
|
342
|
3361 cscf->merge_slashes = NGX_CONF_UNSET;
|
412
|
3362 cscf->underscores_in_headers = NGX_CONF_UNSET;
|
0
|
3363
|
|
3364 return cscf;
|
|
3365 }
|
|
3366
|
|
3367
|
36
|
3368 static char *
|
|
3369 ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
0
|
3370 {
|
|
3371 ngx_http_core_srv_conf_t *prev = parent;
|
|
3372 ngx_http_core_srv_conf_t *conf = child;
|
|
3373
|
612
|
3374 ngx_str_t name;
|
142
|
3375 ngx_http_server_name_t *sn;
|
0
|
3376
|
|
3377 /* TODO: it does not merge, it inits only */
|
|
3378
|
540
|
3379 ngx_conf_merge_size_value(conf->connection_pool_size,
|
|
3380 prev->connection_pool_size, 256);
|
|
3381 ngx_conf_merge_size_value(conf->request_pool_size,
|
|
3382 prev->request_pool_size, 4096);
|
|
3383 ngx_conf_merge_msec_value(conf->client_header_timeout,
|
|
3384 prev->client_header_timeout, 60000);
|
|
3385 ngx_conf_merge_size_value(conf->client_header_buffer_size,
|
|
3386 prev->client_header_buffer_size, 1024);
|
|
3387 ngx_conf_merge_bufs_value(conf->large_client_header_buffers,
|
|
3388 prev->large_client_header_buffers,
|
556
|
3389 4, 8192);
|
540
|
3390
|
|
3391 if (conf->large_client_header_buffers.size < conf->connection_pool_size) {
|
|
3392 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3393 "the \"large_client_header_buffers\" size must be "
|
640
|
3394 "equal to or greater than \"connection_pool_size\"");
|
540
|
3395 return NGX_CONF_ERROR;
|
|
3396 }
|
|
3397
|
|
3398 ngx_conf_merge_value(conf->ignore_invalid_headers,
|
|
3399 prev->ignore_invalid_headers, 1);
|
|
3400
|
|
3401 ngx_conf_merge_value(conf->merge_slashes, prev->merge_slashes, 1);
|
|
3402
|
|
3403 ngx_conf_merge_value(conf->underscores_in_headers,
|
|
3404 prev->underscores_in_headers, 0);
|
|
3405
|
612
|
3406 if (conf->server_names.nelts == 0) {
|
640
|
3407 /* the array has 4 empty preallocated elements, so push cannot fail */
|
50
|
3408 sn = ngx_array_push(&conf->server_names);
|
342
|
3409 #if (NGX_PCRE)
|
|
3410 sn->regex = NULL;
|
|
3411 #endif
|
538
|
3412 sn->server = conf;
|
592
|
3413 ngx_str_set(&sn->name, "");
|
0
|
3414 }
|
|
3415
|
612
|
3416 sn = conf->server_names.elts;
|
|
3417 name = sn[0].name;
|
|
3418
|
|
3419 #if (NGX_PCRE)
|
|
3420 if (sn->regex) {
|
|
3421 name.len++;
|
|
3422 name.data--;
|
|
3423 } else
|
|
3424 #endif
|
|
3425
|
|
3426 if (name.data[0] == '.') {
|
|
3427 name.len--;
|
|
3428 name.data++;
|
|
3429 }
|
|
3430
|
|
3431 conf->server_name.len = name.len;
|
|
3432 conf->server_name.data = ngx_pstrdup(cf->pool, &name);
|
|
3433 if (conf->server_name.data == NULL) {
|
|
3434 return NGX_CONF_ERROR;
|
|
3435 }
|
|
3436
|
0
|
3437 return NGX_CONF_OK;
|
|
3438 }
|
|
3439
|
|
3440
|
36
|
3441 static void *
|
|
3442 ngx_http_core_create_loc_conf(ngx_conf_t *cf)
|
0
|
3443 {
|
546
|
3444 ngx_http_core_loc_conf_t *clcf;
|
|
3445
|
|
3446 clcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t));
|
|
3447 if (clcf == NULL) {
|
496
|
3448 return NULL;
|
36
|
3449 }
|
0
|
3450
|
28
|
3451 /*
|
|
3452 * set by ngx_pcalloc():
|
|
3453 *
|
546
|
3454 * clcf->root = { 0, NULL };
|
|
3455 * clcf->limit_except = 0;
|
|
3456 * clcf->post_action = { 0, NULL };
|
|
3457 * clcf->types = NULL;
|
|
3458 * clcf->default_type = { 0, NULL };
|
|
3459 * clcf->error_log = NULL;
|
|
3460 * clcf->error_pages = NULL;
|
|
3461 * clcf->try_files = NULL;
|
|
3462 * clcf->client_body_path = NULL;
|
|
3463 * clcf->regex = NULL;
|
|
3464 * clcf->exact_match = 0;
|
|
3465 * clcf->auto_redirect = 0;
|
|
3466 * clcf->alias = 0;
|
|
3467 * clcf->gzip_proxied = 0;
|
650
|
3468 * clcf->keepalive_disable = 0;
|
28
|
3469 */
|
0
|
3470
|
546
|
3471 clcf->client_max_body_size = NGX_CONF_UNSET;
|
|
3472 clcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE;
|
|
3473 clcf->client_body_timeout = NGX_CONF_UNSET_MSEC;
|
|
3474 clcf->satisfy = NGX_CONF_UNSET_UINT;
|
|
3475 clcf->if_modified_since = NGX_CONF_UNSET_UINT;
|
636
|
3476 clcf->max_ranges = NGX_CONF_UNSET_UINT;
|
546
|
3477 clcf->client_body_in_file_only = NGX_CONF_UNSET_UINT;
|
|
3478 clcf->client_body_in_single_buffer = NGX_CONF_UNSET;
|
|
3479 clcf->internal = NGX_CONF_UNSET;
|
|
3480 clcf->sendfile = NGX_CONF_UNSET;
|
|
3481 clcf->sendfile_max_chunk = NGX_CONF_UNSET_SIZE;
|
518
|
3482 #if (NGX_HAVE_FILE_AIO)
|
546
|
3483 clcf->aio = NGX_CONF_UNSET;
|
518
|
3484 #endif
|
546
|
3485 clcf->read_ahead = NGX_CONF_UNSET_SIZE;
|
|
3486 clcf->directio = NGX_CONF_UNSET;
|
|
3487 clcf->directio_alignment = NGX_CONF_UNSET;
|
|
3488 clcf->tcp_nopush = NGX_CONF_UNSET;
|
|
3489 clcf->tcp_nodelay = NGX_CONF_UNSET;
|
|
3490 clcf->send_timeout = NGX_CONF_UNSET_MSEC;
|
|
3491 clcf->send_lowat = NGX_CONF_UNSET_SIZE;
|
|
3492 clcf->postpone_output = NGX_CONF_UNSET_SIZE;
|
|
3493 clcf->limit_rate = NGX_CONF_UNSET_SIZE;
|
|
3494 clcf->limit_rate_after = NGX_CONF_UNSET_SIZE;
|
|
3495 clcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
|
|
3496 clcf->keepalive_header = NGX_CONF_UNSET;
|
|
3497 clcf->keepalive_requests = NGX_CONF_UNSET_UINT;
|
632
|
3498 clcf->lingering_close = NGX_CONF_UNSET_UINT;
|
546
|
3499 clcf->lingering_time = NGX_CONF_UNSET_MSEC;
|
|
3500 clcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
|
|
3501 clcf->resolver_timeout = NGX_CONF_UNSET_MSEC;
|
|
3502 clcf->reset_timedout_connection = NGX_CONF_UNSET;
|
|
3503 clcf->server_name_in_redirect = NGX_CONF_UNSET;
|
|
3504 clcf->port_in_redirect = NGX_CONF_UNSET;
|
|
3505 clcf->msie_padding = NGX_CONF_UNSET;
|
|
3506 clcf->msie_refresh = NGX_CONF_UNSET;
|
|
3507 clcf->log_not_found = NGX_CONF_UNSET;
|
|
3508 clcf->log_subrequest = NGX_CONF_UNSET;
|
|
3509 clcf->recursive_error_pages = NGX_CONF_UNSET;
|
|
3510 clcf->server_tokens = NGX_CONF_UNSET;
|
566
|
3511 clcf->chunked_transfer_encoding = NGX_CONF_UNSET;
|
546
|
3512 clcf->types_hash_max_size = NGX_CONF_UNSET_UINT;
|
|
3513 clcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT;
|
|
3514
|
|
3515 clcf->open_file_cache = NGX_CONF_UNSET_PTR;
|
|
3516 clcf->open_file_cache_valid = NGX_CONF_UNSET;
|
|
3517 clcf->open_file_cache_min_uses = NGX_CONF_UNSET_UINT;
|
|
3518 clcf->open_file_cache_errors = NGX_CONF_UNSET;
|
|
3519 clcf->open_file_cache_events = NGX_CONF_UNSET;
|
0
|
3520
|
358
|
3521 #if (NGX_HTTP_GZIP)
|
546
|
3522 clcf->gzip_vary = NGX_CONF_UNSET;
|
|
3523 clcf->gzip_http_version = NGX_CONF_UNSET_UINT;
|
362
|
3524 #if (NGX_PCRE)
|
546
|
3525 clcf->gzip_disable = NGX_CONF_UNSET_PTR;
|
596
|
3526 #endif
|
546
|
3527 clcf->gzip_disable_msie6 = 3;
|
602
|
3528 #if (NGX_HTTP_DEGRADATION)
|
|
3529 clcf->gzip_disable_degradation = 3;
|
|
3530 #endif
|
358
|
3531 #endif
|
|
3532
|
662
|
3533 #if (NGX_HAVE_OPENAT)
|
|
3534 clcf->disable_symlinks = NGX_CONF_UNSET_UINT;
|
664
|
3535 clcf->disable_symlinks_from = NGX_CONF_UNSET_PTR;
|
662
|
3536 #endif
|
|
3537
|
546
|
3538 return clcf;
|
0
|
3539 }
|
|
3540
|
|
3541
|
138
|
3542 static ngx_str_t ngx_http_core_text_html_type = ngx_string("text/html");
|
|
3543 static ngx_str_t ngx_http_core_image_gif_type = ngx_string("image/gif");
|
|
3544 static ngx_str_t ngx_http_core_image_jpeg_type = ngx_string("image/jpeg");
|
|
3545
|
|
3546 static ngx_hash_key_t ngx_http_core_default_types[] = {
|
|
3547 { ngx_string("html"), 0, &ngx_http_core_text_html_type },
|
|
3548 { ngx_string("gif"), 0, &ngx_http_core_image_gif_type },
|
|
3549 { ngx_string("jpg"), 0, &ngx_http_core_image_jpeg_type },
|
|
3550 { ngx_null_string, 0, NULL }
|
0
|
3551 };
|
|
3552
|
|
3553
|
36
|
3554 static char *
|
138
|
3555 ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
0
|
3556 {
|
|
3557 ngx_http_core_loc_conf_t *prev = parent;
|
|
3558 ngx_http_core_loc_conf_t *conf = child;
|
|
3559
|
36
|
3560 ngx_uint_t i;
|
138
|
3561 ngx_hash_key_t *type;
|
|
3562 ngx_hash_init_t types_hash;
|
0
|
3563
|
152
|
3564 if (conf->root.data == NULL) {
|
|
3565
|
174
|
3566 conf->alias = prev->alias;
|
152
|
3567 conf->root = prev->root;
|
|
3568 conf->root_lengths = prev->root_lengths;
|
|
3569 conf->root_values = prev->root_values;
|
|
3570
|
|
3571 if (prev->root.data == NULL) {
|
570
|
3572 ngx_str_set(&conf->root, "html");
|
152
|
3573
|
454
|
3574 if (ngx_conf_full_name(cf->cycle, &conf->root, 0) != NGX_OK) {
|
152
|
3575 return NGX_CONF_ERROR;
|
|
3576 }
|
|
3577 }
|
0
|
3578 }
|
|
3579
|
126
|
3580 if (conf->post_action.data == NULL) {
|
|
3581 conf->post_action = prev->post_action;
|
|
3582 }
|
|
3583
|
212
|
3584 ngx_conf_merge_uint_value(conf->types_hash_max_size,
|
|
3585 prev->types_hash_max_size, 1024);
|
|
3586
|
|
3587 ngx_conf_merge_uint_value(conf->types_hash_bucket_size,
|
|
3588 prev->types_hash_bucket_size,
|
|
3589 ngx_cacheline_size);
|
138
|
3590
|
|
3591 conf->types_hash_bucket_size = ngx_align(conf->types_hash_bucket_size,
|
|
3592 ngx_cacheline_size);
|
|
3593
|
|
3594 /*
|
644
|
3595 * the special handling of the "types" directive in the "http" section
|
138
|
3596 * to inherit the http's conf->types_hash to all servers
|
|
3597 */
|
|
3598
|
|
3599 if (prev->types && prev->types_hash.buckets == NULL) {
|
|
3600
|
|
3601 types_hash.hash = &prev->types_hash;
|
|
3602 types_hash.key = ngx_hash_key_lc;
|
|
3603 types_hash.max_size = conf->types_hash_max_size;
|
|
3604 types_hash.bucket_size = conf->types_hash_bucket_size;
|
144
|
3605 types_hash.name = "types_hash";
|
138
|
3606 types_hash.pool = cf->pool;
|
|
3607 types_hash.temp_pool = NULL;
|
|
3608
|
|
3609 if (ngx_hash_init(&types_hash, prev->types->elts, prev->types->nelts)
|
|
3610 != NGX_OK)
|
|
3611 {
|
|
3612 return NGX_CONF_ERROR;
|
|
3613 }
|
|
3614 }
|
|
3615
|
0
|
3616 if (conf->types == NULL) {
|
138
|
3617 conf->types = prev->types;
|
|
3618 conf->types_hash = prev->types_hash;
|
|
3619 }
|
|
3620
|
|
3621 if (conf->types == NULL) {
|
644
|
3622 conf->types = ngx_array_create(cf->pool, 3, sizeof(ngx_hash_key_t));
|
138
|
3623 if (conf->types == NULL) {
|
|
3624 return NGX_CONF_ERROR;
|
|
3625 }
|
|
3626
|
|
3627 for (i = 0; ngx_http_core_default_types[i].key.len; i++) {
|
|
3628 type = ngx_array_push(conf->types);
|
|
3629 if (type == NULL) {
|
36
|
3630 return NGX_CONF_ERROR;
|
|
3631 }
|
0
|
3632
|
138
|
3633 type->key = ngx_http_core_default_types[i].key;
|
|
3634 type->key_hash =
|
|
3635 ngx_hash_key_lc(ngx_http_core_default_types[i].key.data,
|
|
3636 ngx_http_core_default_types[i].key.len);
|
|
3637 type->value = ngx_http_core_default_types[i].value;
|
|
3638 }
|
|
3639 }
|
|
3640
|
|
3641 if (conf->types_hash.buckets == NULL) {
|
|
3642
|
|
3643 types_hash.hash = &conf->types_hash;
|
|
3644 types_hash.key = ngx_hash_key_lc;
|
|
3645 types_hash.max_size = conf->types_hash_max_size;
|
|
3646 types_hash.bucket_size = conf->types_hash_bucket_size;
|
644
|
3647 types_hash.name = "types_hash";
|
138
|
3648 types_hash.pool = cf->pool;
|
|
3649 types_hash.temp_pool = NULL;
|
|
3650
|
|
3651 if (ngx_hash_init(&types_hash, conf->types->elts, conf->types->nelts)
|
|
3652 != NGX_OK)
|
|
3653 {
|
|
3654 return NGX_CONF_ERROR;
|
0
|
3655 }
|
|
3656 }
|
|
3657
|
484
|
3658 if (conf->error_log == NULL) {
|
|
3659 if (prev->error_log) {
|
|
3660 conf->error_log = prev->error_log;
|
0
|
3661 } else {
|
484
|
3662 conf->error_log = &cf->cycle->new_log;
|
0
|
3663 }
|
|
3664 }
|
|
3665
|
|
3666 if (conf->error_pages == NULL && prev->error_pages) {
|
|
3667 conf->error_pages = prev->error_pages;
|
|
3668 }
|
|
3669
|
|
3670 ngx_conf_merge_str_value(conf->default_type,
|
36
|
3671 prev->default_type, "text/plain");
|
0
|
3672
|
212
|
3673 ngx_conf_merge_off_value(conf->client_max_body_size,
|
0
|
3674 prev->client_max_body_size, 1 * 1024 * 1024);
|
|
3675 ngx_conf_merge_size_value(conf->client_body_buffer_size,
|
|
3676 prev->client_body_buffer_size,
|
|
3677 (size_t) 2 * ngx_pagesize);
|
|
3678 ngx_conf_merge_msec_value(conf->client_body_timeout,
|
|
3679 prev->client_body_timeout, 60000);
|
58
|
3680
|
648
|
3681 ngx_conf_merge_bitmask_value(conf->keepalive_disable,
|
|
3682 prev->keepalive_disable,
|
|
3683 (NGX_CONF_BITMASK_SET
|
668
|
3684 |NGX_HTTP_KEEPALIVE_DISABLE_MSIE6));
|
362
|
3685 ngx_conf_merge_uint_value(conf->satisfy, prev->satisfy,
|
|
3686 NGX_HTTP_SATISFY_ALL);
|
424
|
3687 ngx_conf_merge_uint_value(conf->if_modified_since, prev->if_modified_since,
|
444
|
3688 NGX_HTTP_IMS_EXACT);
|
636
|
3689 ngx_conf_merge_uint_value(conf->max_ranges, prev->max_ranges,
|
644
|
3690 NGX_MAX_INT32_VALUE);
|
492
|
3691 ngx_conf_merge_uint_value(conf->client_body_in_file_only,
|
644
|
3692 prev->client_body_in_file_only,
|
|
3693 NGX_HTTP_REQUEST_BODY_FILE_OFF);
|
492
|
3694 ngx_conf_merge_value(conf->client_body_in_single_buffer,
|
|
3695 prev->client_body_in_single_buffer, 0);
|
58
|
3696 ngx_conf_merge_value(conf->internal, prev->internal, 0);
|
0
|
3697 ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
|
300
|
3698 ngx_conf_merge_size_value(conf->sendfile_max_chunk,
|
|
3699 prev->sendfile_max_chunk, 0);
|
518
|
3700 #if (NGX_HAVE_FILE_AIO)
|
644
|
3701 ngx_conf_merge_value(conf->aio, prev->aio, NGX_HTTP_AIO_OFF);
|
518
|
3702 #endif
|
532
|
3703 ngx_conf_merge_size_value(conf->read_ahead, prev->read_ahead, 0);
|
390
|
3704 ngx_conf_merge_off_value(conf->directio, prev->directio,
|
644
|
3705 NGX_OPEN_FILE_DIRECTIO_OFF);
|
518
|
3706 ngx_conf_merge_off_value(conf->directio_alignment, prev->directio_alignment,
|
|
3707 512);
|
0
|
3708 ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0);
|
228
|
3709 ngx_conf_merge_value(conf->tcp_nodelay, prev->tcp_nodelay, 1);
|
58
|
3710
|
0
|
3711 ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000);
|
|
3712 ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0);
|
|
3713 ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output,
|
|
3714 1460);
|
|
3715 ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0);
|
496
|
3716 ngx_conf_merge_size_value(conf->limit_rate_after, prev->limit_rate_after,
|
|
3717 0);
|
0
|
3718 ngx_conf_merge_msec_value(conf->keepalive_timeout,
|
|
3719 prev->keepalive_timeout, 75000);
|
|
3720 ngx_conf_merge_sec_value(conf->keepalive_header,
|
|
3721 prev->keepalive_header, 0);
|
496
|
3722 ngx_conf_merge_uint_value(conf->keepalive_requests,
|
|
3723 prev->keepalive_requests, 100);
|
634
|
3724 ngx_conf_merge_uint_value(conf->lingering_close,
|
632
|
3725 prev->lingering_close, NGX_HTTP_LINGERING_ON);
|
0
|
3726 ngx_conf_merge_msec_value(conf->lingering_time,
|
|
3727 prev->lingering_time, 30000);
|
|
3728 ngx_conf_merge_msec_value(conf->lingering_timeout,
|
|
3729 prev->lingering_timeout, 5000);
|
348
|
3730 ngx_conf_merge_msec_value(conf->resolver_timeout,
|
|
3731 prev->resolver_timeout, 30000);
|
|
3732
|
|
3733 if (conf->resolver == NULL) {
|
366
|
3734
|
|
3735 if (prev->resolver == NULL) {
|
|
3736
|
|
3737 /*
|
|
3738 * create dummy resolver in http {} context
|
|
3739 * to inherit it in all servers
|
|
3740 */
|
|
3741
|
646
|
3742 prev->resolver = ngx_resolver_create(cf, NULL, 0);
|
366
|
3743 if (prev->resolver == NULL) {
|
364
|
3744 return NGX_CONF_ERROR;
|
354
|
3745 }
|
|
3746 }
|
376
|
3747
|
366
|
3748 conf->resolver = prev->resolver;
|
348
|
3749 }
|
0
|
3750
|
464
|
3751 if (ngx_conf_merge_path_value(cf, &conf->client_body_temp_path,
|
28
|
3752 prev->client_body_temp_path,
|
464
|
3753 &ngx_http_client_temp_path)
|
|
3754 != NGX_OK)
|
|
3755 {
|
|
3756 return NGX_CONF_ERROR;
|
|
3757 }
|
28
|
3758
|
0
|
3759 ngx_conf_merge_value(conf->reset_timedout_connection,
|
36
|
3760 prev->reset_timedout_connection, 0);
|
362
|
3761 ngx_conf_merge_value(conf->server_name_in_redirect,
|
592
|
3762 prev->server_name_in_redirect, 0);
|
70
|
3763 ngx_conf_merge_value(conf->port_in_redirect, prev->port_in_redirect, 1);
|
0
|
3764 ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1);
|
228
|
3765 ngx_conf_merge_value(conf->msie_refresh, prev->msie_refresh, 0);
|
76
|
3766 ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1);
|
412
|
3767 ngx_conf_merge_value(conf->log_subrequest, prev->log_subrequest, 0);
|
228
|
3768 ngx_conf_merge_value(conf->recursive_error_pages,
|
|
3769 prev->recursive_error_pages, 0);
|
342
|
3770 ngx_conf_merge_value(conf->server_tokens, prev->server_tokens, 1);
|
566
|
3771 ngx_conf_merge_value(conf->chunked_transfer_encoding,
|
|
3772 prev->chunked_transfer_encoding, 1);
|
0
|
3773
|
332
|
3774 ngx_conf_merge_ptr_value(conf->open_file_cache,
|
358
|
3775 prev->open_file_cache, NULL);
|
|
3776
|
|
3777 ngx_conf_merge_sec_value(conf->open_file_cache_valid,
|
|
3778 prev->open_file_cache_valid, 60);
|
|
3779
|
|
3780 ngx_conf_merge_uint_value(conf->open_file_cache_min_uses,
|
|
3781 prev->open_file_cache_min_uses, 1);
|
332
|
3782
|
|
3783 ngx_conf_merge_sec_value(conf->open_file_cache_errors,
|
358
|
3784 prev->open_file_cache_errors, 0);
|
332
|
3785
|
|
3786 ngx_conf_merge_sec_value(conf->open_file_cache_events,
|
358
|
3787 prev->open_file_cache_events, 0);
|
|
3788 #if (NGX_HTTP_GZIP)
|
|
3789
|
|
3790 ngx_conf_merge_value(conf->gzip_vary, prev->gzip_vary, 0);
|
|
3791 ngx_conf_merge_uint_value(conf->gzip_http_version, prev->gzip_http_version,
|
|
3792 NGX_HTTP_VERSION_11);
|
|
3793 ngx_conf_merge_bitmask_value(conf->gzip_proxied, prev->gzip_proxied,
|
|
3794 (NGX_CONF_BITMASK_SET|NGX_HTTP_GZIP_PROXIED_OFF));
|
|
3795
|
362
|
3796 #if (NGX_PCRE)
|
358
|
3797 ngx_conf_merge_ptr_value(conf->gzip_disable, prev->gzip_disable, NULL);
|
362
|
3798 #endif
|
358
|
3799
|
400
|
3800 if (conf->gzip_disable_msie6 == 3) {
|
|
3801 conf->gzip_disable_msie6 =
|
|
3802 (prev->gzip_disable_msie6 == 3) ? 0 : prev->gzip_disable_msie6;
|
|
3803 }
|
|
3804
|
602
|
3805 #if (NGX_HTTP_DEGRADATION)
|
|
3806
|
|
3807 if (conf->gzip_disable_degradation == 3) {
|
|
3808 conf->gzip_disable_degradation =
|
|
3809 (prev->gzip_disable_degradation == 3) ?
|
|
3810 0 : prev->gzip_disable_degradation;
|
|
3811 }
|
|
3812
|
|
3813 #endif
|
358
|
3814 #endif
|
0
|
3815
|
662
|
3816 #if (NGX_HAVE_OPENAT)
|
|
3817 ngx_conf_merge_uint_value(conf->disable_symlinks, prev->disable_symlinks,
|
|
3818 NGX_DISABLE_SYMLINKS_OFF);
|
664
|
3819 ngx_conf_merge_ptr_value(conf->disable_symlinks_from,
|
|
3820 prev->disable_symlinks_from, NULL);
|
662
|
3821 #endif
|
|
3822
|
0
|
3823 return NGX_CONF_OK;
|
|
3824 }
|
|
3825
|
|
3826
|
36
|
3827 static char *
|
|
3828 ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
3829 {
|
538
|
3830 ngx_http_core_srv_conf_t *cscf = conf;
|
|
3831
|
|
3832 ngx_str_t *value, size;
|
|
3833 ngx_url_t u;
|
|
3834 ngx_uint_t n;
|
|
3835 ngx_http_listen_opt_t lsopt;
|
|
3836
|
|
3837 cscf->listen = 1;
|
0
|
3838
|
72
|
3839 value = cf->args->elts;
|
126
|
3840
|
252
|
3841 ngx_memzero(&u, sizeof(ngx_url_t));
|
|
3842
|
|
3843 u.url = value[1];
|
|
3844 u.listen = 1;
|
266
|
3845 u.default_port = 80;
|
252
|
3846
|
340
|
3847 if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
|
252
|
3848 if (u.err) {
|
|
3849 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3850 "%s in \"%V\" of the \"listen\" directive",
|
|
3851 u.err, &u.url);
|
|
3852 }
|
|
3853
|
126
|
3854 return NGX_CONF_ERROR;
|
72
|
3855 }
|
|
3856
|
538
|
3857 ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t));
|
|
3858
|
558
|
3859 ngx_memcpy(&lsopt.u.sockaddr, u.sockaddr, u.socklen);
|
538
|
3860
|
|
3861 lsopt.socklen = u.socklen;
|
|
3862 lsopt.backlog = NGX_LISTEN_BACKLOG;
|
|
3863 lsopt.rcvbuf = -1;
|
|
3864 lsopt.sndbuf = -1;
|
584
|
3865 #if (NGX_HAVE_SETFIB)
|
|
3866 lsopt.setfib = -1;
|
|
3867 #endif
|
538
|
3868 lsopt.wildcard = u.wildcard;
|
|
3869
|
558
|
3870 (void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.addr,
|
448
|
3871 NGX_SOCKADDR_STRLEN, 1);
|
180
|
3872
|
538
|
3873 for (n = 2; n < cf->args->nelts; n++) {
|
|
3874
|
|
3875 if (ngx_strcmp(value[n].data, "default_server") == 0
|
|
3876 || ngx_strcmp(value[n].data, "default") == 0)
|
|
3877 {
|
|
3878 lsopt.default_server = 1;
|
|
3879 continue;
|
72
|
3880 }
|
|
3881
|
|
3882 if (ngx_strcmp(value[n].data, "bind") == 0) {
|
538
|
3883 lsopt.set = 1;
|
|
3884 lsopt.bind = 1;
|
72
|
3885 continue;
|
|
3886 }
|
|
3887
|
584
|
3888 #if (NGX_HAVE_SETFIB)
|
|
3889 if (ngx_strncmp(value[n].data, "setfib=", 7) == 0) {
|
|
3890 lsopt.setfib = ngx_atoi(value[n].data + 7, value[n].len - 7);
|
|
3891
|
586
|
3892 if (lsopt.setfib == NGX_ERROR) {
|
584
|
3893 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3894 "invalid setfib \"%V\"", &value[n]);
|
|
3895 return NGX_CONF_ERROR;
|
|
3896 }
|
|
3897
|
|
3898 continue;
|
|
3899 }
|
|
3900 #endif
|
112
|
3901 if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) {
|
538
|
3902 lsopt.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8);
|
|
3903 lsopt.set = 1;
|
|
3904 lsopt.bind = 1;
|
|
3905
|
|
3906 if (lsopt.backlog == NGX_ERROR || lsopt.backlog == 0) {
|
72
|
3907 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3908 "invalid backlog \"%V\"", &value[n]);
|
|
3909 return NGX_CONF_ERROR;
|
|
3910 }
|
|
3911
|
|
3912 continue;
|
|
3913 }
|
|
3914
|
112
|
3915 if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) {
|
|
3916 size.len = value[n].len - 7;
|
|
3917 size.data = value[n].data + 7;
|
|
3918
|
538
|
3919 lsopt.rcvbuf = ngx_parse_size(&size);
|
|
3920 lsopt.set = 1;
|
|
3921 lsopt.bind = 1;
|
|
3922
|
|
3923 if (lsopt.rcvbuf == NGX_ERROR) {
|
112
|
3924 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3925 "invalid rcvbuf \"%V\"", &value[n]);
|
|
3926 return NGX_CONF_ERROR;
|
|
3927 }
|
|
3928
|
|
3929 continue;
|
|
3930 }
|
|
3931
|
|
3932 if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) {
|
|
3933 size.len = value[n].len - 7;
|
|
3934 size.data = value[n].data + 7;
|
|
3935
|
538
|
3936 lsopt.sndbuf = ngx_parse_size(&size);
|
|
3937 lsopt.set = 1;
|
|
3938 lsopt.bind = 1;
|
|
3939
|
|
3940 if (lsopt.sndbuf == NGX_ERROR) {
|
112
|
3941 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3942 "invalid sndbuf \"%V\"", &value[n]);
|
|
3943 return NGX_CONF_ERROR;
|
|
3944 }
|
|
3945
|
|
3946 continue;
|
|
3947 }
|
|
3948
|
|
3949 if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) {
|
72
|
3950 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
|
538
|
3951 lsopt.accept_filter = (char *) &value[n].data[14];
|
|
3952 lsopt.set = 1;
|
|
3953 lsopt.bind = 1;
|
72
|
3954 #else
|
|
3955 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3956 "accept filters \"%V\" are not supported "
|
|
3957 "on this platform, ignored",
|
|
3958 &value[n]);
|
|
3959 #endif
|
|
3960 continue;
|
|
3961 }
|
|
3962
|
|
3963 if (ngx_strcmp(value[n].data, "deferred") == 0) {
|
|
3964 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
|
538
|
3965 lsopt.deferred_accept = 1;
|
|
3966 lsopt.set = 1;
|
|
3967 lsopt.bind = 1;
|
72
|
3968 #else
|
|
3969 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3970 "the deferred accept is not supported "
|
|
3971 "on this platform, ignored");
|
|
3972 #endif
|
|
3973 continue;
|
|
3974 }
|
0
|
3975
|
460
|
3976 if (ngx_strncmp(value[n].data, "ipv6only=o", 10) == 0) {
|
|
3977 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
|
|
3978 struct sockaddr *sa;
|
|
3979
|
558
|
3980 sa = &lsopt.u.sockaddr;
|
460
|
3981
|
|
3982 if (sa->sa_family == AF_INET6) {
|
|
3983
|
|
3984 if (ngx_strcmp(&value[n].data[10], "n") == 0) {
|
538
|
3985 lsopt.ipv6only = 1;
|
460
|
3986
|
|
3987 } else if (ngx_strcmp(&value[n].data[10], "ff") == 0) {
|
538
|
3988 lsopt.ipv6only = 2;
|
460
|
3989
|
|
3990 } else {
|
|
3991 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3992 "invalid ipv6only flags \"%s\"",
|
|
3993 &value[n].data[9]);
|
|
3994 return NGX_CONF_ERROR;
|
|
3995 }
|
|
3996
|
538
|
3997 lsopt.set = 1;
|
|
3998 lsopt.bind = 1;
|
460
|
3999
|
|
4000 } else {
|
|
4001 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4002 "ipv6only is not supported "
|
538
|
4003 "on addr \"%s\", ignored", lsopt.addr);
|
460
|
4004 }
|
|
4005
|
|
4006 continue;
|
|
4007 #else
|
|
4008 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
640
|
4009 "ipv6only is not supported "
|
460
|
4010 "on this platform");
|
|
4011 return NGX_CONF_ERROR;
|
|
4012 #endif
|
|
4013 }
|
|
4014
|
404
|
4015 if (ngx_strcmp(value[n].data, "ssl") == 0) {
|
|
4016 #if (NGX_HTTP_SSL)
|
538
|
4017 lsopt.ssl = 1;
|
404
|
4018 continue;
|
|
4019 #else
|
|
4020 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4021 "the \"ssl\" parameter requires "
|
|
4022 "ngx_http_ssl_module");
|
|
4023 return NGX_CONF_ERROR;
|
|
4024 #endif
|
|
4025 }
|
|
4026
|
654
|
4027 if (ngx_strncmp(value[n].data, "so_keepalive=", 13) == 0) {
|
|
4028
|
|
4029 if (ngx_strcmp(&value[n].data[13], "on") == 0) {
|
|
4030 lsopt.so_keepalive = 1;
|
|
4031
|
|
4032 } else if (ngx_strcmp(&value[n].data[13], "off") == 0) {
|
|
4033 lsopt.so_keepalive = 2;
|
|
4034
|
|
4035 } else {
|
|
4036
|
|
4037 #if (NGX_HAVE_KEEPALIVE_TUNABLE)
|
|
4038 u_char *p, *end;
|
|
4039 ngx_str_t s;
|
|
4040
|
|
4041 end = value[n].data + value[n].len;
|
|
4042 s.data = value[n].data + 13;
|
|
4043
|
|
4044 p = ngx_strlchr(s.data, end, ':');
|
|
4045 if (p == NULL) {
|
|
4046 p = end;
|
|
4047 }
|
|
4048
|
|
4049 if (p > s.data) {
|
|
4050 s.len = p - s.data;
|
|
4051
|
|
4052 lsopt.tcp_keepidle = ngx_parse_time(&s, 1);
|
662
|
4053 if (lsopt.tcp_keepidle == (time_t) NGX_ERROR) {
|
654
|
4054 goto invalid_so_keepalive;
|
|
4055 }
|
|
4056 }
|
|
4057
|
|
4058 s.data = (p < end) ? (p + 1) : end;
|
|
4059
|
|
4060 p = ngx_strlchr(s.data, end, ':');
|
|
4061 if (p == NULL) {
|
|
4062 p = end;
|
|
4063 }
|
|
4064
|
|
4065 if (p > s.data) {
|
|
4066 s.len = p - s.data;
|
|
4067
|
|
4068 lsopt.tcp_keepintvl = ngx_parse_time(&s, 1);
|
662
|
4069 if (lsopt.tcp_keepintvl == (time_t) NGX_ERROR) {
|
654
|
4070 goto invalid_so_keepalive;
|
|
4071 }
|
|
4072 }
|
|
4073
|
|
4074 s.data = (p < end) ? (p + 1) : end;
|
|
4075
|
|
4076 if (s.data < end) {
|
|
4077 s.len = end - s.data;
|
|
4078
|
|
4079 lsopt.tcp_keepcnt = ngx_atoi(s.data, s.len);
|
|
4080 if (lsopt.tcp_keepcnt == NGX_ERROR) {
|
|
4081 goto invalid_so_keepalive;
|
|
4082 }
|
|
4083 }
|
|
4084
|
666
|
4085 if (lsopt.tcp_keepidle == 0 && lsopt.tcp_keepintvl == 0
|
654
|
4086 && lsopt.tcp_keepcnt == 0)
|
|
4087 {
|
|
4088 goto invalid_so_keepalive;
|
|
4089 }
|
|
4090
|
|
4091 lsopt.so_keepalive = 1;
|
|
4092
|
|
4093 #else
|
|
4094
|
|
4095 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4096 "the \"so_keepalive\" parameter accepts "
|
|
4097 "only \"on\" or \"off\" on this platform");
|
|
4098 return NGX_CONF_ERROR;
|
|
4099
|
|
4100 #endif
|
|
4101 }
|
|
4102
|
|
4103 lsopt.set = 1;
|
|
4104 lsopt.bind = 1;
|
|
4105
|
|
4106 continue;
|
|
4107
|
|
4108 #if (NGX_HAVE_KEEPALIVE_TUNABLE)
|
|
4109 invalid_so_keepalive:
|
|
4110
|
|
4111 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4112 "invalid so_keepalive value: \"%s\"",
|
|
4113 &value[n].data[13]);
|
|
4114 return NGX_CONF_ERROR;
|
|
4115 #endif
|
|
4116 }
|
|
4117
|
0
|
4118 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
640
|
4119 "invalid parameter \"%V\"", &value[n]);
|
0
|
4120 return NGX_CONF_ERROR;
|
|
4121 }
|
|
4122
|
538
|
4123 if (ngx_http_add_listen(cf, cscf, &lsopt) == NGX_OK) {
|
|
4124 return NGX_CONF_OK;
|
|
4125 }
|
|
4126
|
|
4127 return NGX_CONF_ERROR;
|
0
|
4128 }
|
|
4129
|
|
4130
|
36
|
4131 static char *
|
|
4132 ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
4133 {
|
142
|
4134 ngx_http_core_srv_conf_t *cscf = conf;
|
|
4135
|
|
4136 u_char ch;
|
612
|
4137 ngx_str_t *value;
|
142
|
4138 ngx_uint_t i;
|
|
4139 ngx_http_server_name_t *sn;
|
0
|
4140
|
|
4141 value = cf->args->elts;
|
|
4142
|
142
|
4143 for (i = 1; i < cf->args->nelts; i++) {
|
|
4144
|
|
4145 ch = value[i].data[0];
|
|
4146
|
400
|
4147 if ((ch == '*' && (value[i].len < 3 || value[i].data[1] != '.'))
|
142
|
4148 || (ch == '.' && value[i].len < 2))
|
|
4149 {
|
|
4150 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4151 "server name \"%V\" is invalid", &value[i]);
|
|
4152 return NGX_CONF_ERROR;
|
|
4153 }
|
|
4154
|
294
|
4155 if (ngx_strchr(value[i].data, '/')) {
|
|
4156 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
640
|
4157 "server name \"%V\" has suspicious symbols",
|
294
|
4158 &value[i]);
|
|
4159 }
|
|
4160
|
142
|
4161 sn = ngx_array_push(&cscf->server_names);
|
50
|
4162 if (sn == NULL) {
|
4
|
4163 return NGX_CONF_ERROR;
|
|
4164 }
|
0
|
4165
|
326
|
4166 #if (NGX_PCRE)
|
|
4167 sn->regex = NULL;
|
|
4168 #endif
|
538
|
4169 sn->server = cscf;
|
612
|
4170
|
|
4171 if (ngx_strcasecmp(value[i].data, (u_char *) "$hostname") == 0) {
|
|
4172 sn->name = cf->cycle->hostname;
|
|
4173
|
|
4174 } else {
|
|
4175 sn->name = value[i];
|
|
4176 }
|
326
|
4177
|
|
4178 if (value[i].data[0] != '~') {
|
554
|
4179 ngx_strlow(sn->name.data, sn->name.data, sn->name.len);
|
326
|
4180 continue;
|
|
4181 }
|
|
4182
|
|
4183 #if (NGX_PCRE)
|
356
|
4184 {
|
554
|
4185 u_char *p;
|
|
4186 ngx_regex_compile_t rc;
|
|
4187 u_char errstr[NGX_MAX_CONF_ERRSTR];
|
356
|
4188
|
526
|
4189 if (value[i].len == 1) {
|
|
4190 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4191 "empty regex in server name \"%V\"", &value[i]);
|
|
4192 return NGX_CONF_ERROR;
|
|
4193 }
|
|
4194
|
326
|
4195 value[i].len--;
|
|
4196 value[i].data++;
|
|
4197
|
546
|
4198 ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
|
|
4199
|
|
4200 rc.pattern = value[i];
|
|
4201 rc.err.len = NGX_MAX_CONF_ERRSTR;
|
|
4202 rc.err.data = errstr;
|
|
4203
|
554
|
4204 for (p = value[i].data; p < value[i].data + value[i].len; p++) {
|
|
4205 if (*p >= 'A' && *p <= 'Z') {
|
|
4206 rc.options = NGX_REGEX_CASELESS;
|
|
4207 break;
|
|
4208 }
|
|
4209 }
|
|
4210
|
546
|
4211 sn->regex = ngx_http_regex_compile(cf, &rc);
|
326
|
4212 if (sn->regex == NULL) {
|
|
4213 return NGX_CONF_ERROR;
|
|
4214 }
|
|
4215
|
358
|
4216 sn->name = value[i];
|
546
|
4217 cscf->captures = (rc.captures > 0);
|
356
|
4218 }
|
326
|
4219 #else
|
|
4220 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
640
|
4221 "using regex \"%V\" "
|
326
|
4222 "requires PCRE library", &value[i]);
|
|
4223
|
|
4224 return NGX_CONF_ERROR;
|
|
4225 #endif
|
0
|
4226 }
|
|
4227
|
|
4228 return NGX_CONF_OK;
|
|
4229 }
|
|
4230
|
|
4231
|
36
|
4232 static char *
|
|
4233 ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
4234 {
|
546
|
4235 ngx_http_core_loc_conf_t *clcf = conf;
|
0
|
4236
|
144
|
4237 ngx_str_t *value;
|
574
|
4238 ngx_int_t alias;
|
|
4239 ngx_uint_t n;
|
144
|
4240 ngx_http_script_compile_t sc;
|
0
|
4241
|
|
4242 alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0;
|
|
4243
|
546
|
4244 if (clcf->root.data) {
|
0
|
4245
|
574
|
4246 if ((clcf->alias != 0) == alias) {
|
0
|
4247 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
4248 "\"%V\" directive is duplicate",
|
|
4249 &cmd->name);
|
0
|
4250 } else {
|
|
4251 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
4252 "\"%V\" directive is duplicate, "
|
640
|
4253 "\"%s\" directive was specified earlier",
|
546
|
4254 &cmd->name, clcf->alias ? "alias" : "root");
|
0
|
4255 }
|
|
4256
|
|
4257 return NGX_CONF_ERROR;
|
|
4258 }
|
|
4259
|
546
|
4260 if (clcf->named && alias) {
|
324
|
4261 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
640
|
4262 "the \"alias\" directive cannot be used "
|
|
4263 "inside the named location");
|
324
|
4264
|
|
4265 return NGX_CONF_ERROR;
|
|
4266 }
|
|
4267
|
0
|
4268 value = cf->args->elts;
|
|
4269
|
294
|
4270 if (ngx_strstr(value[1].data, "$document_root")
|
|
4271 || ngx_strstr(value[1].data, "${document_root}"))
|
|
4272 {
|
|
4273 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
640
|
4274 "the $document_root variable cannot be used "
|
294
|
4275 "in the \"%V\" directive",
|
|
4276 &cmd->name);
|
|
4277
|
|
4278 return NGX_CONF_ERROR;
|
|
4279 }
|
|
4280
|
412
|
4281 if (ngx_strstr(value[1].data, "$realpath_root")
|
|
4282 || ngx_strstr(value[1].data, "${realpath_root}"))
|
|
4283 {
|
|
4284 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
640
|
4285 "the $realpath_root variable cannot be used "
|
412
|
4286 "in the \"%V\" directive",
|
|
4287 &cmd->name);
|
|
4288
|
|
4289 return NGX_CONF_ERROR;
|
|
4290 }
|
|
4291
|
574
|
4292 clcf->alias = alias ? clcf->name.len : 0;
|
546
|
4293 clcf->root = value[1];
|
|
4294
|
|
4295 if (!alias && clcf->root.data[clcf->root.len - 1] == '/') {
|
|
4296 clcf->root.len--;
|
0
|
4297 }
|
|
4298
|
546
|
4299 if (clcf->root.data[0] != '$') {
|
|
4300 if (ngx_conf_full_name(cf->cycle, &clcf->root, 0) != NGX_OK) {
|
216
|
4301 return NGX_CONF_ERROR;
|
|
4302 }
|
152
|
4303 }
|
|
4304
|
546
|
4305 n = ngx_http_script_variables_count(&clcf->root);
|
144
|
4306
|
456
|
4307 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
596
|
4308 sc.variables = n;
|
|
4309
|
|
4310 #if (NGX_PCRE)
|
|
4311 if (alias && clcf->regex) {
|
|
4312 n = 1;
|
|
4313 }
|
|
4314 #endif
|
456
|
4315
|
|
4316 if (n) {
|
|
4317 sc.cf = cf;
|
546
|
4318 sc.source = &clcf->root;
|
|
4319 sc.lengths = &clcf->root_lengths;
|
|
4320 sc.values = &clcf->root_values;
|
456
|
4321 sc.complete_lengths = 1;
|
|
4322 sc.complete_values = 1;
|
|
4323
|
|
4324 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
4325 return NGX_CONF_ERROR;
|
|
4326 }
|
144
|
4327 }
|
|
4328
|
0
|
4329 return NGX_CONF_OK;
|
|
4330 }
|
|
4331
|
|
4332
|
180
|
4333 static ngx_http_method_name_t ngx_methods_names[] = {
|
286
|
4334 { (u_char *) "GET", (uint32_t) ~NGX_HTTP_GET },
|
|
4335 { (u_char *) "HEAD", (uint32_t) ~NGX_HTTP_HEAD },
|
|
4336 { (u_char *) "POST", (uint32_t) ~NGX_HTTP_POST },
|
|
4337 { (u_char *) "PUT", (uint32_t) ~NGX_HTTP_PUT },
|
|
4338 { (u_char *) "DELETE", (uint32_t) ~NGX_HTTP_DELETE },
|
|
4339 { (u_char *) "MKCOL", (uint32_t) ~NGX_HTTP_MKCOL },
|
|
4340 { (u_char *) "COPY", (uint32_t) ~NGX_HTTP_COPY },
|
|
4341 { (u_char *) "MOVE", (uint32_t) ~NGX_HTTP_MOVE },
|
|
4342 { (u_char *) "OPTIONS", (uint32_t) ~NGX_HTTP_OPTIONS },
|
|
4343 { (u_char *) "PROPFIND" , (uint32_t) ~NGX_HTTP_PROPFIND },
|
|
4344 { (u_char *) "PROPPATCH", (uint32_t) ~NGX_HTTP_PROPPATCH },
|
|
4345 { (u_char *) "LOCK", (uint32_t) ~NGX_HTTP_LOCK },
|
|
4346 { (u_char *) "UNLOCK", (uint32_t) ~NGX_HTTP_UNLOCK },
|
578
|
4347 { (u_char *) "PATCH", (uint32_t) ~NGX_HTTP_PATCH },
|
180
|
4348 { NULL, 0 }
|
|
4349 };
|
|
4350
|
|
4351
|
|
4352 static char *
|
|
4353 ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
4354 {
|
378
|
4355 ngx_http_core_loc_conf_t *pclcf = conf;
|
180
|
4356
|
|
4357 char *rv;
|
|
4358 void *mconf;
|
|
4359 ngx_str_t *value;
|
|
4360 ngx_uint_t i;
|
|
4361 ngx_conf_t save;
|
|
4362 ngx_http_module_t *module;
|
|
4363 ngx_http_conf_ctx_t *ctx, *pctx;
|
|
4364 ngx_http_method_name_t *name;
|
378
|
4365 ngx_http_core_loc_conf_t *clcf;
|
|
4366
|
|
4367 if (pclcf->limit_except) {
|
180
|
4368 return "duplicate";
|
|
4369 }
|
|
4370
|
378
|
4371 pclcf->limit_except = 0xffffffff;
|
180
|
4372
|
|
4373 value = cf->args->elts;
|
|
4374
|
|
4375 for (i = 1; i < cf->args->nelts; i++) {
|
|
4376 for (name = ngx_methods_names; name->name; name++) {
|
|
4377
|
|
4378 if (ngx_strcasecmp(value[i].data, name->name) == 0) {
|
378
|
4379 pclcf->limit_except &= name->method;
|
180
|
4380 goto next;
|
|
4381 }
|
|
4382 }
|
|
4383
|
|
4384 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4385 "invalid method \"%V\"", &value[i]);
|
|
4386 return NGX_CONF_ERROR;
|
|
4387
|
|
4388 next:
|
|
4389 continue;
|
|
4390 }
|
|
4391
|
378
|
4392 if (!(pclcf->limit_except & NGX_HTTP_GET)) {
|
|
4393 pclcf->limit_except &= (uint32_t) ~NGX_HTTP_HEAD;
|
180
|
4394 }
|
|
4395
|
|
4396 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
|
|
4397 if (ctx == NULL) {
|
|
4398 return NGX_CONF_ERROR;
|
|
4399 }
|
|
4400
|
|
4401 pctx = cf->ctx;
|
|
4402 ctx->main_conf = pctx->main_conf;
|
|
4403 ctx->srv_conf = pctx->srv_conf;
|
|
4404
|
|
4405 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
4406 if (ctx->loc_conf == NULL) {
|
|
4407 return NGX_CONF_ERROR;
|
|
4408 }
|
|
4409
|
|
4410 for (i = 0; ngx_modules[i]; i++) {
|
|
4411 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
|
|
4412 continue;
|
|
4413 }
|
|
4414
|
|
4415 module = ngx_modules[i]->ctx;
|
|
4416
|
|
4417 if (module->create_loc_conf) {
|
|
4418
|
|
4419 mconf = module->create_loc_conf(cf);
|
|
4420 if (mconf == NULL) {
|
|
4421 return NGX_CONF_ERROR;
|
|
4422 }
|
|
4423
|
|
4424 ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
|
|
4425 }
|
|
4426 }
|
|
4427
|
|
4428
|
378
|
4429 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
|
|
4430 pclcf->limit_except_loc_conf = ctx->loc_conf;
|
|
4431 clcf->loc_conf = ctx->loc_conf;
|
|
4432 clcf->name = pclcf->name;
|
|
4433 clcf->noname = 1;
|
592
|
4434 clcf->lmt_excpt = 1;
|
378
|
4435
|
|
4436 if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
|
180
|
4437 return NGX_CONF_ERROR;
|
|
4438 }
|
|
4439
|
|
4440 save = *cf;
|
|
4441 cf->ctx = ctx;
|
|
4442 cf->cmd_type = NGX_HTTP_LMT_CONF;
|
|
4443
|
|
4444 rv = ngx_conf_parse(cf, NULL);
|
|
4445
|
|
4446 *cf = save;
|
|
4447
|
|
4448 return rv;
|
|
4449 }
|
|
4450
|
|
4451
|
36
|
4452 static char *
|
390
|
4453 ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
4454 {
|
|
4455 ngx_http_core_loc_conf_t *clcf = conf;
|
|
4456
|
|
4457 ngx_str_t *value;
|
|
4458
|
|
4459 if (clcf->directio != NGX_CONF_UNSET) {
|
|
4460 return "is duplicate";
|
|
4461 }
|
|
4462
|
|
4463 value = cf->args->elts;
|
|
4464
|
|
4465 if (ngx_strcmp(value[1].data, "off") == 0) {
|
416
|
4466 clcf->directio = NGX_OPEN_FILE_DIRECTIO_OFF;
|
390
|
4467 return NGX_CONF_OK;
|
|
4468 }
|
|
4469
|
|
4470 clcf->directio = ngx_parse_offset(&value[1]);
|
|
4471 if (clcf->directio == (off_t) NGX_ERROR) {
|
|
4472 return "invalid value";
|
|
4473 }
|
|
4474
|
|
4475 return NGX_CONF_OK;
|
|
4476 }
|
|
4477
|
|
4478
|
|
4479 static char *
|
36
|
4480 ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
4481 {
|
546
|
4482 ngx_http_core_loc_conf_t *clcf = conf;
|
0
|
4483
|
464
|
4484 u_char *p;
|
|
4485 ngx_int_t overwrite;
|
|
4486 ngx_str_t *value, uri, args;
|
|
4487 ngx_uint_t i, n;
|
|
4488 ngx_http_err_page_t *err;
|
|
4489 ngx_http_complex_value_t cv;
|
|
4490 ngx_http_compile_complex_value_t ccv;
|
0
|
4491
|
546
|
4492 if (clcf->error_pages == NULL) {
|
|
4493 clcf->error_pages = ngx_array_create(cf->pool, 4,
|
|
4494 sizeof(ngx_http_err_page_t));
|
|
4495 if (clcf->error_pages == NULL) {
|
0
|
4496 return NGX_CONF_ERROR;
|
|
4497 }
|
|
4498 }
|
|
4499
|
|
4500 value = cf->args->elts;
|
|
4501
|
|
4502 i = cf->args->nelts - 2;
|
|
4503
|
|
4504 if (value[i].data[0] == '=') {
|
|
4505 if (i == 1) {
|
|
4506 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
4507 "invalid value \"%V\"", &value[i]);
|
0
|
4508 return NGX_CONF_ERROR;
|
|
4509 }
|
|
4510
|
104
|
4511 if (value[i].len > 1) {
|
|
4512 overwrite = ngx_atoi(&value[i].data[1], value[i].len - 1);
|
|
4513
|
|
4514 if (overwrite == NGX_ERROR) {
|
|
4515 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4516 "invalid value \"%V\"", &value[i]);
|
|
4517 return NGX_CONF_ERROR;
|
|
4518 }
|
|
4519
|
|
4520 } else {
|
|
4521 overwrite = 0;
|
0
|
4522 }
|
|
4523
|
|
4524 n = 2;
|
|
4525
|
|
4526 } else {
|
104
|
4527 overwrite = -1;
|
0
|
4528 n = 1;
|
|
4529 }
|
|
4530
|
222
|
4531 uri = value[cf->args->nelts - 1];
|
464
|
4532
|
|
4533 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
|
|
4534
|
|
4535 ccv.cf = cf;
|
|
4536 ccv.value = &uri;
|
|
4537 ccv.complex_value = &cv;
|
|
4538
|
|
4539 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
|
|
4540 return NGX_CONF_ERROR;
|
|
4541 }
|
|
4542
|
570
|
4543 ngx_str_null(&args);
|
464
|
4544
|
478
|
4545 if (cv.lengths == NULL && uri.data[0] == '/') {
|
464
|
4546 p = (u_char *) ngx_strchr(uri.data, '?');
|
|
4547
|
|
4548 if (p) {
|
|
4549 cv.value.len = p - uri.data;
|
|
4550 cv.value.data = uri.data;
|
|
4551 p++;
|
|
4552 args.len = (uri.data + uri.len) - p;
|
|
4553 args.data = p;
|
222
|
4554 }
|
|
4555 }
|
|
4556
|
0
|
4557 for (i = 1; i < cf->args->nelts - n; i++) {
|
546
|
4558 err = ngx_array_push(clcf->error_pages);
|
50
|
4559 if (err == NULL) {
|
0
|
4560 return NGX_CONF_ERROR;
|
|
4561 }
|
|
4562
|
|
4563 err->status = ngx_atoi(value[i].data, value[i].len);
|
36
|
4564
|
236
|
4565 if (err->status == NGX_ERROR || err->status == 499) {
|
0
|
4566 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
4567 "invalid value \"%V\"", &value[i]);
|
0
|
4568 return NGX_CONF_ERROR;
|
|
4569 }
|
|
4570
|
558
|
4571 if (err->status < 300 || err->status > 599) {
|
0
|
4572 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
558
|
4573 "value \"%V\" must be between 300 and 599",
|
10
|
4574 &value[i]);
|
0
|
4575 return NGX_CONF_ERROR;
|
|
4576 }
|
|
4577
|
602
|
4578 err->overwrite = overwrite;
|
|
4579
|
|
4580 if (overwrite == -1) {
|
366
|
4581 switch (err->status) {
|
|
4582 case NGX_HTTP_TO_HTTPS:
|
|
4583 case NGX_HTTPS_CERT_ERROR:
|
|
4584 case NGX_HTTPS_NO_CERT:
|
|
4585 err->overwrite = NGX_HTTP_BAD_REQUEST;
|
|
4586 default:
|
|
4587 break;
|
|
4588 }
|
|
4589 }
|
104
|
4590
|
464
|
4591 err->value = cv;
|
|
4592 err->args = args;
|
0
|
4593 }
|
|
4594
|
|
4595 return NGX_CONF_OK;
|
|
4596 }
|
|
4597
|
|
4598
|
36
|
4599 static char *
|
430
|
4600 ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
4601 {
|
|
4602 ngx_http_core_loc_conf_t *clcf = conf;
|
|
4603
|
|
4604 ngx_str_t *value;
|
478
|
4605 ngx_int_t code;
|
430
|
4606 ngx_uint_t i, n;
|
|
4607 ngx_http_try_file_t *tf;
|
|
4608 ngx_http_script_compile_t sc;
|
|
4609 ngx_http_core_main_conf_t *cmcf;
|
|
4610
|
|
4611 if (clcf->try_files) {
|
|
4612 return "is duplicate";
|
|
4613 }
|
|
4614
|
|
4615 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
|
|
4616
|
|
4617 cmcf->try_files = 1;
|
|
4618
|
|
4619 tf = ngx_pcalloc(cf->pool, cf->args->nelts * sizeof(ngx_http_try_file_t));
|
|
4620 if (tf == NULL) {
|
|
4621 return NGX_CONF_ERROR;
|
|
4622 }
|
|
4623
|
|
4624 clcf->try_files = tf;
|
|
4625
|
|
4626 value = cf->args->elts;
|
|
4627
|
|
4628 for (i = 0; i < cf->args->nelts - 1; i++) {
|
|
4629
|
|
4630 tf[i].name = value[i + 1];
|
|
4631
|
440
|
4632 if (tf[i].name.data[tf[i].name.len - 1] == '/') {
|
|
4633 tf[i].test_dir = 1;
|
|
4634 tf[i].name.len--;
|
464
|
4635 tf[i].name.data[tf[i].name.len] = '\0';
|
440
|
4636 }
|
|
4637
|
430
|
4638 n = ngx_http_script_variables_count(&tf[i].name);
|
|
4639
|
|
4640 if (n) {
|
|
4641 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
4642
|
|
4643 sc.cf = cf;
|
|
4644 sc.source = &tf[i].name;
|
|
4645 sc.lengths = &tf[i].lengths;
|
|
4646 sc.values = &tf[i].values;
|
|
4647 sc.variables = n;
|
|
4648 sc.complete_lengths = 1;
|
|
4649 sc.complete_values = 1;
|
|
4650
|
|
4651 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
4652 return NGX_CONF_ERROR;
|
|
4653 }
|
|
4654
|
|
4655 } else {
|
|
4656 /* add trailing '\0' to length */
|
|
4657 tf[i].name.len++;
|
|
4658 }
|
|
4659 }
|
|
4660
|
478
|
4661 if (tf[i - 1].name.data[0] == '=') {
|
|
4662
|
|
4663 code = ngx_atoi(tf[i - 1].name.data + 1, tf[i - 1].name.len - 2);
|
|
4664
|
|
4665 if (code == NGX_ERROR) {
|
|
4666 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4667 "invalid code \"%*s\"",
|
|
4668 tf[i - 1].name.len - 1, tf[i - 1].name.data);
|
|
4669 return NGX_CONF_ERROR;
|
|
4670 }
|
|
4671
|
|
4672 tf[i].code = code;
|
|
4673 }
|
|
4674
|
430
|
4675 return NGX_CONF_OK;
|
|
4676 }
|
|
4677
|
|
4678
|
|
4679 static char *
|
332
|
4680 ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
4681 {
|
546
|
4682 ngx_http_core_loc_conf_t *clcf = conf;
|
332
|
4683
|
|
4684 time_t inactive;
|
|
4685 ngx_str_t *value, s;
|
|
4686 ngx_int_t max;
|
|
4687 ngx_uint_t i;
|
|
4688
|
546
|
4689 if (clcf->open_file_cache != NGX_CONF_UNSET_PTR) {
|
332
|
4690 return "is duplicate";
|
|
4691 }
|
|
4692
|
|
4693 value = cf->args->elts;
|
|
4694
|
|
4695 max = 0;
|
|
4696 inactive = 60;
|
|
4697
|
|
4698 for (i = 1; i < cf->args->nelts; i++) {
|
|
4699
|
|
4700 if (ngx_strncmp(value[i].data, "max=", 4) == 0) {
|
|
4701
|
|
4702 max = ngx_atoi(value[i].data + 4, value[i].len - 4);
|
648
|
4703 if (max <= 0) {
|
388
|
4704 goto failed;
|
332
|
4705 }
|
|
4706
|
|
4707 continue;
|
|
4708 }
|
|
4709
|
|
4710 if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) {
|
|
4711
|
|
4712 s.len = value[i].len - 9;
|
|
4713 s.data = value[i].data + 9;
|
|
4714
|
|
4715 inactive = ngx_parse_time(&s, 1);
|
662
|
4716 if (inactive == (time_t) NGX_ERROR) {
|
388
|
4717 goto failed;
|
332
|
4718 }
|
|
4719
|
|
4720 continue;
|
|
4721 }
|
|
4722
|
|
4723 if (ngx_strcmp(value[i].data, "off") == 0) {
|
|
4724
|
546
|
4725 clcf->open_file_cache = NULL;
|
332
|
4726
|
|
4727 continue;
|
|
4728 }
|
|
4729
|
388
|
4730 failed:
|
|
4731
|
332
|
4732 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4733 "invalid \"open_file_cache\" parameter \"%V\"",
|
|
4734 &value[i]);
|
|
4735 return NGX_CONF_ERROR;
|
|
4736 }
|
|
4737
|
546
|
4738 if (clcf->open_file_cache == NULL) {
|
332
|
4739 return NGX_CONF_OK;
|
|
4740 }
|
|
4741
|
|
4742 if (max == 0) {
|
|
4743 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
666
|
4744 "\"open_file_cache\" must have the \"max\" parameter");
|
332
|
4745 return NGX_CONF_ERROR;
|
|
4746 }
|
|
4747
|
546
|
4748 clcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive);
|
|
4749 if (clcf->open_file_cache) {
|
332
|
4750 return NGX_CONF_OK;
|
|
4751 }
|
|
4752
|
|
4753 return NGX_CONF_ERROR;
|
|
4754 }
|
|
4755
|
|
4756
|
|
4757 static char *
|
58
|
4758 ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
4759 {
|
546
|
4760 ngx_http_core_loc_conf_t *clcf = conf;
|
58
|
4761
|
668
|
4762 ngx_str_t *value, name;
|
482
|
4763
|
546
|
4764 if (clcf->error_log) {
|
484
|
4765 return "is duplicate";
|
|
4766 }
|
|
4767
|
482
|
4768 value = cf->args->elts;
|
|
4769
|
668
|
4770 if (ngx_strcmp(value[1].data, "stderr") == 0) {
|
|
4771 ngx_str_null(&name);
|
|
4772
|
|
4773 } else {
|
|
4774 name = value[1];
|
|
4775 }
|
|
4776
|
|
4777 clcf->error_log = ngx_log_create(cf->cycle, &name);
|
546
|
4778 if (clcf->error_log == NULL) {
|
58
|
4779 return NGX_CONF_ERROR;
|
|
4780 }
|
|
4781
|
484
|
4782 if (cf->args->nelts == 2) {
|
546
|
4783 clcf->error_log->log_level = NGX_LOG_ERR;
|
484
|
4784 return NGX_CONF_OK;
|
|
4785 }
|
|
4786
|
546
|
4787 return ngx_log_set_levels(cf, clcf->error_log);
|
58
|
4788 }
|
|
4789
|
|
4790
|
|
4791 static char *
|
36
|
4792 ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
4793 {
|
546
|
4794 ngx_http_core_loc_conf_t *clcf = conf;
|
0
|
4795
|
|
4796 ngx_str_t *value;
|
|
4797
|
546
|
4798 if (clcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) {
|
0
|
4799 return "is duplicate";
|
|
4800 }
|
|
4801
|
|
4802 value = cf->args->elts;
|
|
4803
|
546
|
4804 clcf->keepalive_timeout = ngx_parse_time(&value[1], 0);
|
|
4805
|
|
4806 if (clcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) {
|
0
|
4807 return "invalid value";
|
|
4808 }
|
|
4809
|
|
4810 if (cf->args->nelts == 2) {
|
|
4811 return NGX_CONF_OK;
|
|
4812 }
|
|
4813
|
546
|
4814 clcf->keepalive_header = ngx_parse_time(&value[2], 1);
|
|
4815
|
662
|
4816 if (clcf->keepalive_header == (time_t) NGX_ERROR) {
|
0
|
4817 return "invalid value";
|
|
4818 }
|
|
4819
|
|
4820 return NGX_CONF_OK;
|
|
4821 }
|
|
4822
|
|
4823
|
36
|
4824 static char *
|
58
|
4825 ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
4826 {
|
546
|
4827 ngx_http_core_loc_conf_t *clcf = conf;
|
|
4828
|
|
4829 if (clcf->internal != NGX_CONF_UNSET) {
|
58
|
4830 return "is duplicate";
|
0
|
4831 }
|
|
4832
|
546
|
4833 clcf->internal = 1;
|
58
|
4834
|
|
4835 return NGX_CONF_OK;
|
0
|
4836 }
|
|
4837
|
|
4838
|
36
|
4839 static char *
|
348
|
4840 ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
4841 {
|
|
4842 ngx_http_core_loc_conf_t *clcf = conf;
|
|
4843
|
|
4844 ngx_str_t *value;
|
|
4845
|
366
|
4846 if (clcf->resolver) {
|
|
4847 return "is duplicate";
|
|
4848 }
|
|
4849
|
348
|
4850 value = cf->args->elts;
|
|
4851
|
646
|
4852 clcf->resolver = ngx_resolver_create(cf, &value[1], cf->args->nelts - 1);
|
|
4853 if (clcf->resolver == NULL) {
|
348
|
4854 return NGX_CONF_ERROR;
|
|
4855 }
|
|
4856
|
|
4857 return NGX_CONF_OK;
|
|
4858 }
|
|
4859
|
|
4860
|
358
|
4861 #if (NGX_HTTP_GZIP)
|
|
4862
|
|
4863 static char *
|
|
4864 ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
4865 {
|
400
|
4866 ngx_http_core_loc_conf_t *clcf = conf;
|
|
4867
|
358
|
4868 #if (NGX_PCRE)
|
|
4869
|
546
|
4870 ngx_str_t *value;
|
|
4871 ngx_uint_t i;
|
|
4872 ngx_regex_elt_t *re;
|
|
4873 ngx_regex_compile_t rc;
|
|
4874 u_char errstr[NGX_MAX_CONF_ERRSTR];
|
358
|
4875
|
|
4876 if (clcf->gzip_disable == NGX_CONF_UNSET_PTR) {
|
|
4877 clcf->gzip_disable = ngx_array_create(cf->pool, 2,
|
|
4878 sizeof(ngx_regex_elt_t));
|
|
4879 if (clcf->gzip_disable == NULL) {
|
|
4880 return NGX_CONF_ERROR;
|
|
4881 }
|
|
4882 }
|
|
4883
|
|
4884 value = cf->args->elts;
|
|
4885
|
546
|
4886 ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
|
|
4887
|
|
4888 rc.pool = cf->pool;
|
|
4889 rc.err.len = NGX_MAX_CONF_ERRSTR;
|
|
4890 rc.err.data = errstr;
|
358
|
4891
|
|
4892 for (i = 1; i < cf->args->nelts; i++) {
|
|
4893
|
596
|
4894 if (ngx_strcmp(value[i].data, "msie6") == 0) {
|
400
|
4895 clcf->gzip_disable_msie6 = 1;
|
|
4896 continue;
|
|
4897 }
|
|
4898
|
602
|
4899 #if (NGX_HTTP_DEGRADATION)
|
|
4900
|
|
4901 if (ngx_strcmp(value[i].data, "degradation") == 0) {
|
|
4902 clcf->gzip_disable_degradation = 1;
|
|
4903 continue;
|
|
4904 }
|
|
4905
|
|
4906 #endif
|
|
4907
|
358
|
4908 re = ngx_array_push(clcf->gzip_disable);
|
|
4909 if (re == NULL) {
|
|
4910 return NGX_CONF_ERROR;
|
|
4911 }
|
|
4912
|
596
|
4913 rc.pattern = value[i];
|
546
|
4914 rc.options = NGX_REGEX_CASELESS;
|
|
4915
|
|
4916 if (ngx_regex_compile(&rc) != NGX_OK) {
|
|
4917 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err);
|
358
|
4918 return NGX_CONF_ERROR;
|
|
4919 }
|
|
4920
|
546
|
4921 re->regex = rc.regex;
|
358
|
4922 re->name = value[i].data;
|
|
4923 }
|
|
4924
|
|
4925 return NGX_CONF_OK;
|
|
4926
|
|
4927 #else
|
602
|
4928 ngx_str_t *value;
|
|
4929 ngx_uint_t i;
|
400
|
4930
|
|
4931 value = cf->args->elts;
|
|
4932
|
602
|
4933 for (i = 1; i < cf->args->nelts; i++) {
|
|
4934 if (ngx_strcmp(value[i].data, "msie6") == 0) {
|
|
4935 clcf->gzip_disable_msie6 = 1;
|
|
4936 continue;
|
|
4937 }
|
|
4938
|
|
4939 #if (NGX_HTTP_DEGRADATION)
|
|
4940
|
|
4941 if (ngx_strcmp(value[i].data, "degradation") == 0) {
|
|
4942 clcf->gzip_disable_degradation = 1;
|
|
4943 continue;
|
|
4944 }
|
|
4945
|
|
4946 #endif
|
|
4947
|
|
4948 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4949 "without PCRE library \"gzip_disable\" supports "
|
|
4950 "builtin \"msie6\" and \"degradation\" mask only");
|
|
4951
|
|
4952 return NGX_CONF_ERROR;
|
400
|
4953 }
|
|
4954
|
602
|
4955 return NGX_CONF_OK;
|
|
4956
|
358
|
4957 #endif
|
|
4958 }
|
|
4959
|
|
4960 #endif
|
|
4961
|
|
4962
|
664
|
4963 #if (NGX_HAVE_OPENAT)
|
|
4964
|
|
4965 static char *
|
|
4966 ngx_http_disable_symlinks(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
4967 {
|
|
4968 ngx_http_core_loc_conf_t *clcf = conf;
|
|
4969
|
|
4970 ngx_str_t *value;
|
|
4971 ngx_uint_t i;
|
|
4972 ngx_http_compile_complex_value_t ccv;
|
|
4973
|
|
4974 if (clcf->disable_symlinks != NGX_CONF_UNSET_UINT) {
|
|
4975 return "is duplicate";
|
|
4976 }
|
|
4977
|
|
4978 value = cf->args->elts;
|
|
4979
|
|
4980 for (i = 1; i < cf->args->nelts; i++) {
|
|
4981
|
|
4982 if (ngx_strcmp(value[i].data, "off") == 0) {
|
|
4983 clcf->disable_symlinks = NGX_DISABLE_SYMLINKS_OFF;
|
|
4984 continue;
|
|
4985 }
|
|
4986
|
|
4987 if (ngx_strcmp(value[i].data, "if_not_owner") == 0) {
|
|
4988 clcf->disable_symlinks = NGX_DISABLE_SYMLINKS_NOTOWNER;
|
|
4989 continue;
|
|
4990 }
|
|
4991
|
|
4992 if (ngx_strcmp(value[i].data, "on") == 0) {
|
|
4993 clcf->disable_symlinks = NGX_DISABLE_SYMLINKS_ON;
|
|
4994 continue;
|
|
4995 }
|
|
4996
|
|
4997 if (ngx_strncmp(value[i].data, "from=", 5) == 0) {
|
|
4998 value[i].len -= 5;
|
|
4999 value[i].data += 5;
|
|
5000
|
|
5001 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
|
|
5002
|
|
5003 ccv.cf = cf;
|
|
5004 ccv.value = &value[i];
|
|
5005 ccv.complex_value = ngx_palloc(cf->pool,
|
|
5006 sizeof(ngx_http_complex_value_t));
|
|
5007 if (ccv.complex_value == NULL) {
|
|
5008 return NGX_CONF_ERROR;
|
|
5009 }
|
|
5010
|
|
5011 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
|
|
5012 return NGX_CONF_ERROR;
|
|
5013 }
|
|
5014
|
|
5015 clcf->disable_symlinks_from = ccv.complex_value;
|
|
5016
|
|
5017 continue;
|
|
5018 }
|
|
5019
|
|
5020 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
5021 "invalid parameter \"%V\"", &value[i]);
|
|
5022 return NGX_CONF_ERROR;
|
|
5023 }
|
|
5024
|
|
5025 if (clcf->disable_symlinks == NGX_CONF_UNSET_UINT) {
|
|
5026 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
5027 "\"%V\" must have \"off\", \"on\" "
|
|
5028 "or \"if_not_owner\" parameter",
|
|
5029 &cmd->name);
|
|
5030 return NGX_CONF_ERROR;
|
|
5031 }
|
|
5032
|
|
5033 if (cf->args->nelts == 2) {
|
|
5034 clcf->disable_symlinks_from = NULL;
|
|
5035 return NGX_CONF_OK;
|
|
5036 }
|
|
5037
|
|
5038 if (clcf->disable_symlinks_from == NGX_CONF_UNSET_PTR) {
|
|
5039 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
5040 "duplicate parameters \"%V %V\"",
|
|
5041 &value[1], &value[2]);
|
|
5042 return NGX_CONF_ERROR;
|
|
5043 }
|
|
5044
|
|
5045 if (clcf->disable_symlinks == NGX_DISABLE_SYMLINKS_OFF) {
|
|
5046 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
5047 "\"from=\" cannot be used with \"off\" parameter");
|
|
5048 return NGX_CONF_ERROR;
|
|
5049 }
|
|
5050
|
|
5051 return NGX_CONF_OK;
|
|
5052 }
|
|
5053
|
|
5054 #endif
|
|
5055
|
|
5056
|
348
|
5057 static char *
|
36
|
5058 ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data)
|
0
|
5059 {
|
22
|
5060 #if (NGX_FREEBSD)
|
2
|
5061 ssize_t *np = data;
|
0
|
5062
|
222
|
5063 if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) {
|
0
|
5064 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
5065 "\"send_lowat\" must be less than %d "
|
|
5066 "(sysctl net.inet.tcp.sendspace)",
|
|
5067 ngx_freebsd_net_inet_tcp_sendspace);
|
|
5068
|
|
5069 return NGX_CONF_ERROR;
|
|
5070 }
|
|
5071
|
18
|
5072 #elif !(NGX_HAVE_SO_SNDLOWAT)
|
22
|
5073 ssize_t *np = data;
|
0
|
5074
|
|
5075 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
5076 "\"send_lowat\" is not supported, ignored");
|
|
5077
|
2
|
5078 *np = 0;
|
|
5079
|
0
|
5080 #endif
|
|
5081
|
|
5082 return NGX_CONF_OK;
|
|
5083 }
|
300
|
5084
|
|
5085
|
|
5086 static char *
|
|
5087 ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data)
|
|
5088 {
|
|
5089 size_t *sp = data;
|
|
5090
|
|
5091 if (*sp < NGX_MIN_POOL_SIZE) {
|
|
5092 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
558
|
5093 "the pool size must be no less than %uz",
|
|
5094 NGX_MIN_POOL_SIZE);
|
|
5095 return NGX_CONF_ERROR;
|
|
5096 }
|
|
5097
|
|
5098 if (*sp % NGX_POOL_ALIGNMENT) {
|
|
5099 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
5100 "the pool size must be a multiple of %uz",
|
|
5101 NGX_POOL_ALIGNMENT);
|
300
|
5102 return NGX_CONF_ERROR;
|
|
5103 }
|
|
5104
|
|
5105 return NGX_CONF_OK;
|
|
5106 }
|