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