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