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
|
0
|
14 #define NGX_HTTP_LOCATION_EXACT 1
|
|
15 #define NGX_HTTP_LOCATION_AUTO_REDIRECT 2
|
16
|
16 #define NGX_HTTP_LOCATION_NOREGEX 3
|
|
17 #define NGX_HTTP_LOCATION_REGEX 4
|
0
|
18
|
|
19
|
34
|
20 static void ngx_http_core_run_phases(ngx_http_request_t *r);
|
|
21 static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r,
|
36
|
22 ngx_array_t *locations, size_t len);
|
0
|
23
|
58
|
24 static ngx_int_t ngx_http_core_preconfiguration(ngx_conf_t *cf);
|
|
25 static ngx_int_t ngx_http_core_postconfiguration(ngx_conf_t *cf);
|
0
|
26 static void *ngx_http_core_create_main_conf(ngx_conf_t *cf);
|
|
27 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf);
|
|
28 static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf);
|
|
29 static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
|
36
|
30 void *parent, void *child);
|
0
|
31 static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf);
|
|
32 static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
|
36
|
33 void *parent, void *child);
|
0
|
34
|
34
|
35 static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
36 void *dummy);
|
34
|
37 static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
38 void *dummy);
|
52
|
39 static int ngx_libc_cdecl ngx_http_core_cmp_locations(const void *first,
|
|
40 const void *second);
|
34
|
41
|
|
42 static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
43 void *conf);
|
34
|
44 static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy,
|
36
|
45 void *conf);
|
0
|
46
|
34
|
47 static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
48 void *conf);
|
34
|
49 static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
50 void *conf);
|
34
|
51 static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
|
52 static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
53 void *conf);
|
34
|
54 static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
55 void *conf);
|
34
|
56 static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
57 void *conf);
|
58
|
58 static char *ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
59 void *conf);
|
0
|
60
|
34
|
61 static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data);
|
|
62
|
|
63 static ngx_conf_post_t ngx_http_core_lowat_post =
|
|
64 { ngx_http_core_lowat_check };
|
0
|
65
|
|
66
|
|
67 static ngx_conf_enum_t ngx_http_restrict_host_names[] = {
|
|
68 { ngx_string("off"), NGX_HTTP_RESTRICT_HOST_OFF },
|
|
69 { ngx_string("on"), NGX_HTTP_RESTRICT_HOST_ON },
|
|
70 { ngx_string("close"), NGX_HTTP_RESTRICT_HOST_CLOSE },
|
|
71 { ngx_null_string, 0 }
|
|
72 };
|
|
73
|
|
74
|
|
75 static ngx_command_t ngx_http_core_commands[] = {
|
|
76
|
26
|
77 { ngx_string("server_names_hash"),
|
|
78 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
|
79 ngx_conf_set_num_slot,
|
|
80 NGX_HTTP_MAIN_CONF_OFFSET,
|
|
81 offsetof(ngx_http_core_main_conf_t, server_names_hash),
|
|
82 NULL },
|
|
83
|
|
84 { ngx_string("server_names_hash_threshold"),
|
|
85 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
|
86 ngx_conf_set_num_slot,
|
|
87 NGX_HTTP_MAIN_CONF_OFFSET,
|
|
88 offsetof(ngx_http_core_main_conf_t, server_names_hash_threshold),
|
|
89 NULL },
|
|
90
|
0
|
91 { ngx_string("server"),
|
|
92 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
|
34
|
93 ngx_http_core_server,
|
0
|
94 0,
|
|
95 0,
|
|
96 NULL },
|
|
97
|
|
98 { ngx_string("connection_pool_size"),
|
|
99 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
100 ngx_conf_set_size_slot,
|
|
101 NGX_HTTP_SRV_CONF_OFFSET,
|
|
102 offsetof(ngx_http_core_srv_conf_t, connection_pool_size),
|
|
103 NULL },
|
|
104
|
|
105 { ngx_string("post_accept_timeout"),
|
|
106 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
107 ngx_conf_set_msec_slot,
|
|
108 NGX_HTTP_SRV_CONF_OFFSET,
|
|
109 offsetof(ngx_http_core_srv_conf_t, post_accept_timeout),
|
|
110 NULL },
|
|
111
|
|
112 { ngx_string("request_pool_size"),
|
|
113 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
114 ngx_conf_set_size_slot,
|
|
115 NGX_HTTP_SRV_CONF_OFFSET,
|
|
116 offsetof(ngx_http_core_srv_conf_t, request_pool_size),
|
|
117 NULL },
|
|
118
|
|
119 { ngx_string("client_header_timeout"),
|
|
120 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
121 ngx_conf_set_msec_slot,
|
|
122 NGX_HTTP_SRV_CONF_OFFSET,
|
|
123 offsetof(ngx_http_core_srv_conf_t, client_header_timeout),
|
|
124 NULL },
|
|
125
|
|
126 { ngx_string("client_header_buffer_size"),
|
|
127 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
128 ngx_conf_set_size_slot,
|
|
129 NGX_HTTP_SRV_CONF_OFFSET,
|
|
130 offsetof(ngx_http_core_srv_conf_t, client_header_buffer_size),
|
|
131 NULL },
|
|
132
|
|
133 { ngx_string("large_client_header_buffers"),
|
|
134 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE2,
|
|
135 ngx_conf_set_bufs_slot,
|
|
136 NGX_HTTP_SRV_CONF_OFFSET,
|
|
137 offsetof(ngx_http_core_srv_conf_t, large_client_header_buffers),
|
|
138 NULL },
|
|
139
|
|
140 { ngx_string("restrict_host_names"),
|
|
141 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
142 ngx_conf_set_enum_slot,
|
|
143 NGX_HTTP_SRV_CONF_OFFSET,
|
|
144 offsetof(ngx_http_core_srv_conf_t, restrict_host_names),
|
|
145 &ngx_http_restrict_host_names },
|
|
146
|
|
147 { ngx_string("location"),
|
|
148 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12,
|
34
|
149 ngx_http_core_location,
|
0
|
150 NGX_HTTP_SRV_CONF_OFFSET,
|
|
151 0,
|
|
152 NULL },
|
|
153
|
|
154 { ngx_string("listen"),
|
|
155 #if 0
|
|
156 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
157 #else
|
4
|
158 NGX_HTTP_SRV_CONF|NGX_CONF_TAKE12,
|
0
|
159 #endif
|
34
|
160 ngx_http_core_listen,
|
0
|
161 NGX_HTTP_SRV_CONF_OFFSET,
|
|
162 0,
|
|
163 NULL },
|
|
164
|
|
165 { ngx_string("server_name"),
|
|
166 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
|
34
|
167 ngx_http_core_server_name,
|
0
|
168 NGX_HTTP_SRV_CONF_OFFSET,
|
|
169 0,
|
|
170 NULL },
|
|
171
|
|
172 { ngx_string("types"),
|
|
173 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF
|
|
174 |NGX_CONF_BLOCK|NGX_CONF_NOARGS,
|
34
|
175 ngx_http_core_types,
|
0
|
176 NGX_HTTP_LOC_CONF_OFFSET,
|
|
177 0,
|
|
178 NULL },
|
|
179
|
|
180 { ngx_string("default_type"),
|
|
181 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
182 ngx_conf_set_str_slot,
|
|
183 NGX_HTTP_LOC_CONF_OFFSET,
|
|
184 offsetof(ngx_http_core_loc_conf_t, default_type),
|
|
185 NULL },
|
|
186
|
|
187 { ngx_string("root"),
|
58
|
188 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
189 |NGX_CONF_TAKE1,
|
34
|
190 ngx_http_core_root,
|
0
|
191 NGX_HTTP_LOC_CONF_OFFSET,
|
|
192 0,
|
|
193 NULL },
|
|
194
|
|
195 { ngx_string("alias"),
|
|
196 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
34
|
197 ngx_http_core_root,
|
0
|
198 NGX_HTTP_LOC_CONF_OFFSET,
|
|
199 0,
|
|
200 NULL },
|
|
201
|
|
202 { ngx_string("client_max_body_size"),
|
|
203 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
204 ngx_conf_set_size_slot,
|
|
205 NGX_HTTP_LOC_CONF_OFFSET,
|
|
206 offsetof(ngx_http_core_loc_conf_t, client_max_body_size),
|
|
207 NULL },
|
|
208
|
|
209 { ngx_string("client_body_buffer_size"),
|
|
210 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
211 ngx_conf_set_size_slot,
|
|
212 NGX_HTTP_LOC_CONF_OFFSET,
|
|
213 offsetof(ngx_http_core_loc_conf_t, client_body_buffer_size),
|
|
214 NULL },
|
|
215
|
|
216 { ngx_string("client_body_timeout"),
|
|
217 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
218 ngx_conf_set_msec_slot,
|
|
219 NGX_HTTP_LOC_CONF_OFFSET,
|
|
220 offsetof(ngx_http_core_loc_conf_t, client_body_timeout),
|
|
221 NULL },
|
|
222
|
28
|
223 { ngx_string("client_body_temp_path"),
|
|
224 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
|
|
225 ngx_conf_set_path_slot,
|
|
226 NGX_HTTP_LOC_CONF_OFFSET,
|
|
227 offsetof(ngx_http_core_loc_conf_t, client_body_temp_path),
|
|
228 (void *) ngx_garbage_collector_temp_handler },
|
|
229
|
0
|
230 { ngx_string("sendfile"),
|
|
231 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
232 ngx_conf_set_flag_slot,
|
|
233 NGX_HTTP_LOC_CONF_OFFSET,
|
|
234 offsetof(ngx_http_core_loc_conf_t, sendfile),
|
|
235 NULL },
|
|
236
|
|
237 { ngx_string("tcp_nopush"),
|
|
238 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
239 ngx_conf_set_flag_slot,
|
|
240 NGX_HTTP_LOC_CONF_OFFSET,
|
|
241 offsetof(ngx_http_core_loc_conf_t, tcp_nopush),
|
|
242 NULL },
|
|
243
|
2
|
244 { ngx_string("tcp_nodelay"),
|
|
245 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
246 ngx_conf_set_flag_slot,
|
|
247 NGX_HTTP_LOC_CONF_OFFSET,
|
|
248 offsetof(ngx_http_core_loc_conf_t, tcp_nodelay),
|
|
249 NULL },
|
|
250
|
0
|
251 { ngx_string("send_timeout"),
|
|
252 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
253 ngx_conf_set_msec_slot,
|
|
254 NGX_HTTP_LOC_CONF_OFFSET,
|
|
255 offsetof(ngx_http_core_loc_conf_t, send_timeout),
|
|
256 NULL },
|
|
257
|
|
258 { ngx_string("send_lowat"),
|
|
259 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
260 ngx_conf_set_size_slot,
|
|
261 NGX_HTTP_LOC_CONF_OFFSET,
|
|
262 offsetof(ngx_http_core_loc_conf_t, send_lowat),
|
34
|
263 &ngx_http_core_lowat_post },
|
0
|
264
|
|
265 { ngx_string("postpone_output"),
|
|
266 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
267 ngx_conf_set_size_slot,
|
|
268 NGX_HTTP_LOC_CONF_OFFSET,
|
|
269 offsetof(ngx_http_core_loc_conf_t, postpone_output),
|
|
270 NULL },
|
|
271
|
|
272 { ngx_string("limit_rate"),
|
34
|
273 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
274 |NGX_CONF_TAKE1,
|
0
|
275 ngx_conf_set_size_slot,
|
|
276 NGX_HTTP_LOC_CONF_OFFSET,
|
|
277 offsetof(ngx_http_core_loc_conf_t, limit_rate),
|
|
278 NULL },
|
|
279
|
|
280 { ngx_string("keepalive_timeout"),
|
|
281 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
|
34
|
282 ngx_http_core_keepalive,
|
0
|
283 NGX_HTTP_LOC_CONF_OFFSET,
|
|
284 0,
|
|
285 NULL },
|
|
286
|
58
|
287 { ngx_string("internal"),
|
|
288 NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
|
|
289 ngx_http_core_internal,
|
|
290 NGX_HTTP_LOC_CONF_OFFSET,
|
|
291 0,
|
|
292 NULL },
|
|
293
|
0
|
294 { ngx_string("lingering_time"),
|
|
295 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
296 ngx_conf_set_msec_slot,
|
|
297 NGX_HTTP_LOC_CONF_OFFSET,
|
|
298 offsetof(ngx_http_core_loc_conf_t, lingering_time),
|
|
299 NULL },
|
|
300
|
|
301 { ngx_string("lingering_timeout"),
|
|
302 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
303 ngx_conf_set_msec_slot,
|
|
304 NGX_HTTP_LOC_CONF_OFFSET,
|
|
305 offsetof(ngx_http_core_loc_conf_t, lingering_timeout),
|
|
306 NULL },
|
|
307
|
|
308 { ngx_string("reset_timedout_connection"),
|
|
309 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
310 ngx_conf_set_flag_slot,
|
|
311 NGX_HTTP_LOC_CONF_OFFSET,
|
|
312 offsetof(ngx_http_core_loc_conf_t, reset_timedout_connection),
|
|
313 NULL },
|
|
314
|
|
315 { ngx_string("msie_padding"),
|
|
316 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
317 ngx_conf_set_flag_slot,
|
|
318 NGX_HTTP_LOC_CONF_OFFSET,
|
|
319 offsetof(ngx_http_core_loc_conf_t, msie_padding),
|
|
320 NULL },
|
|
321
|
|
322 { ngx_string("error_page"),
|
58
|
323 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
324 |NGX_CONF_2MORE,
|
34
|
325 ngx_http_core_error_page,
|
0
|
326 NGX_HTTP_LOC_CONF_OFFSET,
|
|
327 0,
|
|
328 NULL },
|
|
329
|
|
330 { ngx_string("error_log"),
|
|
331 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
34
|
332 ngx_http_core_error_log,
|
0
|
333 NGX_HTTP_LOC_CONF_OFFSET,
|
|
334 0,
|
|
335 NULL },
|
|
336
|
|
337 #if (NGX_HTTP_CACHE)
|
|
338
|
|
339 { ngx_string("open_file_cache"),
|
|
340 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE4,
|
|
341 ngx_http_set_cache_slot,
|
|
342 NGX_HTTP_LOC_CONF_OFFSET,
|
|
343 offsetof(ngx_http_core_loc_conf_t, open_files),
|
|
344 NULL },
|
|
345
|
|
346 #endif
|
|
347
|
|
348 ngx_null_command
|
|
349 };
|
|
350
|
|
351
|
|
352 ngx_http_module_t ngx_http_core_module_ctx = {
|
58
|
353 ngx_http_core_preconfiguration, /* preconfiguration */
|
|
354 ngx_http_core_postconfiguration, /* postconfiguration */
|
0
|
355
|
|
356 ngx_http_core_create_main_conf, /* create main configuration */
|
|
357 ngx_http_core_init_main_conf, /* init main configuration */
|
|
358
|
|
359 ngx_http_core_create_srv_conf, /* create server configuration */
|
|
360 ngx_http_core_merge_srv_conf, /* merge server configuration */
|
|
361
|
|
362 ngx_http_core_create_loc_conf, /* create location configuration */
|
|
363 ngx_http_core_merge_loc_conf /* merge location configuration */
|
|
364 };
|
|
365
|
|
366
|
|
367 ngx_module_t ngx_http_core_module = {
|
58
|
368 NGX_MODULE_V1,
|
0
|
369 &ngx_http_core_module_ctx, /* module context */
|
|
370 ngx_http_core_commands, /* module directives */
|
|
371 NGX_HTTP_MODULE, /* module type */
|
58
|
372 NULL, /* init module */
|
0
|
373 NULL /* init process */
|
|
374 };
|
|
375
|
|
376
|
36
|
377 void
|
|
378 ngx_http_handler(ngx_http_request_t *r)
|
0
|
379 {
|
32
|
380 r->connection->log->action = NULL;
|
0
|
381
|
|
382 r->connection->unexpected_eof = 0;
|
|
383
|
|
384 switch (r->headers_in.connection_type) {
|
|
385 case 0:
|
|
386 if (r->http_version > NGX_HTTP_VERSION_10) {
|
|
387 r->keepalive = 1;
|
|
388 } else {
|
|
389 r->keepalive = 0;
|
|
390 }
|
|
391 break;
|
|
392
|
|
393 case NGX_HTTP_CONNECTION_CLOSE:
|
|
394 r->keepalive = 0;
|
|
395 break;
|
|
396
|
|
397 case NGX_HTTP_CONNECTION_KEEP_ALIVE:
|
|
398 r->keepalive = 1;
|
|
399 break;
|
|
400 }
|
|
401
|
|
402 if (r->keepalive && r->headers_in.msie && r->method == NGX_HTTP_POST) {
|
|
403
|
|
404 /*
|
|
405 * MSIE may wait for some time if the response for the POST request
|
|
406 * is sent over the keepalive connection
|
|
407 */
|
|
408
|
|
409 r->keepalive = 0;
|
|
410 }
|
|
411
|
|
412 #if 0
|
|
413 /* TEST STUB */ r->http_version = NGX_HTTP_VERSION_10;
|
|
414 /* TEST STUB */ r->keepalive = 0;
|
|
415 #endif
|
|
416
|
|
417 if (r->headers_in.content_length_n > 0) {
|
|
418 r->lingering_close = 1;
|
|
419
|
|
420 } else {
|
|
421 r->lingering_close = 0;
|
|
422 }
|
|
423
|
|
424 #if 0
|
|
425 /* TEST STUB */ r->lingering_close = 1;
|
|
426 #endif
|
|
427
|
58
|
428 r->write_event_handler = ngx_http_core_run_phases;
|
0
|
429
|
54
|
430 r->valid_unparsed_uri = 1;
|
58
|
431 r->valid_location = 1;
|
34
|
432 r->uri_changed = 1;
|
58
|
433 r->uri_changes = NGX_HTTP_MAX_REWRITE_CYCLES + 1;
|
54
|
434
|
38
|
435 r->phase = NGX_HTTP_REWRITE_PHASE;
|
|
436 r->phase_handler = 0;
|
34
|
437
|
|
438 ngx_http_core_run_phases(r);
|
0
|
439 }
|
|
440
|
|
441
|
36
|
442 static void
|
|
443 ngx_http_core_run_phases(ngx_http_request_t *r)
|
0
|
444 {
|
|
445 ngx_int_t rc;
|
|
446 ngx_http_handler_pt *h;
|
|
447 ngx_http_core_loc_conf_t *clcf;
|
|
448 ngx_http_core_main_conf_t *cmcf;
|
|
449
|
58
|
450 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
451 "http phase handler");
|
|
452
|
0
|
453 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
|
|
454
|
|
455 for (/* void */; r->phase < NGX_HTTP_LAST_PHASE; r->phase++) {
|
|
456
|
38
|
457 if (r->phase == NGX_HTTP_REWRITE_PHASE + 1 && r->uri_changed) {
|
34
|
458
|
|
459 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
460 "uri changes: %d", r->uri_changes);
|
|
461
|
|
462 /*
|
|
463 * gcc before 3.3 compiles the broken code for
|
|
464 * if (r->uri_changes-- == 0)
|
|
465 * if the r->uri_changes is defined as
|
|
466 * unsigned uri_changes:4
|
|
467 */
|
|
468
|
|
469 r->uri_changes--;
|
|
470
|
|
471 if (r->uri_changes == 0) {
|
|
472 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
473 "rewrite cycle");
|
|
474 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
475 return;
|
|
476 }
|
|
477
|
38
|
478 r->phase = NGX_HTTP_FIND_CONFIG_PHASE;
|
34
|
479 }
|
|
480
|
0
|
481 if (r->phase == NGX_HTTP_CONTENT_PHASE && r->content_handler) {
|
58
|
482 r->write_event_handler = ngx_http_request_empty_handler;
|
34
|
483 ngx_http_finalize_request(r, r->content_handler(r));
|
0
|
484 return;
|
|
485 }
|
|
486
|
|
487 h = cmcf->phases[r->phase].handlers.elts;
|
|
488 for (r->phase_handler = cmcf->phases[r->phase].handlers.nelts - 1;
|
|
489 r->phase_handler >= 0;
|
|
490 r->phase_handler--)
|
|
491 {
|
|
492 rc = h[r->phase_handler](r);
|
|
493
|
|
494 if (rc == NGX_DONE) {
|
|
495
|
|
496 /*
|
|
497 * we should never use r here because
|
|
498 * it could point to already freed data
|
|
499 */
|
|
500
|
|
501 return;
|
|
502 }
|
|
503
|
|
504 if (rc == NGX_DECLINED) {
|
|
505 continue;
|
|
506 }
|
|
507
|
|
508 if (rc >= NGX_HTTP_SPECIAL_RESPONSE || rc == NGX_ERROR) {
|
|
509 ngx_http_finalize_request(r, rc);
|
|
510 return;
|
|
511 }
|
|
512
|
|
513 if (r->phase == NGX_HTTP_CONTENT_PHASE) {
|
|
514 ngx_http_finalize_request(r, rc);
|
|
515 return;
|
|
516 }
|
|
517
|
|
518 if (rc == NGX_AGAIN) {
|
|
519 return;
|
|
520 }
|
|
521
|
|
522 if (rc == NGX_OK && cmcf->phases[r->phase].type == NGX_OK) {
|
|
523 break;
|
|
524 }
|
|
525 }
|
|
526 }
|
|
527
|
34
|
528 /* no content handler was found */
|
0
|
529
|
38
|
530 if (r->uri.data[r->uri.len - 1] == '/' && !r->zero_in_uri) {
|
0
|
531
|
|
532 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
533
|
|
534 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
34
|
535 "directory index of \"%V%V\" is forbidden",
|
|
536 &clcf->root, &r->uri);
|
0
|
537
|
|
538 ngx_http_finalize_request(r, NGX_HTTP_FORBIDDEN);
|
|
539 return;
|
|
540 }
|
|
541
|
|
542 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no handler found");
|
|
543
|
|
544 ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
|
|
545 }
|
|
546
|
|
547
|
36
|
548 ngx_int_t
|
|
549 ngx_http_find_location_config(ngx_http_request_t *r)
|
0
|
550 {
|
|
551 ngx_int_t rc;
|
|
552 ngx_http_core_loc_conf_t *clcf;
|
|
553 ngx_http_core_srv_conf_t *cscf;
|
|
554
|
38
|
555 r->content_handler = NULL;
|
|
556 r->uri_changed = 0;
|
|
557
|
0
|
558 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
|
559
|
34
|
560 rc = ngx_http_core_find_location(r, &cscf->locations, 0);
|
0
|
561
|
|
562 if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) {
|
|
563 return rc;
|
|
564 }
|
|
565
|
|
566 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
567
|
58
|
568 if (!r->internal && clcf->internal) {
|
|
569 return NGX_HTTP_NOT_FOUND;
|
|
570 }
|
|
571
|
0
|
572 r->connection->log->file = clcf->err_log->file;
|
|
573 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
|
|
574 r->connection->log->log_level = clcf->err_log->log_level;
|
|
575 }
|
|
576
|
2
|
577 if ((ngx_io.flags & NGX_IO_SENDFILE) && clcf->sendfile) {
|
|
578 r->connection->sendfile = 1;
|
0
|
579
|
|
580 } else {
|
2
|
581 r->connection->sendfile = 0;
|
0
|
582 }
|
|
583
|
32
|
584 if (r->keepalive && clcf->keepalive_timeout == 0) {
|
|
585 r->keepalive = 0;
|
|
586 }
|
|
587
|
0
|
588 if (!clcf->tcp_nopush) {
|
|
589 /* disable TCP_NOPUSH/TCP_CORK use */
|
|
590 r->connection->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;
|
|
591 }
|
|
592
|
|
593
|
|
594 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
10
|
595 "http cl:%z max:%uz",
|
|
596 r->headers_in.content_length_n, clcf->client_max_body_size);
|
0
|
597
|
|
598 if (r->headers_in.content_length_n != -1
|
|
599 && clcf->client_max_body_size
|
|
600 && clcf->client_max_body_size < (size_t) r->headers_in.content_length_n)
|
|
601 {
|
|
602 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
10
|
603 "client intented to send too large body: %z bytes",
|
0
|
604 r->headers_in.content_length_n);
|
|
605
|
|
606 return NGX_HTTP_REQUEST_ENTITY_TOO_LARGE;
|
|
607 }
|
|
608
|
|
609
|
|
610 if (rc == NGX_HTTP_LOCATION_AUTO_REDIRECT) {
|
|
611 r->headers_out.location = ngx_list_push(&r->headers_out.headers);
|
|
612 if (r->headers_out.location == NULL) {
|
|
613 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
614 }
|
|
615
|
58
|
616 /*
|
|
617 * we do not need to set the r->headers_out.location->hash and
|
|
618 * r->headers_out.location->key fields
|
|
619 */
|
|
620
|
0
|
621 r->headers_out.location->value = clcf->name;
|
|
622
|
|
623 return NGX_HTTP_MOVED_PERMANENTLY;
|
|
624 }
|
|
625
|
|
626 if (clcf->handler) {
|
|
627 r->content_handler = clcf->handler;
|
|
628 }
|
|
629
|
|
630 return NGX_OK;
|
|
631 }
|
|
632
|
|
633
|
36
|
634 static ngx_int_t
|
|
635 ngx_http_core_find_location(ngx_http_request_t *r,
|
|
636 ngx_array_t *locations, size_t len)
|
0
|
637 {
|
|
638 ngx_int_t n, rc;
|
16
|
639 ngx_uint_t i, found, noregex;
|
0
|
640 ngx_http_core_loc_conf_t *clcf, **clcfp;
|
|
641
|
|
642 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "find location");
|
|
643
|
|
644 found = 0;
|
16
|
645 noregex = 0;
|
0
|
646
|
|
647 clcfp = locations->elts;
|
|
648 for (i = 0; i < locations->nelts; i++) {
|
|
649
|
4
|
650 #if (NGX_PCRE)
|
0
|
651 if (clcfp[i]->regex) {
|
|
652 break;
|
|
653 }
|
|
654 #endif
|
|
655
|
34
|
656 if (clcfp[i]->noname) {
|
|
657 break;
|
|
658 }
|
|
659
|
0
|
660 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
10
|
661 "find location: %s\"%V\"",
|
|
662 clcfp[i]->exact_match ? "= " : "", &clcfp[i]->name);
|
0
|
663
|
|
664 if (clcfp[i]->auto_redirect
|
|
665 && r->uri.len == clcfp[i]->name.len - 1
|
|
666 && ngx_strncmp(r->uri.data, clcfp[i]->name.data,
|
|
667 clcfp[i]->name.len - 1) == 0)
|
|
668 {
|
|
669 /* the locations are lexicographically sorted */
|
|
670
|
|
671 r->loc_conf = clcfp[i]->loc_conf;
|
|
672
|
|
673 return NGX_HTTP_LOCATION_AUTO_REDIRECT;
|
|
674 }
|
|
675
|
|
676 if (r->uri.len < clcfp[i]->name.len) {
|
|
677 continue;
|
|
678 }
|
|
679
|
|
680 n = ngx_strncmp(r->uri.data, clcfp[i]->name.data, clcfp[i]->name.len);
|
|
681
|
|
682 if (n < 0) {
|
|
683 /* the locations are lexicographically sorted */
|
|
684 break;
|
|
685 }
|
|
686
|
|
687 if (n == 0) {
|
34
|
688 if (clcfp[i]->exact_match) {
|
|
689
|
|
690 if (r->uri.len == clcfp[i]->name.len) {
|
|
691 r->loc_conf = clcfp[i]->loc_conf;
|
|
692 return NGX_HTTP_LOCATION_EXACT;
|
|
693 }
|
|
694
|
|
695 continue;
|
0
|
696 }
|
|
697
|
|
698 if (len > clcfp[i]->name.len) {
|
|
699 /* the previous match is longer */
|
|
700 break;
|
|
701 }
|
|
702
|
|
703 r->loc_conf = clcfp[i]->loc_conf;
|
16
|
704 noregex = clcfp[i]->noregex;
|
0
|
705 found = 1;
|
|
706 }
|
|
707 }
|
|
708
|
|
709 if (found) {
|
|
710 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
711
|
|
712 if (clcf->locations.nelts) {
|
34
|
713 rc = ngx_http_core_find_location(r, &clcf->locations, len);
|
0
|
714
|
|
715 if (rc != NGX_OK) {
|
|
716 return rc;
|
|
717 }
|
|
718 }
|
|
719 }
|
|
720
|
4
|
721 #if (NGX_PCRE)
|
0
|
722
|
16
|
723 if (noregex) {
|
|
724 return NGX_HTTP_LOCATION_NOREGEX;
|
|
725 }
|
|
726
|
0
|
727 /* regex matches */
|
|
728
|
|
729 for (/* void */; i < locations->nelts; i++) {
|
|
730
|
|
731 if (!clcfp[i]->regex) {
|
|
732 continue;
|
|
733 }
|
|
734
|
34
|
735 if (clcfp[i]->noname) {
|
|
736 break;
|
|
737 }
|
|
738
|
0
|
739 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
10
|
740 "find location: ~ \"%V\"", &clcfp[i]->name);
|
0
|
741
|
|
742 n = ngx_regex_exec(clcfp[i]->regex, &r->uri, NULL, 0);
|
|
743
|
30
|
744 if (n == NGX_REGEX_NO_MATCHED) {
|
0
|
745 continue;
|
|
746 }
|
|
747
|
|
748 if (n < 0) {
|
|
749 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
|
750 ngx_regex_exec_n
|
10
|
751 " failed: %d on \"%V\" using \"%V\"",
|
|
752 n, &r->uri, &clcfp[i]->name);
|
0
|
753 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
754 }
|
|
755
|
|
756 /* match */
|
|
757
|
|
758 r->loc_conf = clcfp[i]->loc_conf;
|
|
759
|
|
760 return NGX_HTTP_LOCATION_REGEX;
|
|
761 }
|
|
762
|
4
|
763 #endif /* NGX_PCRE */
|
0
|
764
|
|
765 return NGX_OK;
|
|
766 }
|
|
767
|
|
768
|
36
|
769 ngx_int_t
|
|
770 ngx_http_set_content_type(ngx_http_request_t *r)
|
0
|
771 {
|
34
|
772 u_char c, *p, *exten;
|
0
|
773 uint32_t key;
|
|
774 ngx_uint_t i;
|
|
775 ngx_http_type_t *type;
|
|
776 ngx_http_core_loc_conf_t *clcf;
|
|
777
|
|
778 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
779
|
|
780 if (r->exten.len) {
|
34
|
781
|
|
782 if (!r->low_case_exten) {
|
|
783 for (i = 0; i < r->exten.len; i++) {
|
|
784 c = r->exten.data[i];
|
|
785 if (c >= 'A' && c <= 'Z') {
|
|
786 break;
|
|
787 }
|
|
788 }
|
|
789
|
|
790 if (i < r->exten.len) {
|
50
|
791 p = ngx_palloc(r->pool, r->exten.len);
|
|
792 if (p == NULL) {
|
34
|
793 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
794 }
|
|
795
|
|
796 exten = p;
|
|
797
|
|
798 for (i = 0; i < r->exten.len; i++) {
|
|
799 c = r->exten.data[i];
|
|
800 if (c >= 'A' && c <= 'Z') {
|
|
801 *p++ = (u_char) (c | 0x20);
|
|
802 } else {
|
|
803 *p++ = c;
|
|
804 }
|
|
805 }
|
|
806
|
|
807 r->exten.data = exten;
|
|
808 }
|
|
809
|
|
810 r->low_case_exten = 1;
|
|
811 }
|
|
812
|
0
|
813 ngx_http_types_hash_key(key, r->exten);
|
|
814
|
|
815 type = clcf->types[key].elts;
|
|
816 for (i = 0; i < clcf->types[key].nelts; i++) {
|
|
817 if (r->exten.len != type[i].exten.len) {
|
|
818 continue;
|
|
819 }
|
|
820
|
|
821 if (ngx_memcmp(r->exten.data, type[i].exten.data, r->exten.len)
|
|
822 == 0)
|
|
823 {
|
58
|
824 r->headers_out.content_type = type[i].type;
|
0
|
825 break;
|
|
826 }
|
|
827 }
|
|
828 }
|
|
829
|
58
|
830 if (r->headers_out.content_type.len == 0) {
|
|
831 r->headers_out.content_type= clcf->default_type;
|
0
|
832 }
|
|
833
|
|
834 return NGX_OK;
|
|
835 }
|
|
836
|
|
837
|
36
|
838 ngx_int_t
|
|
839 ngx_http_send_header(ngx_http_request_t *r)
|
0
|
840 {
|
|
841 if (r->err_ctx) {
|
|
842 r->headers_out.status = r->err_status;
|
|
843 r->headers_out.status_line.len = 0;
|
|
844 }
|
|
845
|
36
|
846 return ngx_http_top_header_filter(r);
|
0
|
847 }
|
|
848
|
|
849
|
36
|
850 ngx_int_t
|
|
851 ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
0
|
852 {
|
|
853 ngx_int_t rc;
|
|
854
|
|
855 if (r->connection->write->error) {
|
|
856 return NGX_ERROR;
|
|
857 }
|
|
858
|
58
|
859 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
860 "http output filter \"%V\"", &r->uri);
|
|
861
|
0
|
862 rc = ngx_http_top_body_filter(r, in);
|
|
863
|
|
864 if (rc == NGX_ERROR) {
|
36
|
865 /* NGX_ERROR may be returned by any filter */
|
0
|
866 r->connection->write->error = 1;
|
|
867 }
|
|
868
|
|
869 return rc;
|
|
870 }
|
|
871
|
|
872
|
36
|
873 ngx_int_t
|
|
874 ngx_http_redirect(ngx_http_request_t *r, int redirect)
|
0
|
875 {
|
|
876 /* STUB */
|
|
877
|
|
878 /* log request */
|
|
879
|
|
880 ngx_http_close_request(r, 0);
|
|
881 return NGX_OK;
|
|
882 }
|
|
883
|
|
884
|
36
|
885 ngx_int_t
|
|
886 ngx_http_set_exten(ngx_http_request_t *r)
|
0
|
887 {
|
|
888 ngx_int_t i;
|
|
889
|
|
890 r->exten.len = 0;
|
|
891 r->exten.data = NULL;
|
|
892
|
|
893 for (i = r->uri.len - 1; i > 1; i--) {
|
|
894 if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {
|
|
895 r->exten.len = r->uri.len - i - 1;
|
|
896
|
|
897 if (r->exten.len > 0) {
|
50
|
898 r->exten.data = ngx_palloc(r->pool, r->exten.len + 1);
|
|
899 if (r->exten.data == NULL) {
|
0
|
900 return NGX_ERROR;
|
|
901 }
|
|
902
|
|
903 ngx_cpystrn(r->exten.data, &r->uri.data[i + 1],
|
|
904 r->exten.len + 1);
|
|
905 }
|
|
906
|
|
907 break;
|
|
908
|
|
909 } else if (r->uri.data[i] == '/') {
|
|
910 break;
|
|
911 }
|
|
912 }
|
|
913
|
34
|
914 r->low_case_exten = 0;
|
|
915
|
0
|
916 return NGX_OK;
|
|
917 }
|
|
918
|
|
919
|
36
|
920 ngx_int_t
|
58
|
921 ngx_http_subrequest(ngx_http_request_t *r,
|
|
922 ngx_str_t *uri, ngx_str_t *args)
|
|
923 {
|
|
924 ngx_http_request_t *sr;
|
|
925 ngx_http_core_srv_conf_t *cscf;
|
|
926 ngx_http_postponed_request_t *pr, *p;
|
|
927
|
|
928 sr = ngx_pcalloc(r->pool, sizeof(ngx_http_request_t));
|
|
929 if (sr == NULL) {
|
|
930 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
931 }
|
|
932
|
|
933 sr->signature = NGX_HTTP_MODULE;
|
|
934 sr->connection = r->connection;
|
|
935
|
|
936 sr->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
|
|
937 if (sr->ctx == NULL) {
|
|
938 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
939 }
|
|
940
|
|
941 if (ngx_list_init(&sr->headers_out.headers, r->pool, 20,
|
|
942 sizeof(ngx_table_elt_t)) == NGX_ERROR)
|
|
943 {
|
|
944 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
945 }
|
|
946
|
|
947 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
|
948 sr->main_conf = cscf->ctx->main_conf;
|
|
949 sr->srv_conf = cscf->ctx->srv_conf;
|
|
950 sr->loc_conf = cscf->ctx->loc_conf;
|
|
951
|
|
952 sr->pool = r->pool;
|
|
953
|
|
954 sr->headers_in = r->headers_in;
|
|
955
|
|
956 sr->start_time = ngx_time();
|
|
957 sr->headers_out.content_length_n = -1;
|
|
958 sr->headers_out.last_modified_time = -1;
|
|
959
|
|
960 sr->request_body = r->request_body;
|
|
961
|
|
962 sr->method = NGX_HTTP_GET;
|
|
963 sr->http_version = r->http_version;
|
|
964 sr->http_major = r->http_minor;
|
|
965
|
|
966 sr->request_line = r->request_line;
|
|
967 sr->uri = *uri;
|
|
968 if (args) {
|
|
969 sr->args = *args;
|
|
970 }
|
|
971 sr->unparsed_uri = r->unparsed_uri;
|
|
972 sr->method_name = r->method_name;
|
|
973 sr->http_protocol = r->http_protocol;
|
|
974
|
|
975 if (ngx_http_set_exten(sr) != NGX_OK) {
|
|
976 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
977 }
|
|
978
|
|
979 sr->main = r->main ? r->main : r;
|
|
980 sr->parent = r;
|
|
981 sr->read_event_handler = ngx_http_request_empty_handler;
|
|
982 sr->write_event_handler = ngx_http_request_empty_handler;
|
|
983
|
|
984 if (r->connection->data == r) {
|
|
985 sr->connection->data = sr;
|
|
986 }
|
|
987
|
|
988 sr->in_addr = r->in_addr;
|
|
989 sr->port = r->port;
|
|
990 sr->port_text = r->port_text;
|
|
991 sr->server_name = r->server_name;
|
|
992
|
|
993 sr->variables = r->variables;
|
|
994
|
|
995 sr->log_handler = r->log_handler;
|
|
996
|
|
997 pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t));
|
|
998 if (pr == NULL) {
|
|
999 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
1000 }
|
|
1001
|
|
1002 pr->request = sr;
|
|
1003 pr->out = NULL;
|
|
1004 pr->next = NULL;
|
|
1005
|
|
1006 if (r->postponed) {
|
|
1007 for (p = r->postponed; p->next; p = p->next) { /* void */ }
|
|
1008 p->next = pr;
|
|
1009
|
|
1010 } else {
|
|
1011 r->postponed = pr;
|
|
1012 }
|
|
1013
|
|
1014 sr->internal = 1;
|
|
1015
|
|
1016 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1017 "http subrequest \"%V\"", uri);
|
|
1018
|
|
1019 ngx_http_handler(sr);
|
|
1020
|
|
1021 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1022 "http subrequest \"%V\" done", uri);
|
|
1023
|
|
1024 return NGX_OK;
|
|
1025 }
|
|
1026
|
|
1027
|
|
1028 ngx_int_t
|
36
|
1029 ngx_http_internal_redirect(ngx_http_request_t *r,
|
|
1030 ngx_str_t *uri, ngx_str_t *args)
|
0
|
1031 {
|
36
|
1032 ngx_http_core_srv_conf_t *cscf;
|
|
1033
|
0
|
1034 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
10
|
1035 "internal redirect: \"%V\"", uri);
|
0
|
1036
|
10
|
1037 r->uri = *uri;
|
0
|
1038
|
|
1039 if (args) {
|
10
|
1040 r->args = *args;
|
58
|
1041
|
|
1042 } else {
|
|
1043 r->args.len = 0;
|
|
1044 r->args.data = NULL;
|
0
|
1045 }
|
|
1046
|
|
1047 if (ngx_http_set_exten(r) != NGX_OK) {
|
|
1048 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
1049 }
|
|
1050
|
|
1051 if (r->err_ctx) {
|
|
1052
|
36
|
1053 /* allocate the new module's contexts */
|
0
|
1054
|
|
1055 r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
|
|
1056 if (r->ctx == NULL) {
|
|
1057 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
1058 }
|
|
1059
|
|
1060 } else {
|
|
1061
|
|
1062 /* clear the modules contexts */
|
|
1063
|
|
1064 ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
|
|
1065 }
|
|
1066
|
36
|
1067 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
|
1068 r->loc_conf = cscf->ctx->loc_conf;
|
|
1069
|
58
|
1070 r->internal = 1;
|
|
1071
|
0
|
1072 ngx_http_handler(r);
|
|
1073
|
|
1074 return NGX_DONE;
|
|
1075 }
|
|
1076
|
|
1077
|
|
1078 #if 0 /* STUB: test the delay http handler */
|
|
1079
|
36
|
1080 ngx_int_t
|
|
1081 ngx_http_delay_handler(ngx_http_request_t *r)
|
0
|
1082 {
|
|
1083 static int on;
|
|
1084
|
|
1085 if (on++ == 0) {
|
|
1086 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1087 "http set delay");
|
|
1088 ngx_add_timer(r->connection->write, 10000);
|
|
1089 return NGX_AGAIN;
|
|
1090 }
|
|
1091
|
|
1092 r->connection->write->timedout = 0;
|
|
1093 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1094 "http reset delay");
|
|
1095 return NGX_DECLINED;
|
|
1096 }
|
|
1097
|
|
1098 #endif
|
|
1099
|
|
1100
|
36
|
1101 static char *
|
|
1102 ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
0
|
1103 {
|
36
|
1104 int m;
|
|
1105 char *rv;
|
|
1106 void *mconf;
|
|
1107 ngx_conf_t save;
|
|
1108 ngx_http_module_t *module;
|
|
1109 ngx_http_conf_ctx_t *ctx, *http_ctx;
|
|
1110 ngx_http_core_srv_conf_t *cscf, **cscfp;
|
|
1111 ngx_http_core_main_conf_t *cmcf;
|
|
1112
|
50
|
1113 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
|
|
1114 if (ctx == NULL) {
|
36
|
1115 return NGX_CONF_ERROR;
|
|
1116 }
|
0
|
1117
|
|
1118 http_ctx = cf->ctx;
|
|
1119 ctx->main_conf = http_ctx->main_conf;
|
|
1120
|
|
1121 /* the server{}'s srv_conf */
|
|
1122
|
36
|
1123 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
1124 if (ctx->srv_conf == NULL) {
|
|
1125 return NGX_CONF_ERROR;
|
|
1126 }
|
0
|
1127
|
|
1128 /* the server{}'s loc_conf */
|
|
1129
|
36
|
1130 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
1131 if (ctx->loc_conf == NULL) {
|
|
1132 return NGX_CONF_ERROR;
|
|
1133 }
|
0
|
1134
|
|
1135 for (m = 0; ngx_modules[m]; m++) {
|
|
1136 if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
|
|
1137 continue;
|
|
1138 }
|
|
1139
|
|
1140 module = ngx_modules[m]->ctx;
|
|
1141
|
|
1142 if (module->create_srv_conf) {
|
50
|
1143 mconf = module->create_srv_conf(cf);
|
|
1144 if (mconf == NULL) {
|
36
|
1145 return NGX_CONF_ERROR;
|
|
1146 }
|
|
1147
|
|
1148 ctx->srv_conf[ngx_modules[m]->ctx_index] = mconf;
|
0
|
1149 }
|
|
1150
|
|
1151 if (module->create_loc_conf) {
|
50
|
1152 mconf = module->create_loc_conf(cf);
|
|
1153 if (mconf == NULL) {
|
36
|
1154 return NGX_CONF_ERROR;
|
|
1155 }
|
|
1156
|
|
1157 ctx->loc_conf[ngx_modules[m]->ctx_index] = mconf;
|
0
|
1158 }
|
|
1159 }
|
|
1160
|
36
|
1161
|
|
1162 /* the server configuration context */
|
0
|
1163
|
|
1164 cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
|
|
1165 cscf->ctx = ctx;
|
|
1166
|
36
|
1167
|
0
|
1168 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
|
36
|
1169
|
50
|
1170 cscfp = ngx_array_push(&cmcf->servers);
|
|
1171 if (cscfp == NULL) {
|
36
|
1172 return NGX_CONF_ERROR;
|
|
1173 }
|
|
1174
|
0
|
1175 *cscfp = cscf;
|
|
1176
|
36
|
1177
|
0
|
1178 /* parse inside server{} */
|
|
1179
|
34
|
1180 save = *cf;
|
0
|
1181 cf->ctx = ctx;
|
|
1182 cf->cmd_type = NGX_HTTP_SRV_CONF;
|
34
|
1183
|
0
|
1184 rv = ngx_conf_parse(cf, NULL);
|
34
|
1185
|
|
1186 *cf = save;
|
0
|
1187
|
|
1188 if (rv != NGX_CONF_OK) {
|
|
1189 return rv;
|
|
1190 }
|
|
1191
|
|
1192 ngx_qsort(cscf->locations.elts, (size_t) cscf->locations.nelts,
|
34
|
1193 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations);
|
0
|
1194
|
|
1195 return rv;
|
|
1196 }
|
|
1197
|
|
1198
|
36
|
1199 static char *
|
|
1200 ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
0
|
1201 {
|
|
1202 char *rv;
|
|
1203 ngx_int_t m;
|
|
1204 ngx_str_t *value;
|
34
|
1205 ngx_conf_t save;
|
0
|
1206 ngx_http_module_t *module;
|
|
1207 ngx_http_conf_ctx_t *ctx, *pctx;
|
|
1208 ngx_http_core_srv_conf_t *cscf;
|
|
1209 ngx_http_core_loc_conf_t *clcf, *pclcf, **clcfp;
|
4
|
1210 #if (NGX_PCRE)
|
0
|
1211 ngx_str_t err;
|
|
1212 u_char errstr[NGX_MAX_CONF_ERRSTR];
|
|
1213 #endif
|
|
1214
|
50
|
1215 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
|
|
1216 if (ctx == NULL) {
|
0
|
1217 return NGX_CONF_ERROR;
|
|
1218 }
|
|
1219
|
|
1220 pctx = cf->ctx;
|
|
1221 ctx->main_conf = pctx->main_conf;
|
|
1222 ctx->srv_conf = pctx->srv_conf;
|
|
1223
|
|
1224 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
1225 if (ctx->loc_conf == NULL) {
|
|
1226 return NGX_CONF_ERROR;
|
|
1227 }
|
|
1228
|
|
1229 for (m = 0; ngx_modules[m]; m++) {
|
|
1230 if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
|
|
1231 continue;
|
|
1232 }
|
|
1233
|
|
1234 module = ngx_modules[m]->ctx;
|
|
1235
|
|
1236 if (module->create_loc_conf) {
|
|
1237 ctx->loc_conf[ngx_modules[m]->ctx_index] =
|
|
1238 module->create_loc_conf(cf);
|
|
1239 if (ctx->loc_conf[ngx_modules[m]->ctx_index] == NULL) {
|
|
1240 return NGX_CONF_ERROR;
|
|
1241 }
|
|
1242 }
|
|
1243 }
|
|
1244
|
|
1245 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
|
|
1246 clcf->loc_conf = ctx->loc_conf;
|
|
1247
|
|
1248 value = cf->args->elts;
|
|
1249
|
|
1250 if (cf->args->nelts == 3) {
|
|
1251 if (value[1].len == 1 && value[1].data[0] == '=') {
|
12
|
1252 clcf->name = value[2];
|
0
|
1253 clcf->exact_match = 1;
|
|
1254
|
16
|
1255 } else if (value[1].len == 2
|
|
1256 && value[1].data[0] == '^'
|
|
1257 && value[1].data[1] == '~')
|
|
1258 {
|
|
1259 clcf->name = value[2];
|
|
1260 clcf->noregex = 1;
|
|
1261
|
0
|
1262 } else if ((value[1].len == 1 && value[1].data[0] == '~')
|
|
1263 || (value[1].len == 2
|
|
1264 && value[1].data[0] == '~'
|
|
1265 && value[1].data[1] == '*'))
|
|
1266 {
|
4
|
1267 #if (NGX_PCRE)
|
0
|
1268 err.len = NGX_MAX_CONF_ERRSTR;
|
|
1269 err.data = errstr;
|
|
1270
|
|
1271 clcf->regex = ngx_regex_compile(&value[2],
|
|
1272 value[1].len == 2 ? NGX_REGEX_CASELESS: 0,
|
|
1273 cf->pool, &err);
|
|
1274
|
|
1275 if (clcf->regex == NULL) {
|
|
1276 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
|
|
1277 return NGX_CONF_ERROR;
|
|
1278 }
|
|
1279
|
|
1280 clcf->name = value[2];
|
|
1281 #else
|
|
1282 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
1283 "the using of the regex \"%V\" "
|
|
1284 "requires PCRE library", &value[2]);
|
0
|
1285 return NGX_CONF_ERROR;
|
|
1286 #endif
|
|
1287
|
|
1288 } else {
|
|
1289 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
1290 "invalid location modifier \"%V\"", &value[1]);
|
0
|
1291 return NGX_CONF_ERROR;
|
|
1292 }
|
|
1293
|
|
1294 } else {
|
12
|
1295 clcf->name = value[1];
|
0
|
1296 }
|
|
1297
|
|
1298 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
|
|
1299
|
|
1300 if (pclcf->name.len == 0) {
|
|
1301 cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
|
50
|
1302
|
|
1303 clcfp = ngx_array_push(&cscf->locations);
|
|
1304 if (clcfp == NULL) {
|
0
|
1305 return NGX_CONF_ERROR;
|
|
1306 }
|
|
1307
|
|
1308 } else {
|
34
|
1309 #if 0
|
0
|
1310 clcf->prev_location = pclcf;
|
34
|
1311 #endif
|
0
|
1312
|
|
1313 if (pclcf->exact_match) {
|
|
1314 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
1315 "location \"%V\" could not be inside "
|
|
1316 "the exact location \"%V\"",
|
|
1317 &clcf->name, &pclcf->name);
|
0
|
1318 return NGX_CONF_ERROR;
|
|
1319 }
|
|
1320
|
4
|
1321 #if (NGX_PCRE)
|
0
|
1322 if (clcf->regex == NULL
|
|
1323 && ngx_strncmp(clcf->name.data, pclcf->name.data, pclcf->name.len)
|
|
1324 != 0)
|
|
1325 #else
|
|
1326 if (ngx_strncmp(clcf->name.data, pclcf->name.data, pclcf->name.len)
|
|
1327 != 0)
|
|
1328 #endif
|
|
1329 {
|
|
1330 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
1331 "location \"%V\" is outside location \"%V\"",
|
|
1332 &clcf->name, &pclcf->name);
|
0
|
1333 return NGX_CONF_ERROR;
|
|
1334 }
|
|
1335
|
|
1336 if (pclcf->locations.elts == NULL) {
|
50
|
1337 if (ngx_array_init(&pclcf->locations, cf->pool, 4, sizeof(void *))
|
|
1338 != NGX_OK)
|
|
1339 {
|
|
1340 return NGX_CONF_ERROR;
|
|
1341 }
|
0
|
1342 }
|
|
1343
|
50
|
1344 clcfp = ngx_array_push(&pclcf->locations);
|
|
1345 if (clcfp == NULL) {
|
0
|
1346 return NGX_CONF_ERROR;
|
|
1347 }
|
|
1348 }
|
|
1349
|
|
1350 *clcfp = clcf;
|
|
1351
|
34
|
1352 save = *cf;
|
0
|
1353 cf->ctx = ctx;
|
|
1354 cf->cmd_type = NGX_HTTP_LOC_CONF;
|
34
|
1355
|
0
|
1356 rv = ngx_conf_parse(cf, NULL);
|
34
|
1357
|
|
1358 *cf = save;
|
|
1359
|
|
1360 if (rv != NGX_CONF_OK) {
|
|
1361 return rv;
|
|
1362 }
|
|
1363
|
|
1364 ngx_qsort(clcf->locations.elts, (size_t) clcf->locations.nelts,
|
|
1365 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations);
|
0
|
1366
|
|
1367 return rv;
|
|
1368 }
|
|
1369
|
|
1370
|
52
|
1371 static int ngx_libc_cdecl
|
36
|
1372 ngx_http_core_cmp_locations(const void *one, const void *two)
|
34
|
1373 {
|
|
1374 ngx_int_t rc;
|
|
1375 ngx_http_core_loc_conf_t *first, *second;
|
|
1376
|
|
1377 first = *(ngx_http_core_loc_conf_t **) one;
|
|
1378 second = *(ngx_http_core_loc_conf_t **) two;
|
|
1379
|
|
1380 if (first->noname && !second->noname) {
|
|
1381 /* shift no named locations to the end */
|
|
1382 return 1;
|
|
1383 }
|
|
1384
|
|
1385 if (!first->noname && second->noname) {
|
|
1386 /* shift no named locations to the end */
|
|
1387 return -1;
|
|
1388 }
|
|
1389
|
|
1390 if (first->noname || second->noname) {
|
|
1391 /* do not sort no named locations */
|
|
1392 return 0;
|
|
1393 }
|
|
1394
|
|
1395 #if (NGX_PCRE)
|
|
1396
|
|
1397 if (first->regex && !second->regex) {
|
|
1398 /* shift the regex matches to the end */
|
|
1399 return 1;
|
|
1400 }
|
|
1401
|
|
1402 if (!first->regex && second->regex) {
|
|
1403 /* shift the regex matches to the end */
|
|
1404 return -1;
|
|
1405 }
|
|
1406
|
|
1407 if (first->regex || second->regex) {
|
|
1408 /* do not sort the regex matches */
|
|
1409 return 0;
|
|
1410 }
|
|
1411
|
|
1412 #endif
|
|
1413
|
|
1414 rc = ngx_strcmp(first->name.data, second->name.data);
|
|
1415
|
|
1416 if (rc == 0 && second->exact_match) {
|
|
1417 /* an exact match must be before the same inclusive one */
|
|
1418 return 1;
|
|
1419 }
|
|
1420
|
|
1421 return (int) rc;
|
|
1422 }
|
|
1423
|
|
1424
|
36
|
1425 static char *
|
|
1426 ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
1427 {
|
|
1428 char *rv;
|
34
|
1429 ngx_conf_t save;
|
0
|
1430
|
34
|
1431 save = *cf;
|
|
1432 cf->handler = ngx_http_core_type;
|
0
|
1433 cf->handler_conf = conf;
|
34
|
1434
|
0
|
1435 rv = ngx_conf_parse(cf, NULL);
|
34
|
1436
|
|
1437 *cf = save;
|
0
|
1438
|
|
1439 return rv;
|
|
1440 }
|
|
1441
|
|
1442
|
36
|
1443 static char *
|
|
1444 ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
|
0
|
1445 {
|
|
1446 ngx_http_core_loc_conf_t *lcf = conf;
|
|
1447
|
|
1448 uint32_t key;
|
|
1449 ngx_uint_t i;
|
34
|
1450 ngx_str_t *value;
|
0
|
1451 ngx_http_type_t *type;
|
|
1452
|
|
1453 if (lcf->types == NULL) {
|
|
1454 lcf->types = ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME
|
|
1455 * sizeof(ngx_array_t));
|
|
1456 if (lcf->types == NULL) {
|
|
1457 return NGX_CONF_ERROR;
|
|
1458 }
|
|
1459
|
|
1460 for (i = 0; i < NGX_HTTP_TYPES_HASH_PRIME; i++) {
|
48
|
1461 if (ngx_array_init(&lcf->types[i], cf->pool, 4,
|
0
|
1462 sizeof(ngx_http_type_t)) == NGX_ERROR)
|
|
1463 {
|
|
1464 return NGX_CONF_ERROR;
|
|
1465 }
|
|
1466 }
|
|
1467 }
|
|
1468
|
34
|
1469 value = cf->args->elts;
|
0
|
1470
|
|
1471 for (i = 1; i < cf->args->nelts; i++) {
|
34
|
1472 ngx_http_types_hash_key(key, value[i]);
|
0
|
1473
|
50
|
1474 type = ngx_array_push(&lcf->types[key]);
|
|
1475 if (type == NULL) {
|
0
|
1476 return NGX_CONF_ERROR;
|
|
1477 }
|
|
1478
|
34
|
1479 type->exten = value[i];
|
|
1480 type->type = value[0];
|
0
|
1481 }
|
|
1482
|
|
1483 return NGX_CONF_OK;
|
|
1484 }
|
|
1485
|
|
1486
|
58
|
1487 static ngx_int_t
|
|
1488 ngx_http_core_preconfiguration(ngx_conf_t *cf)
|
|
1489 {
|
|
1490 return ngx_http_variables_add_core_vars(cf);
|
|
1491 }
|
|
1492
|
|
1493
|
|
1494 static ngx_int_t
|
|
1495 ngx_http_core_postconfiguration(ngx_conf_t *cf)
|
|
1496 {
|
|
1497 return ngx_http_variables_init_vars(cf);
|
|
1498 }
|
|
1499
|
|
1500
|
36
|
1501 static void *
|
|
1502 ngx_http_core_create_main_conf(ngx_conf_t *cf)
|
0
|
1503 {
|
34
|
1504 ngx_http_core_main_conf_t *cmcf;
|
|
1505
|
50
|
1506 cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t));
|
|
1507 if (cmcf == NULL) {
|
34
|
1508 return NGX_CONF_ERROR;
|
|
1509 }
|
0
|
1510
|
48
|
1511 if (ngx_array_init(&cmcf->servers, cf->pool, 4,
|
34
|
1512 sizeof(ngx_http_core_srv_conf_t *)) == NGX_ERROR)
|
|
1513 {
|
|
1514 return NGX_CONF_ERROR;
|
|
1515 }
|
0
|
1516
|
26
|
1517 cmcf->server_names_hash = NGX_CONF_UNSET_UINT;
|
|
1518 cmcf->server_names_hash_threshold = NGX_CONF_UNSET_UINT;
|
|
1519
|
0
|
1520 return cmcf;
|
|
1521 }
|
|
1522
|
|
1523
|
36
|
1524 static char *
|
|
1525 ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf)
|
0
|
1526 {
|
|
1527 ngx_http_core_main_conf_t *cmcf = conf;
|
|
1528
|
26
|
1529 if (cmcf->server_names_hash == NGX_CONF_UNSET_UINT) {
|
|
1530 cmcf->server_names_hash = 1009;
|
|
1531 }
|
|
1532
|
|
1533 if (cmcf->server_names_hash_threshold == NGX_CONF_UNSET_UINT) {
|
|
1534 cmcf->server_names_hash_threshold = 50;
|
|
1535 }
|
0
|
1536
|
|
1537 return NGX_CONF_OK;
|
|
1538 }
|
|
1539
|
|
1540
|
36
|
1541 static void *
|
|
1542 ngx_http_core_create_srv_conf(ngx_conf_t *cf)
|
0
|
1543 {
|
|
1544 ngx_http_core_srv_conf_t *cscf;
|
|
1545
|
50
|
1546 cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t));
|
|
1547 if (cscf == NULL) {
|
36
|
1548 return NGX_CONF_ERROR;
|
|
1549 }
|
|
1550
|
0
|
1551 /*
|
36
|
1552 * set by ngx_pcalloc():
|
28
|
1553 *
|
|
1554 * conf->client_large_buffers.num = 0;
|
|
1555 */
|
0
|
1556
|
48
|
1557 if (ngx_array_init(&cscf->locations, cf->pool, 4, sizeof(void *))
|
36
|
1558 == NGX_ERROR)
|
|
1559 {
|
|
1560 return NGX_CONF_ERROR;
|
|
1561 }
|
|
1562
|
48
|
1563 if (ngx_array_init(&cscf->listen, cf->pool, 4, sizeof(ngx_http_listen_t))
|
36
|
1564 == NGX_ERROR)
|
|
1565 {
|
|
1566 return NGX_CONF_ERROR;
|
|
1567 }
|
|
1568
|
48
|
1569 if (ngx_array_init(&cscf->server_names, cf->pool, 4,
|
36
|
1570 sizeof(ngx_http_server_name_t)) == NGX_ERROR)
|
|
1571 {
|
|
1572 return NGX_CONF_ERROR;
|
|
1573 }
|
0
|
1574
|
|
1575 cscf->connection_pool_size = NGX_CONF_UNSET_SIZE;
|
|
1576 cscf->post_accept_timeout = NGX_CONF_UNSET_MSEC;
|
|
1577 cscf->request_pool_size = NGX_CONF_UNSET_SIZE;
|
|
1578 cscf->client_header_timeout = NGX_CONF_UNSET_MSEC;
|
|
1579 cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE;
|
|
1580 cscf->restrict_host_names = NGX_CONF_UNSET_UINT;
|
|
1581
|
|
1582 return cscf;
|
|
1583 }
|
|
1584
|
|
1585
|
36
|
1586 static char *
|
|
1587 ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
0
|
1588 {
|
|
1589 ngx_http_core_srv_conf_t *prev = parent;
|
|
1590 ngx_http_core_srv_conf_t *conf = child;
|
|
1591
|
36
|
1592 ngx_http_listen_t *ls;
|
|
1593 ngx_http_server_name_t *sn;
|
0
|
1594 ngx_http_core_main_conf_t *cmcf;
|
|
1595
|
|
1596 /* TODO: it does not merge, it inits only */
|
|
1597
|
|
1598 if (conf->listen.nelts == 0) {
|
50
|
1599 ls = ngx_array_push(&conf->listen);
|
|
1600 if (ls == NULL) {
|
36
|
1601 return NGX_CONF_ERROR;
|
|
1602 }
|
|
1603
|
|
1604 ls->addr = INADDR_ANY;
|
10
|
1605 #if (NGX_WIN32)
|
36
|
1606 ls->port = 80;
|
0
|
1607 #else
|
|
1608 /* STUB: getuid() should be cached */
|
36
|
1609 ls->port = (getuid() == 0) ? 80 : 8000;
|
0
|
1610 #endif
|
36
|
1611 ls->family = AF_INET;
|
0
|
1612 }
|
|
1613
|
|
1614 if (conf->server_names.nelts == 0) {
|
50
|
1615 sn = ngx_array_push(&conf->server_names);
|
|
1616 if (sn == NULL) {
|
36
|
1617 return NGX_CONF_ERROR;
|
|
1618 }
|
|
1619
|
50
|
1620 sn->name.data = ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN);
|
|
1621 if (sn->name.data == NULL) {
|
36
|
1622 return NGX_CONF_ERROR;
|
|
1623 }
|
|
1624
|
|
1625 if (gethostname((char *) sn->name.data, NGX_MAXHOSTNAMELEN) == -1) {
|
0
|
1626 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
|
|
1627 "gethostname() failed");
|
|
1628 return NGX_CONF_ERROR;
|
|
1629 }
|
|
1630
|
36
|
1631 sn->name.len = ngx_strlen(sn->name.data);
|
|
1632 sn->core_srv_conf = conf;
|
|
1633 sn->wildcard = 0;
|
0
|
1634
|
|
1635 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
|
|
1636
|
36
|
1637 if (cmcf->max_server_name_len < sn->name.len) {
|
|
1638 cmcf->max_server_name_len = sn->name.len;
|
0
|
1639 }
|
|
1640 }
|
|
1641
|
|
1642 ngx_conf_merge_size_value(conf->connection_pool_size,
|
|
1643 prev->connection_pool_size, 256);
|
|
1644 ngx_conf_merge_msec_value(conf->post_accept_timeout,
|
|
1645 prev->post_accept_timeout, 60000);
|
|
1646 ngx_conf_merge_size_value(conf->request_pool_size,
|
|
1647 prev->request_pool_size, 4096);
|
|
1648 ngx_conf_merge_msec_value(conf->client_header_timeout,
|
|
1649 prev->client_header_timeout, 60000);
|
|
1650 ngx_conf_merge_size_value(conf->client_header_buffer_size,
|
|
1651 prev->client_header_buffer_size, 1024);
|
|
1652 ngx_conf_merge_bufs_value(conf->large_client_header_buffers,
|
|
1653 prev->large_client_header_buffers,
|
|
1654 4, ngx_pagesize);
|
|
1655
|
|
1656 if (conf->large_client_header_buffers.size < conf->connection_pool_size) {
|
|
1657 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1658 "the \"large_client_header_buffers\" size must be "
|
|
1659 "equal to or bigger than \"connection_pool_size\"");
|
|
1660 return NGX_CONF_ERROR;
|
|
1661 }
|
|
1662
|
|
1663 ngx_conf_merge_unsigned_value(conf->restrict_host_names,
|
36
|
1664 prev->restrict_host_names, 0);
|
0
|
1665
|
|
1666 return NGX_CONF_OK;
|
|
1667 }
|
|
1668
|
|
1669
|
36
|
1670 static void *
|
|
1671 ngx_http_core_create_loc_conf(ngx_conf_t *cf)
|
0
|
1672 {
|
34
|
1673 ngx_http_core_loc_conf_t *lcf;
|
0
|
1674
|
50
|
1675 lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t));
|
|
1676 if (lcf == NULL) {
|
36
|
1677 return NGX_CONF_ERROR;
|
|
1678 }
|
0
|
1679
|
28
|
1680 /*
|
|
1681 * set by ngx_pcalloc():
|
|
1682 *
|
|
1683 * lcf->root.len = 0;
|
|
1684 * lcf->root.data = NULL;
|
|
1685 * lcf->types = NULL;
|
|
1686 * lcf->default_type.len = 0;
|
|
1687 * lcf->default_type.data = NULL;
|
|
1688 * lcf->err_log = NULL;
|
|
1689 * lcf->error_pages = NULL;
|
|
1690 * lcf->client_body_path = NULL;
|
|
1691 * lcf->regex = NULL;
|
|
1692 * lcf->exact_match = 0;
|
|
1693 * lcf->auto_redirect = 0;
|
|
1694 * lcf->alias = 0;
|
|
1695 */
|
0
|
1696
|
|
1697 lcf->client_max_body_size = NGX_CONF_UNSET_SIZE;
|
|
1698 lcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE;
|
|
1699 lcf->client_body_timeout = NGX_CONF_UNSET_MSEC;
|
58
|
1700 lcf->internal = NGX_CONF_UNSET;
|
0
|
1701 lcf->sendfile = NGX_CONF_UNSET;
|
|
1702 lcf->tcp_nopush = NGX_CONF_UNSET;
|
2
|
1703 lcf->tcp_nodelay = NGX_CONF_UNSET;
|
0
|
1704 lcf->send_timeout = NGX_CONF_UNSET_MSEC;
|
|
1705 lcf->send_lowat = NGX_CONF_UNSET_SIZE;
|
|
1706 lcf->postpone_output = NGX_CONF_UNSET_SIZE;
|
|
1707 lcf->limit_rate = NGX_CONF_UNSET_SIZE;
|
|
1708 lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
|
|
1709 lcf->keepalive_header = NGX_CONF_UNSET;
|
|
1710 lcf->lingering_time = NGX_CONF_UNSET_MSEC;
|
|
1711 lcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
|
|
1712 lcf->reset_timedout_connection = NGX_CONF_UNSET;
|
|
1713 lcf->msie_padding = NGX_CONF_UNSET;
|
|
1714
|
|
1715 return lcf;
|
|
1716 }
|
|
1717
|
|
1718
|
36
|
1719 static ngx_http_type_t ngx_http_core_default_types[] = {
|
0
|
1720 { ngx_string("html"), ngx_string("text/html") },
|
|
1721 { ngx_string("gif"), ngx_string("image/gif") },
|
|
1722 { ngx_string("jpg"), ngx_string("image/jpeg") },
|
|
1723 { ngx_null_string, ngx_null_string }
|
|
1724 };
|
|
1725
|
|
1726
|
36
|
1727 static char *
|
|
1728 ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
|
0
|
1729 void *parent, void *child)
|
|
1730 {
|
|
1731 ngx_http_core_loc_conf_t *prev = parent;
|
|
1732 ngx_http_core_loc_conf_t *conf = child;
|
|
1733
|
36
|
1734 uint32_t key;
|
|
1735 ngx_uint_t i;
|
|
1736 ngx_http_type_t *type;
|
0
|
1737
|
|
1738 ngx_conf_merge_str_value(conf->root, prev->root, "html");
|
|
1739
|
|
1740 if (ngx_conf_full_name(cf->cycle, &conf->root) == NGX_ERROR) {
|
|
1741 return NGX_CONF_ERROR;
|
|
1742 }
|
|
1743
|
|
1744 if (conf->types == NULL) {
|
|
1745 if (prev->types) {
|
|
1746 conf->types = prev->types;
|
|
1747
|
|
1748 } else {
|
36
|
1749 conf->types = ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME
|
|
1750 * sizeof(ngx_array_t));
|
|
1751 if (conf->types == NULL) {
|
|
1752 return NGX_CONF_ERROR;
|
|
1753 }
|
0
|
1754
|
|
1755 for (i = 0; i < NGX_HTTP_TYPES_HASH_PRIME; i++) {
|
48
|
1756 if (ngx_array_init(&conf->types[i], cf->pool, 4,
|
36
|
1757 sizeof(ngx_http_type_t)) == NGX_ERROR)
|
|
1758 {
|
|
1759 return NGX_CONF_ERROR;
|
|
1760 }
|
0
|
1761 }
|
|
1762
|
36
|
1763 for (i = 0; ngx_http_core_default_types[i].exten.len; i++) {
|
|
1764 ngx_http_types_hash_key(key,
|
|
1765 ngx_http_core_default_types[i].exten);
|
|
1766
|
50
|
1767 type = ngx_array_push(&conf->types[key]);
|
|
1768 if (type == NULL) {
|
36
|
1769 return NGX_CONF_ERROR;
|
|
1770 }
|
|
1771
|
|
1772 *type = ngx_http_core_default_types[i];
|
0
|
1773 }
|
|
1774 }
|
|
1775 }
|
|
1776
|
|
1777 if (conf->err_log == NULL) {
|
|
1778 if (prev->err_log) {
|
|
1779 conf->err_log = prev->err_log;
|
|
1780 } else {
|
|
1781 conf->err_log = cf->cycle->new_log;
|
|
1782 }
|
|
1783 }
|
|
1784
|
|
1785 if (conf->error_pages == NULL && prev->error_pages) {
|
|
1786 conf->error_pages = prev->error_pages;
|
|
1787 }
|
|
1788
|
|
1789 ngx_conf_merge_str_value(conf->default_type,
|
36
|
1790 prev->default_type, "text/plain");
|
0
|
1791
|
|
1792 ngx_conf_merge_size_value(conf->client_max_body_size,
|
|
1793 prev->client_max_body_size, 1 * 1024 * 1024);
|
|
1794 ngx_conf_merge_size_value(conf->client_body_buffer_size,
|
|
1795 prev->client_body_buffer_size,
|
|
1796 (size_t) 2 * ngx_pagesize);
|
|
1797 ngx_conf_merge_msec_value(conf->client_body_timeout,
|
|
1798 prev->client_body_timeout, 60000);
|
58
|
1799
|
|
1800 ngx_conf_merge_value(conf->internal, prev->internal, 0);
|
0
|
1801 ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
|
|
1802 ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0);
|
2
|
1803 ngx_conf_merge_value(conf->tcp_nodelay, prev->tcp_nodelay, 0);
|
58
|
1804
|
0
|
1805 ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000);
|
|
1806 ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0);
|
|
1807 ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output,
|
|
1808 1460);
|
|
1809 ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0);
|
|
1810 ngx_conf_merge_msec_value(conf->keepalive_timeout,
|
|
1811 prev->keepalive_timeout, 75000);
|
|
1812 ngx_conf_merge_sec_value(conf->keepalive_header,
|
|
1813 prev->keepalive_header, 0);
|
|
1814 ngx_conf_merge_msec_value(conf->lingering_time,
|
|
1815 prev->lingering_time, 30000);
|
|
1816 ngx_conf_merge_msec_value(conf->lingering_timeout,
|
|
1817 prev->lingering_timeout, 5000);
|
|
1818
|
28
|
1819 ngx_conf_merge_path_value(conf->client_body_temp_path,
|
|
1820 prev->client_body_temp_path,
|
|
1821 NGX_HTTP_CLIENT_TEMP_PATH, 0, 0, 0,
|
|
1822 ngx_garbage_collector_temp_handler, cf);
|
|
1823
|
0
|
1824 ngx_conf_merge_value(conf->reset_timedout_connection,
|
36
|
1825 prev->reset_timedout_connection, 0);
|
0
|
1826 ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1);
|
|
1827
|
|
1828 if (conf->open_files == NULL) {
|
|
1829 conf->open_files = prev->open_files;
|
|
1830 }
|
|
1831
|
|
1832 return NGX_CONF_OK;
|
|
1833 }
|
|
1834
|
|
1835
|
36
|
1836 static char *
|
|
1837 ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
1838 {
|
|
1839 ngx_http_core_srv_conf_t *scf = conf;
|
|
1840
|
|
1841 u_char *addr;
|
|
1842 ngx_int_t port;
|
|
1843 ngx_uint_t p;
|
|
1844 struct hostent *h;
|
|
1845 ngx_str_t *args;
|
|
1846 ngx_http_listen_t *ls;
|
|
1847
|
|
1848 /*
|
|
1849 * TODO: check duplicate 'listen' directives,
|
|
1850 * add resolved name to server names ???
|
|
1851 */
|
|
1852
|
50
|
1853 ls = ngx_array_push(&scf->listen);
|
|
1854 if (ls == NULL) {
|
0
|
1855 return NGX_CONF_ERROR;
|
|
1856 }
|
|
1857
|
|
1858 /* AF_INET only */
|
|
1859
|
|
1860 ls->family = AF_INET;
|
|
1861 ls->default_server = 0;
|
|
1862 ls->file_name = cf->conf_file->file.name;
|
|
1863 ls->line = cf->conf_file->line;
|
|
1864
|
|
1865 args = cf->args->elts;
|
|
1866 addr = args[1].data;
|
|
1867
|
|
1868 for (p = 0; p < args[1].len; p++) {
|
|
1869 if (addr[p] == ':') {
|
|
1870 addr[p++] = '\0';
|
|
1871 break;
|
|
1872 }
|
|
1873 }
|
|
1874
|
|
1875 if (p == args[1].len) {
|
|
1876 /* no ":" in the "listen" */
|
|
1877 p = 0;
|
|
1878 }
|
|
1879
|
|
1880 port = ngx_atoi(&addr[p], args[1].len - p);
|
|
1881
|
|
1882 if (port == NGX_ERROR && p == 0) {
|
|
1883
|
|
1884 /* "listen host" */
|
|
1885 ls->port = 80;
|
|
1886
|
|
1887 } else if ((port == NGX_ERROR && p != 0) /* "listen host:NONNUMBER" */
|
|
1888 || (port < 1 || port > 65536)) { /* "listen 99999" */
|
|
1889
|
|
1890 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
1891 "invalid port \"%s\" in \"%V\" directive, "
|
0
|
1892 "it must be a number between 1 and 65535",
|
10
|
1893 &addr[p], &cmd->name);
|
0
|
1894
|
|
1895 return NGX_CONF_ERROR;
|
|
1896
|
|
1897 } else if (p == 0) {
|
|
1898 ls->addr = INADDR_ANY;
|
|
1899 ls->port = (in_port_t) port;
|
|
1900 return NGX_CONF_OK;
|
|
1901
|
|
1902 } else {
|
|
1903 ls->port = (in_port_t) port;
|
|
1904 }
|
|
1905
|
|
1906 ls->addr = inet_addr((const char *) addr);
|
36
|
1907
|
0
|
1908 if (ls->addr == INADDR_NONE) {
|
|
1909 h = gethostbyname((const char *) addr);
|
|
1910
|
|
1911 if (h == NULL || h->h_addr_list[0] == NULL) {
|
|
1912 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1913 "can not resolve host \"%s\" "
|
10
|
1914 "in \"%V\" directive", addr, &cmd->name);
|
0
|
1915 return NGX_CONF_ERROR;
|
|
1916 }
|
|
1917
|
|
1918 ls->addr = *(in_addr_t *)(h->h_addr_list[0]);
|
|
1919 }
|
|
1920
|
|
1921 return NGX_CONF_OK;
|
|
1922 }
|
|
1923
|
|
1924
|
36
|
1925 static char *
|
|
1926 ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
1927 {
|
|
1928 ngx_http_core_srv_conf_t *scf = conf;
|
|
1929
|
|
1930 ngx_uint_t i;
|
|
1931 ngx_str_t *value;
|
|
1932 ngx_http_server_name_t *sn;
|
|
1933 ngx_http_core_main_conf_t *cmcf;
|
|
1934
|
|
1935 /* TODO: warn about duplicate 'server_name' directives */
|
|
1936
|
|
1937 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
|
|
1938
|
|
1939 value = cf->args->elts;
|
|
1940
|
|
1941 for (i = 1; i < cf->args->nelts; i++) {
|
|
1942 if (value[i].len == 0) {
|
|
1943 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
1944 "server name \"%V\" is invalid "
|
|
1945 "in \"%V\" directive",
|
|
1946 &value[i], &cmd->name);
|
0
|
1947 return NGX_CONF_ERROR;
|
|
1948 }
|
|
1949
|
50
|
1950 sn = ngx_array_push(&scf->server_names);
|
|
1951 if (sn == NULL) {
|
4
|
1952 return NGX_CONF_ERROR;
|
|
1953 }
|
0
|
1954
|
|
1955 sn->name.len = value[i].len;
|
|
1956 sn->name.data = value[i].data;
|
|
1957 sn->core_srv_conf = scf;
|
|
1958
|
4
|
1959 if (sn->name.data[0] == '*') {
|
|
1960 sn->name.len--;
|
|
1961 sn->name.data++;
|
|
1962 sn->wildcard = 1;
|
|
1963
|
|
1964 } else {
|
|
1965 sn->wildcard = 0;
|
|
1966 }
|
|
1967
|
0
|
1968 if (cmcf->max_server_name_len < sn->name.len) {
|
|
1969 cmcf->max_server_name_len = sn->name.len;
|
|
1970 }
|
|
1971 }
|
|
1972
|
|
1973 return NGX_CONF_OK;
|
|
1974 }
|
|
1975
|
|
1976
|
36
|
1977 static char *
|
|
1978 ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
1979 {
|
|
1980 ngx_http_core_loc_conf_t *lcf = conf;
|
|
1981
|
|
1982 ngx_uint_t alias;
|
|
1983 ngx_str_t *value;
|
|
1984
|
|
1985 alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0;
|
|
1986
|
|
1987 if (lcf->root.data) {
|
|
1988
|
|
1989 /* the (ngx_uint_t) cast is required by gcc 2.7.2.3 */
|
|
1990
|
|
1991 if ((ngx_uint_t) lcf->alias == alias) {
|
|
1992 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
1993 "\"%V\" directive is duplicate",
|
|
1994 &cmd->name);
|
0
|
1995 } else {
|
|
1996 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
1997 "\"%V\" directive is duplicate, "
|
0
|
1998 "\"%s\" directive is specified before",
|
10
|
1999 &cmd->name, lcf->alias ? "alias" : "root");
|
0
|
2000 }
|
|
2001
|
|
2002 return NGX_CONF_ERROR;
|
|
2003 }
|
|
2004
|
|
2005 value = cf->args->elts;
|
|
2006
|
|
2007 lcf->alias = alias;
|
|
2008 lcf->root = value[1];
|
|
2009
|
|
2010 if (!alias && lcf->root.data[lcf->root.len - 1] == '/') {
|
|
2011 lcf->root.len--;
|
|
2012 }
|
|
2013
|
|
2014 return NGX_CONF_OK;
|
|
2015 }
|
|
2016
|
|
2017
|
36
|
2018 static char *
|
|
2019 ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
2020 {
|
|
2021 ngx_http_core_loc_conf_t *lcf = conf;
|
|
2022
|
36
|
2023 ngx_int_t overwrite;
|
0
|
2024 ngx_uint_t i, n;
|
|
2025 ngx_str_t *value;
|
|
2026 ngx_http_err_page_t *err;
|
|
2027
|
|
2028 if (lcf->error_pages == NULL) {
|
36
|
2029 lcf->error_pages = ngx_array_create(cf->pool, 4,
|
0
|
2030 sizeof(ngx_http_err_page_t));
|
|
2031 if (lcf->error_pages == NULL) {
|
|
2032 return NGX_CONF_ERROR;
|
|
2033 }
|
|
2034 }
|
|
2035
|
|
2036 value = cf->args->elts;
|
|
2037
|
|
2038 i = cf->args->nelts - 2;
|
|
2039
|
|
2040 if (value[i].data[0] == '=') {
|
|
2041 if (i == 1) {
|
|
2042 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
2043 "invalid value \"%V\"", &value[i]);
|
0
|
2044 return NGX_CONF_ERROR;
|
|
2045 }
|
|
2046
|
|
2047 overwrite = ngx_atoi(&value[i].data[1], value[i].len - 1);
|
|
2048
|
|
2049 if (overwrite == NGX_ERROR) {
|
|
2050 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
28
|
2051 "invalid value \"%V\"", &value[i]);
|
0
|
2052 return NGX_CONF_ERROR;
|
|
2053 }
|
|
2054
|
|
2055 n = 2;
|
|
2056
|
|
2057 } else {
|
|
2058 overwrite = 0;
|
|
2059 n = 1;
|
|
2060 }
|
|
2061
|
|
2062 for (i = 1; i < cf->args->nelts - n; i++) {
|
50
|
2063 err = ngx_array_push(lcf->error_pages);
|
|
2064 if (err == NULL) {
|
0
|
2065 return NGX_CONF_ERROR;
|
|
2066 }
|
|
2067
|
|
2068 err->status = ngx_atoi(value[i].data, value[i].len);
|
36
|
2069
|
0
|
2070 if (err->status == NGX_ERROR) {
|
|
2071 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
2072 "invalid value \"%V\"", &value[i]);
|
0
|
2073 return NGX_CONF_ERROR;
|
|
2074 }
|
|
2075
|
|
2076 if (err->status < 400 || err->status > 599) {
|
|
2077 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
2078 "value \"%V\" must be between 400 and 599",
|
|
2079 &value[i]);
|
0
|
2080 return NGX_CONF_ERROR;
|
|
2081 }
|
|
2082
|
|
2083 err->overwrite = overwrite;
|
|
2084 err->uri = value[cf->args->nelts - 1];
|
|
2085 }
|
|
2086
|
|
2087 return NGX_CONF_OK;
|
|
2088 }
|
|
2089
|
|
2090
|
36
|
2091 static char *
|
58
|
2092 ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
2093 {
|
|
2094 ngx_http_core_loc_conf_t *lcf = conf;
|
|
2095
|
|
2096 lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args);
|
|
2097 if (lcf->err_log == NULL) {
|
|
2098 return NGX_CONF_ERROR;
|
|
2099 }
|
|
2100
|
|
2101 return ngx_set_error_log_levels(cf, lcf->err_log);
|
|
2102 }
|
|
2103
|
|
2104
|
|
2105 static char *
|
36
|
2106 ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
2107 {
|
|
2108 ngx_http_core_loc_conf_t *lcf = conf;
|
|
2109
|
|
2110 ngx_str_t *value;
|
|
2111
|
|
2112 if (lcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) {
|
|
2113 return "is duplicate";
|
|
2114 }
|
|
2115
|
|
2116 value = cf->args->elts;
|
|
2117
|
|
2118 lcf->keepalive_timeout = ngx_parse_time(&value[1], 0);
|
36
|
2119
|
0
|
2120 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) {
|
|
2121 return "invalid value";
|
|
2122 }
|
|
2123
|
|
2124 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) {
|
|
2125 return "value must be less than 597 hours";
|
|
2126 }
|
|
2127
|
|
2128 if (cf->args->nelts == 2) {
|
|
2129 return NGX_CONF_OK;
|
|
2130 }
|
|
2131
|
|
2132 lcf->keepalive_header = ngx_parse_time(&value[2], 1);
|
36
|
2133
|
0
|
2134 if (lcf->keepalive_header == NGX_ERROR) {
|
|
2135 return "invalid value";
|
|
2136 }
|
|
2137
|
|
2138 if (lcf->keepalive_header == NGX_PARSE_LARGE_TIME) {
|
|
2139 return "value must be less than 68 years";
|
|
2140 }
|
|
2141
|
|
2142 return NGX_CONF_OK;
|
|
2143 }
|
|
2144
|
|
2145
|
36
|
2146 static char *
|
58
|
2147 ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
2148 {
|
|
2149 ngx_http_core_loc_conf_t *lcf = conf;
|
|
2150
|
58
|
2151 if (lcf->internal != NGX_CONF_UNSET) {
|
|
2152 return "is duplicate";
|
0
|
2153 }
|
|
2154
|
58
|
2155 lcf->internal = 1;
|
|
2156
|
|
2157 return NGX_CONF_OK;
|
0
|
2158 }
|
|
2159
|
|
2160
|
36
|
2161 static char *
|
|
2162 ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data)
|
0
|
2163 {
|
22
|
2164 #if (NGX_FREEBSD)
|
2
|
2165 ssize_t *np = data;
|
0
|
2166
|
|
2167 if (*np >= ngx_freebsd_net_inet_tcp_sendspace) {
|
|
2168 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2169 "\"send_lowat\" must be less than %d "
|
|
2170 "(sysctl net.inet.tcp.sendspace)",
|
|
2171 ngx_freebsd_net_inet_tcp_sendspace);
|
|
2172
|
|
2173 return NGX_CONF_ERROR;
|
|
2174 }
|
|
2175
|
18
|
2176 #elif !(NGX_HAVE_SO_SNDLOWAT)
|
22
|
2177 ssize_t *np = data;
|
0
|
2178
|
|
2179 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
2180 "\"send_lowat\" is not supported, ignored");
|
|
2181
|
2
|
2182 *np = 0;
|
|
2183
|
0
|
2184 #endif
|
|
2185
|
|
2186 return NGX_CONF_OK;
|
|
2187 }
|