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