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