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
|
0
|
20 #define NGX_HTTP_LOCATION_EXACT 1
|
|
21 #define NGX_HTTP_LOCATION_AUTO_REDIRECT 2
|
16
|
22 #define NGX_HTTP_LOCATION_NOREGEX 3
|
|
23 #define NGX_HTTP_LOCATION_REGEX 4
|
0
|
24
|
|
25
|
278
|
26 #define NGX_HTTP_REQUEST_BODY_FILE_OFF 0
|
|
27 #define NGX_HTTP_REQUEST_BODY_FILE_ON 1
|
|
28 #define NGX_HTTP_REQUEST_BODY_FILE_CLEAN 2
|
|
29
|
|
30
|
34
|
31 static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r,
|
36
|
32 ngx_array_t *locations, size_t len);
|
0
|
33
|
58
|
34 static ngx_int_t ngx_http_core_preconfiguration(ngx_conf_t *cf);
|
0
|
35 static void *ngx_http_core_create_main_conf(ngx_conf_t *cf);
|
|
36 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf);
|
|
37 static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf);
|
|
38 static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
|
36
|
39 void *parent, void *child);
|
0
|
40 static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf);
|
|
41 static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
|
36
|
42 void *parent, void *child);
|
0
|
43
|
34
|
44 static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
45 void *dummy);
|
34
|
46 static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
47 void *dummy);
|
52
|
48 static int ngx_libc_cdecl ngx_http_core_cmp_locations(const void *first,
|
|
49 const void *second);
|
34
|
50
|
|
51 static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
52 void *conf);
|
34
|
53 static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy,
|
36
|
54 void *conf);
|
0
|
55
|
34
|
56 static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
57 void *conf);
|
34
|
58 static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
59 void *conf);
|
34
|
60 static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
180
|
61 static char *ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
62 void *conf);
|
34
|
63 static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
64 void *conf);
|
34
|
65 static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
66 void *conf);
|
34
|
67 static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
68 void *conf);
|
58
|
69 static char *ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
70 void *conf);
|
0
|
71
|
34
|
72 static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data);
|
|
73
|
|
74 static ngx_conf_post_t ngx_http_core_lowat_post =
|
|
75 { ngx_http_core_lowat_check };
|
0
|
76
|
158
|
77 static ngx_conf_deprecated_t ngx_conf_deprecated_optimize_host_names = {
|
|
78 ngx_conf_deprecated, "optimize_host_names", "optimize_server_names"
|
|
79 };
|
|
80
|
0
|
81
|
278
|
82 static ngx_conf_enum_t ngx_http_core_request_body_in_file[] = {
|
|
83 { ngx_string("off"), NGX_HTTP_REQUEST_BODY_FILE_OFF },
|
|
84 { ngx_string("on"), NGX_HTTP_REQUEST_BODY_FILE_ON },
|
|
85 { ngx_string("clean"), NGX_HTTP_REQUEST_BODY_FILE_CLEAN },
|
|
86 { ngx_null_string, 0 }
|
|
87 };
|
|
88
|
|
89
|
0
|
90 static ngx_command_t ngx_http_core_commands[] = {
|
|
91
|
160
|
92 { ngx_string("variables_hash_max_size"),
|
|
93 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
|
94 ngx_conf_set_num_slot,
|
|
95 NGX_HTTP_MAIN_CONF_OFFSET,
|
|
96 offsetof(ngx_http_core_main_conf_t, variables_hash_max_size),
|
|
97 NULL },
|
|
98
|
|
99 { ngx_string("variables_hash_bucket_size"),
|
|
100 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
|
101 ngx_conf_set_num_slot,
|
|
102 NGX_HTTP_MAIN_CONF_OFFSET,
|
|
103 offsetof(ngx_http_core_main_conf_t, variables_hash_bucket_size),
|
|
104 NULL },
|
|
105
|
142
|
106 { ngx_string("server_names_hash_max_size"),
|
26
|
107 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
|
108 ngx_conf_set_num_slot,
|
|
109 NGX_HTTP_MAIN_CONF_OFFSET,
|
142
|
110 offsetof(ngx_http_core_main_conf_t, server_names_hash_max_size),
|
26
|
111 NULL },
|
|
112
|
142
|
113 { ngx_string("server_names_hash_bucket_size"),
|
26
|
114 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
|
115 ngx_conf_set_num_slot,
|
|
116 NGX_HTTP_MAIN_CONF_OFFSET,
|
142
|
117 offsetof(ngx_http_core_main_conf_t, server_names_hash_bucket_size),
|
26
|
118 NULL },
|
|
119
|
0
|
120 { ngx_string("server"),
|
200
|
121 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_MULTI|NGX_CONF_NOARGS,
|
34
|
122 ngx_http_core_server,
|
0
|
123 0,
|
|
124 0,
|
|
125 NULL },
|
|
126
|
|
127 { ngx_string("connection_pool_size"),
|
|
128 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
129 ngx_conf_set_size_slot,
|
|
130 NGX_HTTP_SRV_CONF_OFFSET,
|
|
131 offsetof(ngx_http_core_srv_conf_t, connection_pool_size),
|
|
132 NULL },
|
|
133
|
|
134 { ngx_string("request_pool_size"),
|
|
135 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
136 ngx_conf_set_size_slot,
|
|
137 NGX_HTTP_SRV_CONF_OFFSET,
|
|
138 offsetof(ngx_http_core_srv_conf_t, request_pool_size),
|
|
139 NULL },
|
|
140
|
|
141 { ngx_string("client_header_timeout"),
|
|
142 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
143 ngx_conf_set_msec_slot,
|
|
144 NGX_HTTP_SRV_CONF_OFFSET,
|
|
145 offsetof(ngx_http_core_srv_conf_t, client_header_timeout),
|
|
146 NULL },
|
|
147
|
|
148 { ngx_string("client_header_buffer_size"),
|
|
149 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
150 ngx_conf_set_size_slot,
|
|
151 NGX_HTTP_SRV_CONF_OFFSET,
|
|
152 offsetof(ngx_http_core_srv_conf_t, client_header_buffer_size),
|
|
153 NULL },
|
|
154
|
|
155 { ngx_string("large_client_header_buffers"),
|
|
156 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE2,
|
|
157 ngx_conf_set_bufs_slot,
|
|
158 NGX_HTTP_SRV_CONF_OFFSET,
|
|
159 offsetof(ngx_http_core_srv_conf_t, large_client_header_buffers),
|
|
160 NULL },
|
|
161
|
158
|
162 { ngx_string("optimize_server_names"),
|
|
163 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
|
|
164 ngx_conf_set_flag_slot,
|
|
165 NGX_HTTP_SRV_CONF_OFFSET,
|
|
166 offsetof(ngx_http_core_srv_conf_t, optimize_server_names),
|
|
167 NULL },
|
|
168
|
152
|
169 { ngx_string("optimize_host_names"),
|
|
170 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
|
|
171 ngx_conf_set_flag_slot,
|
|
172 NGX_HTTP_SRV_CONF_OFFSET,
|
158
|
173 offsetof(ngx_http_core_srv_conf_t, optimize_server_names),
|
|
174 &ngx_conf_deprecated_optimize_host_names },
|
152
|
175
|
60
|
176 { ngx_string("ignore_invalid_headers"),
|
|
177 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
|
|
178 ngx_conf_set_flag_slot,
|
|
179 NGX_HTTP_SRV_CONF_OFFSET,
|
|
180 offsetof(ngx_http_core_srv_conf_t, ignore_invalid_headers),
|
|
181 NULL },
|
|
182
|
0
|
183 { ngx_string("location"),
|
|
184 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12,
|
34
|
185 ngx_http_core_location,
|
0
|
186 NGX_HTTP_SRV_CONF_OFFSET,
|
|
187 0,
|
|
188 NULL },
|
|
189
|
|
190 { ngx_string("listen"),
|
72
|
191 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
|
34
|
192 ngx_http_core_listen,
|
0
|
193 NGX_HTTP_SRV_CONF_OFFSET,
|
|
194 0,
|
|
195 NULL },
|
|
196
|
|
197 { ngx_string("server_name"),
|
|
198 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
|
34
|
199 ngx_http_core_server_name,
|
0
|
200 NGX_HTTP_SRV_CONF_OFFSET,
|
|
201 0,
|
|
202 NULL },
|
|
203
|
138
|
204 { ngx_string("types_hash_max_size"),
|
|
205 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
206 ngx_conf_set_num_slot,
|
|
207 NGX_HTTP_LOC_CONF_OFFSET,
|
|
208 offsetof(ngx_http_core_loc_conf_t, types_hash_max_size),
|
|
209 NULL },
|
|
210
|
|
211 { ngx_string("types_hash_bucket_size"),
|
|
212 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
213 ngx_conf_set_num_slot,
|
|
214 NGX_HTTP_LOC_CONF_OFFSET,
|
|
215 offsetof(ngx_http_core_loc_conf_t, types_hash_bucket_size),
|
|
216 NULL },
|
|
217
|
0
|
218 { ngx_string("types"),
|
|
219 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF
|
|
220 |NGX_CONF_BLOCK|NGX_CONF_NOARGS,
|
34
|
221 ngx_http_core_types,
|
0
|
222 NGX_HTTP_LOC_CONF_OFFSET,
|
|
223 0,
|
|
224 NULL },
|
|
225
|
|
226 { ngx_string("default_type"),
|
|
227 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
228 ngx_conf_set_str_slot,
|
|
229 NGX_HTTP_LOC_CONF_OFFSET,
|
|
230 offsetof(ngx_http_core_loc_conf_t, default_type),
|
|
231 NULL },
|
|
232
|
|
233 { ngx_string("root"),
|
58
|
234 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
235 |NGX_CONF_TAKE1,
|
34
|
236 ngx_http_core_root,
|
0
|
237 NGX_HTTP_LOC_CONF_OFFSET,
|
|
238 0,
|
|
239 NULL },
|
|
240
|
|
241 { ngx_string("alias"),
|
|
242 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
34
|
243 ngx_http_core_root,
|
0
|
244 NGX_HTTP_LOC_CONF_OFFSET,
|
|
245 0,
|
|
246 NULL },
|
|
247
|
180
|
248 { ngx_string("limit_except"),
|
|
249 NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_1MORE,
|
|
250 ngx_http_core_limit_except,
|
|
251 NGX_HTTP_LOC_CONF_OFFSET,
|
|
252 0,
|
|
253 NULL },
|
|
254
|
0
|
255 { ngx_string("client_max_body_size"),
|
|
256 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
212
|
257 ngx_conf_set_off_slot,
|
0
|
258 NGX_HTTP_LOC_CONF_OFFSET,
|
|
259 offsetof(ngx_http_core_loc_conf_t, client_max_body_size),
|
|
260 NULL },
|
|
261
|
|
262 { ngx_string("client_body_buffer_size"),
|
|
263 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
264 ngx_conf_set_size_slot,
|
|
265 NGX_HTTP_LOC_CONF_OFFSET,
|
|
266 offsetof(ngx_http_core_loc_conf_t, client_body_buffer_size),
|
|
267 NULL },
|
|
268
|
|
269 { ngx_string("client_body_timeout"),
|
|
270 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
271 ngx_conf_set_msec_slot,
|
|
272 NGX_HTTP_LOC_CONF_OFFSET,
|
|
273 offsetof(ngx_http_core_loc_conf_t, client_body_timeout),
|
|
274 NULL },
|
|
275
|
28
|
276 { ngx_string("client_body_temp_path"),
|
|
277 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
|
|
278 ngx_conf_set_path_slot,
|
|
279 NGX_HTTP_LOC_CONF_OFFSET,
|
|
280 offsetof(ngx_http_core_loc_conf_t, client_body_temp_path),
|
|
281 (void *) ngx_garbage_collector_temp_handler },
|
|
282
|
182
|
283 { ngx_string("client_body_in_file_only"),
|
|
284 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
278
|
285 ngx_conf_set_enum_slot,
|
182
|
286 NGX_HTTP_LOC_CONF_OFFSET,
|
|
287 offsetof(ngx_http_core_loc_conf_t, client_body_in_file_only),
|
278
|
288 &ngx_http_core_request_body_in_file },
|
182
|
289
|
0
|
290 { ngx_string("sendfile"),
|
278
|
291 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
292 |NGX_CONF_TAKE1,
|
0
|
293 ngx_conf_set_flag_slot,
|
|
294 NGX_HTTP_LOC_CONF_OFFSET,
|
|
295 offsetof(ngx_http_core_loc_conf_t, sendfile),
|
|
296 NULL },
|
|
297
|
|
298 { ngx_string("tcp_nopush"),
|
|
299 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
300 ngx_conf_set_flag_slot,
|
|
301 NGX_HTTP_LOC_CONF_OFFSET,
|
|
302 offsetof(ngx_http_core_loc_conf_t, tcp_nopush),
|
|
303 NULL },
|
|
304
|
2
|
305 { ngx_string("tcp_nodelay"),
|
|
306 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
307 ngx_conf_set_flag_slot,
|
|
308 NGX_HTTP_LOC_CONF_OFFSET,
|
|
309 offsetof(ngx_http_core_loc_conf_t, tcp_nodelay),
|
|
310 NULL },
|
|
311
|
0
|
312 { ngx_string("send_timeout"),
|
|
313 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
314 ngx_conf_set_msec_slot,
|
|
315 NGX_HTTP_LOC_CONF_OFFSET,
|
|
316 offsetof(ngx_http_core_loc_conf_t, send_timeout),
|
|
317 NULL },
|
|
318
|
|
319 { ngx_string("send_lowat"),
|
|
320 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
321 ngx_conf_set_size_slot,
|
|
322 NGX_HTTP_LOC_CONF_OFFSET,
|
|
323 offsetof(ngx_http_core_loc_conf_t, send_lowat),
|
34
|
324 &ngx_http_core_lowat_post },
|
0
|
325
|
|
326 { ngx_string("postpone_output"),
|
|
327 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
328 ngx_conf_set_size_slot,
|
|
329 NGX_HTTP_LOC_CONF_OFFSET,
|
|
330 offsetof(ngx_http_core_loc_conf_t, postpone_output),
|
|
331 NULL },
|
|
332
|
|
333 { ngx_string("limit_rate"),
|
34
|
334 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
335 |NGX_CONF_TAKE1,
|
0
|
336 ngx_conf_set_size_slot,
|
|
337 NGX_HTTP_LOC_CONF_OFFSET,
|
|
338 offsetof(ngx_http_core_loc_conf_t, limit_rate),
|
|
339 NULL },
|
|
340
|
|
341 { ngx_string("keepalive_timeout"),
|
|
342 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
|
34
|
343 ngx_http_core_keepalive,
|
0
|
344 NGX_HTTP_LOC_CONF_OFFSET,
|
|
345 0,
|
|
346 NULL },
|
|
347
|
92
|
348 { ngx_string("satisfy_any"),
|
|
349 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
350 ngx_conf_set_flag_slot,
|
|
351 NGX_HTTP_LOC_CONF_OFFSET,
|
|
352 offsetof(ngx_http_core_loc_conf_t, satisfy_any),
|
|
353 NULL },
|
|
354
|
58
|
355 { ngx_string("internal"),
|
|
356 NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
|
|
357 ngx_http_core_internal,
|
|
358 NGX_HTTP_LOC_CONF_OFFSET,
|
|
359 0,
|
|
360 NULL },
|
|
361
|
0
|
362 { ngx_string("lingering_time"),
|
|
363 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
364 ngx_conf_set_msec_slot,
|
|
365 NGX_HTTP_LOC_CONF_OFFSET,
|
|
366 offsetof(ngx_http_core_loc_conf_t, lingering_time),
|
|
367 NULL },
|
|
368
|
|
369 { ngx_string("lingering_timeout"),
|
|
370 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
371 ngx_conf_set_msec_slot,
|
|
372 NGX_HTTP_LOC_CONF_OFFSET,
|
|
373 offsetof(ngx_http_core_loc_conf_t, lingering_timeout),
|
|
374 NULL },
|
|
375
|
|
376 { ngx_string("reset_timedout_connection"),
|
|
377 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
378 ngx_conf_set_flag_slot,
|
|
379 NGX_HTTP_LOC_CONF_OFFSET,
|
|
380 offsetof(ngx_http_core_loc_conf_t, reset_timedout_connection),
|
|
381 NULL },
|
|
382
|
70
|
383 { ngx_string("port_in_redirect"),
|
|
384 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
385 ngx_conf_set_flag_slot,
|
|
386 NGX_HTTP_LOC_CONF_OFFSET,
|
|
387 offsetof(ngx_http_core_loc_conf_t, port_in_redirect),
|
|
388 NULL },
|
|
389
|
0
|
390 { ngx_string("msie_padding"),
|
|
391 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
392 ngx_conf_set_flag_slot,
|
|
393 NGX_HTTP_LOC_CONF_OFFSET,
|
|
394 offsetof(ngx_http_core_loc_conf_t, msie_padding),
|
|
395 NULL },
|
|
396
|
228
|
397 { ngx_string("msie_refresh"),
|
|
398 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
399 ngx_conf_set_flag_slot,
|
|
400 NGX_HTTP_LOC_CONF_OFFSET,
|
|
401 offsetof(ngx_http_core_loc_conf_t, msie_refresh),
|
|
402 NULL },
|
|
403
|
76
|
404 { ngx_string("log_not_found"),
|
|
405 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
406 ngx_conf_set_flag_slot,
|
|
407 NGX_HTTP_LOC_CONF_OFFSET,
|
|
408 offsetof(ngx_http_core_loc_conf_t, log_not_found),
|
|
409 NULL },
|
|
410
|
228
|
411 { ngx_string("recursive_error_pages"),
|
|
412 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
413 ngx_conf_set_flag_slot,
|
|
414 NGX_HTTP_LOC_CONF_OFFSET,
|
|
415 offsetof(ngx_http_core_loc_conf_t, recursive_error_pages),
|
|
416 NULL },
|
|
417
|
0
|
418 { ngx_string("error_page"),
|
58
|
419 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
420 |NGX_CONF_2MORE,
|
34
|
421 ngx_http_core_error_page,
|
0
|
422 NGX_HTTP_LOC_CONF_OFFSET,
|
|
423 0,
|
|
424 NULL },
|
|
425
|
126
|
426 { ngx_string("post_action"),
|
|
427 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
428 |NGX_CONF_TAKE1,
|
|
429 ngx_conf_set_str_slot,
|
|
430 NGX_HTTP_LOC_CONF_OFFSET,
|
|
431 offsetof(ngx_http_core_loc_conf_t, post_action),
|
|
432 NULL },
|
|
433
|
0
|
434 { ngx_string("error_log"),
|
|
435 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
34
|
436 ngx_http_core_error_log,
|
0
|
437 NGX_HTTP_LOC_CONF_OFFSET,
|
|
438 0,
|
|
439 NULL },
|
|
440
|
|
441 #if (NGX_HTTP_CACHE)
|
|
442
|
|
443 { ngx_string("open_file_cache"),
|
|
444 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE4,
|
|
445 ngx_http_set_cache_slot,
|
|
446 NGX_HTTP_LOC_CONF_OFFSET,
|
|
447 offsetof(ngx_http_core_loc_conf_t, open_files),
|
|
448 NULL },
|
|
449
|
|
450 #endif
|
|
451
|
|
452 ngx_null_command
|
|
453 };
|
|
454
|
|
455
|
216
|
456 static ngx_http_module_t ngx_http_core_module_ctx = {
|
58
|
457 ngx_http_core_preconfiguration, /* preconfiguration */
|
122
|
458 NULL, /* postconfiguration */
|
0
|
459
|
|
460 ngx_http_core_create_main_conf, /* create main configuration */
|
|
461 ngx_http_core_init_main_conf, /* init main configuration */
|
|
462
|
|
463 ngx_http_core_create_srv_conf, /* create server configuration */
|
|
464 ngx_http_core_merge_srv_conf, /* merge server configuration */
|
|
465
|
|
466 ngx_http_core_create_loc_conf, /* create location configuration */
|
|
467 ngx_http_core_merge_loc_conf /* merge location configuration */
|
|
468 };
|
|
469
|
|
470
|
|
471 ngx_module_t ngx_http_core_module = {
|
58
|
472 NGX_MODULE_V1,
|
0
|
473 &ngx_http_core_module_ctx, /* module context */
|
|
474 ngx_http_core_commands, /* module directives */
|
|
475 NGX_HTTP_MODULE, /* module type */
|
90
|
476 NULL, /* init master */
|
58
|
477 NULL, /* init module */
|
90
|
478 NULL, /* init process */
|
|
479 NULL, /* init thread */
|
|
480 NULL, /* exit thread */
|
|
481 NULL, /* exit process */
|
|
482 NULL, /* exit master */
|
|
483 NGX_MODULE_V1_PADDING
|
0
|
484 };
|
|
485
|
|
486
|
36
|
487 void
|
|
488 ngx_http_handler(ngx_http_request_t *r)
|
0
|
489 {
|
230
|
490 ngx_http_core_main_conf_t *cmcf;
|
|
491
|
32
|
492 r->connection->log->action = NULL;
|
0
|
493
|
|
494 r->connection->unexpected_eof = 0;
|
|
495
|
224
|
496 if (!r->internal) {
|
92
|
497 switch (r->headers_in.connection_type) {
|
|
498 case 0:
|
|
499 if (r->http_version > NGX_HTTP_VERSION_10) {
|
|
500 r->keepalive = 1;
|
|
501 } else {
|
|
502 r->keepalive = 0;
|
|
503 }
|
|
504 break;
|
|
505
|
|
506 case NGX_HTTP_CONNECTION_CLOSE:
|
|
507 r->keepalive = 0;
|
|
508 break;
|
|
509
|
|
510 case NGX_HTTP_CONNECTION_KEEP_ALIVE:
|
0
|
511 r->keepalive = 1;
|
92
|
512 break;
|
|
513 }
|
|
514
|
|
515 if (r->keepalive && r->headers_in.msie && r->method == NGX_HTTP_POST) {
|
|
516
|
|
517 /*
|
230
|
518 * MSIE may wait for some time if an response for
|
|
519 * a POST request was sent over a keepalive connection
|
92
|
520 */
|
|
521
|
0
|
522 r->keepalive = 0;
|
|
523 }
|
92
|
524
|
|
525 if (r->headers_in.content_length_n > 0) {
|
|
526 r->lingering_close = 1;
|
|
527
|
|
528 } else {
|
|
529 r->lingering_close = 0;
|
|
530 }
|
236
|
531
|
230
|
532 r->phase_handler = 0;
|
|
533
|
|
534 } else {
|
|
535 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
|
|
536 r->phase_handler = cmcf->phase_engine.server_rewrite_index;
|
|
537 }
|
|
538
|
236
|
539 if (r->unparsed_uri.len) {
|
|
540 r->valid_unparsed_uri = 1;
|
|
541 }
|
|
542
|
|
543 r->valid_location = 1;
|
|
544
|
230
|
545 r->write_event_handler = ngx_http_core_run_phases;
|
34
|
546 ngx_http_core_run_phases(r);
|
0
|
547 }
|
|
548
|
|
549
|
230
|
550 void
|
36
|
551 ngx_http_core_run_phases(ngx_http_request_t *r)
|
0
|
552 {
|
|
553 ngx_int_t rc;
|
230
|
554 ngx_http_phase_handler_t *ph;
|
0
|
555 ngx_http_core_main_conf_t *cmcf;
|
|
556
|
|
557 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
|
|
558
|
230
|
559 ph = cmcf->phase_engine.handlers;
|
|
560
|
|
561 while (ph[r->phase_handler].checker) {
|
|
562
|
|
563 rc = ph[r->phase_handler].checker(r, &ph[r->phase_handler]);
|
|
564
|
|
565 if (rc == NGX_OK) {
|
92
|
566 return;
|
0
|
567 }
|
|
568 }
|
|
569 }
|
|
570
|
|
571
|
36
|
572 ngx_int_t
|
230
|
573 ngx_http_core_generic_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
|
|
574 {
|
|
575 ngx_int_t rc;
|
|
576
|
|
577 /*
|
|
578 * generic phase checker,
|
|
579 * used by the post read, server rewrite, rewrite, and pre-access phases
|
|
580 */
|
|
581
|
|
582 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
583 "generic phase: %ui", r->phase_handler);
|
|
584
|
|
585 rc = ph->handler(r);
|
|
586
|
|
587 if (rc == NGX_OK) {
|
|
588 r->phase_handler = ph->next;
|
|
589 return NGX_AGAIN;
|
|
590 }
|
|
591
|
|
592 if (rc == NGX_DECLINED) {
|
|
593 r->phase_handler++;
|
|
594 return NGX_AGAIN;
|
|
595 }
|
|
596
|
|
597 if (rc == NGX_AGAIN || rc == NGX_DONE) {
|
|
598 return NGX_OK;
|
|
599 }
|
|
600
|
|
601 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
|
|
602
|
|
603 ngx_http_finalize_request(r, rc);
|
|
604
|
|
605 return NGX_OK;
|
|
606 }
|
|
607
|
|
608
|
|
609 ngx_int_t
|
|
610 ngx_http_core_find_config_phase(ngx_http_request_t *r,
|
|
611 ngx_http_phase_handler_t *ph)
|
0
|
612 {
|
|
613 ngx_int_t rc;
|
|
614 ngx_http_core_loc_conf_t *clcf;
|
|
615 ngx_http_core_srv_conf_t *cscf;
|
|
616
|
38
|
617 r->content_handler = NULL;
|
|
618 r->uri_changed = 0;
|
|
619
|
0
|
620 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
|
621
|
34
|
622 rc = ngx_http_core_find_location(r, &cscf->locations, 0);
|
0
|
623
|
|
624 if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) {
|
230
|
625 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
626 return NGX_OK;
|
0
|
627 }
|
|
628
|
|
629 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
630
|
58
|
631 if (!r->internal && clcf->internal) {
|
230
|
632 ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
|
|
633 return NGX_OK;
|
58
|
634 }
|
|
635
|
104
|
636 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
637 "using configuration \"%s%V\"",
|
|
638 (clcf->noname ? "*" : (clcf->exact_match ? "=" : "")),
|
|
639 &clcf->name);
|
|
640
|
84
|
641 ngx_http_update_location_config(r);
|
0
|
642
|
|
643 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
212
|
644 "http cl:%O max:%O",
|
10
|
645 r->headers_in.content_length_n, clcf->client_max_body_size);
|
0
|
646
|
|
647 if (r->headers_in.content_length_n != -1
|
222
|
648 && !r->discard_body
|
0
|
649 && clcf->client_max_body_size
|
212
|
650 && clcf->client_max_body_size < r->headers_in.content_length_n)
|
0
|
651 {
|
|
652 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
212
|
653 "client intented to send too large body: %O bytes",
|
0
|
654 r->headers_in.content_length_n);
|
|
655
|
230
|
656 ngx_http_finalize_request(r, NGX_HTTP_REQUEST_ENTITY_TOO_LARGE);
|
|
657 return NGX_OK;
|
0
|
658 }
|
|
659
|
|
660
|
|
661 if (rc == NGX_HTTP_LOCATION_AUTO_REDIRECT) {
|
|
662 r->headers_out.location = ngx_list_push(&r->headers_out.headers);
|
|
663 if (r->headers_out.location == NULL) {
|
230
|
664 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
665 return NGX_OK;
|
0
|
666 }
|
|
667
|
58
|
668 /*
|
|
669 * we do not need to set the r->headers_out.location->hash and
|
|
670 * r->headers_out.location->key fields
|
|
671 */
|
|
672
|
0
|
673 r->headers_out.location->value = clcf->name;
|
|
674
|
230
|
675 ngx_http_finalize_request(r, NGX_HTTP_MOVED_PERMANENTLY);
|
|
676 return NGX_OK;
|
|
677 }
|
|
678
|
|
679 r->phase_handler++;
|
|
680 return NGX_AGAIN;
|
|
681 }
|
|
682
|
|
683
|
|
684 ngx_int_t
|
|
685 ngx_http_core_post_rewrite_phase(ngx_http_request_t *r,
|
|
686 ngx_http_phase_handler_t *ph)
|
|
687 {
|
|
688 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
689 "post rewrite phase: %ui", r->phase_handler);
|
|
690
|
|
691 if (!r->uri_changed) {
|
|
692 r->phase_handler++;
|
|
693 return NGX_AGAIN;
|
|
694 }
|
|
695
|
|
696 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
697 "uri changes: %d", r->uri_changes);
|
|
698
|
|
699 /*
|
|
700 * gcc before 3.3 compiles the broken code for
|
|
701 * if (r->uri_changes-- == 0)
|
|
702 * if the r->uri_changes is defined as
|
|
703 * unsigned uri_changes:4
|
|
704 */
|
|
705
|
|
706 r->uri_changes--;
|
|
707
|
|
708 if (r->uri_changes == 0) {
|
|
709 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
710 "rewrite or internal redirection cycle "
|
|
711 "while processing \"%V\"", &r->uri);
|
|
712
|
|
713 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
714 return NGX_OK;
|
|
715 }
|
|
716
|
|
717 r->phase_handler = ph->next;
|
|
718
|
|
719 return NGX_AGAIN;
|
|
720 }
|
|
721
|
|
722
|
|
723 ngx_int_t
|
|
724 ngx_http_core_access_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
|
|
725 {
|
|
726 ngx_int_t rc;
|
|
727 ngx_http_core_loc_conf_t *clcf;
|
|
728
|
|
729 if (r != r->main) {
|
|
730 r->phase_handler = ph->next;
|
|
731 return NGX_AGAIN;
|
|
732 }
|
|
733
|
|
734 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
735 "access phase: %ui", r->phase_handler);
|
|
736
|
|
737 rc = ph->handler(r);
|
|
738
|
|
739 if (rc == NGX_DECLINED) {
|
|
740 r->phase_handler++;
|
|
741 return NGX_AGAIN;
|
|
742 }
|
|
743
|
|
744 if (rc == NGX_AGAIN || rc == NGX_DONE) {
|
|
745 return NGX_OK;
|
0
|
746 }
|
|
747
|
230
|
748 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
749
|
|
750 if (clcf->satisfy_any == 0) {
|
|
751
|
|
752 if (rc == NGX_OK) {
|
|
753 r->phase_handler++;
|
|
754 return NGX_AGAIN;
|
|
755 }
|
|
756
|
|
757 } else {
|
|
758 if (rc == NGX_OK) {
|
|
759 r->access_code = 0;
|
|
760
|
|
761 if (r->headers_out.www_authenticate) {
|
|
762 r->headers_out.www_authenticate->hash = 0;
|
|
763 }
|
|
764
|
|
765 r->phase_handler = ph->next;
|
|
766 return NGX_AGAIN;
|
|
767 }
|
|
768
|
|
769 if (rc == NGX_HTTP_FORBIDDEN || rc == NGX_HTTP_UNAUTHORIZED) {
|
|
770 r->access_code = rc;
|
|
771
|
|
772 r->phase_handler++;
|
|
773 return NGX_AGAIN;
|
|
774 }
|
|
775 }
|
|
776
|
|
777 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
|
|
778
|
|
779 ngx_http_finalize_request(r, rc);
|
|
780 return NGX_OK;
|
|
781 }
|
|
782
|
|
783
|
|
784 ngx_int_t
|
|
785 ngx_http_core_post_access_phase(ngx_http_request_t *r,
|
|
786 ngx_http_phase_handler_t *ph)
|
|
787 {
|
|
788 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
789 "post access phase: %ui", r->phase_handler);
|
|
790
|
|
791 if (r->access_code) {
|
|
792
|
|
793 if (r->access_code == NGX_HTTP_FORBIDDEN) {
|
|
794 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
795 "access forbidden by rule");
|
|
796 }
|
|
797
|
|
798 ngx_http_finalize_request(r, r->access_code);
|
|
799 return NGX_OK;
|
|
800 }
|
|
801
|
|
802 r->phase_handler++;
|
|
803 return NGX_AGAIN;
|
|
804 }
|
|
805
|
|
806
|
|
807 ngx_int_t
|
|
808 ngx_http_core_content_phase(ngx_http_request_t *r,
|
|
809 ngx_http_phase_handler_t *ph)
|
|
810 {
|
248
|
811 size_t root;
|
230
|
812 ngx_int_t rc;
|
|
813 ngx_str_t path;
|
|
814
|
|
815 if (r->content_handler) {
|
|
816 r->write_event_handler = ngx_http_request_empty_handler;
|
|
817 ngx_http_finalize_request(r, r->content_handler(r));
|
|
818 return NGX_OK;
|
|
819 }
|
|
820
|
|
821 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
822 "content phase: %ui", r->phase_handler);
|
|
823
|
|
824 rc = ph->handler(r);
|
|
825
|
|
826 if (rc == NGX_DONE) {
|
|
827 return NGX_OK;
|
|
828 }
|
|
829
|
|
830 if (rc != NGX_DECLINED) {
|
|
831 ngx_http_finalize_request(r, rc);
|
|
832 return NGX_OK;
|
|
833 }
|
|
834
|
|
835 /* rc == NGX_DECLINED */
|
|
836
|
|
837 ph++;
|
|
838
|
|
839 if (ph->checker) {
|
|
840 r->phase_handler++;
|
|
841 return NGX_AGAIN;
|
|
842 }
|
|
843
|
|
844 /* no content handler was found */
|
|
845
|
|
846 if (r->uri.data[r->uri.len - 1] == '/' && !r->zero_in_uri) {
|
|
847
|
248
|
848 if (ngx_http_map_uri_to_path(r, &path, &root, 0) != NULL) {
|
230
|
849 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
850 "directory index of \"%V\" is forbidden", &path);
|
|
851 }
|
|
852
|
|
853 ngx_http_finalize_request(r, NGX_HTTP_FORBIDDEN);
|
|
854 return NGX_OK;
|
|
855 }
|
|
856
|
|
857 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no handler found");
|
|
858
|
|
859 ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
|
84
|
860 return NGX_OK;
|
|
861 }
|
|
862
|
|
863
|
|
864 void
|
|
865 ngx_http_update_location_config(ngx_http_request_t *r)
|
|
866 {
|
|
867 ngx_http_core_loc_conf_t *clcf;
|
|
868
|
|
869 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
870
|
180
|
871 if (r->method & clcf->limit_except) {
|
|
872 r->loc_conf = clcf->limit_except_loc_conf;
|
|
873 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
874 }
|
|
875
|
192
|
876 if (r == r->main) {
|
294
|
877 r->connection->log->file = clcf->err_log->file;
|
|
878
|
192
|
879 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
|
|
880 r->connection->log->log_level = clcf->err_log->log_level;
|
|
881 }
|
84
|
882 }
|
|
883
|
|
884 if ((ngx_io.flags & NGX_IO_SENDFILE) && clcf->sendfile) {
|
|
885 r->connection->sendfile = 1;
|
|
886
|
|
887 } else {
|
|
888 r->connection->sendfile = 0;
|
|
889 }
|
|
890
|
182
|
891 if (clcf->client_body_in_file_only) {
|
|
892 r->request_body_in_file_only = 1;
|
|
893 r->request_body_in_persistent_file = 1;
|
278
|
894 r->request_body_in_clean_file =
|
|
895 clcf->client_body_in_file_only == NGX_HTTP_REQUEST_BODY_FILE_CLEAN;
|
186
|
896 r->request_body_file_log_level = NGX_LOG_NOTICE;
|
|
897
|
|
898 } else {
|
|
899 r->request_body_file_log_level = NGX_LOG_WARN;
|
182
|
900 }
|
|
901
|
84
|
902 if (r->keepalive && clcf->keepalive_timeout == 0) {
|
|
903 r->keepalive = 0;
|
|
904 }
|
|
905
|
|
906 if (!clcf->tcp_nopush) {
|
|
907 /* disable TCP_NOPUSH/TCP_CORK use */
|
|
908 r->connection->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;
|
|
909 }
|
|
910
|
162
|
911 if (r->limit_rate == 0) {
|
|
912 r->limit_rate = clcf->limit_rate;
|
|
913 }
|
76
|
914
|
0
|
915 if (clcf->handler) {
|
|
916 r->content_handler = clcf->handler;
|
|
917 }
|
|
918 }
|
|
919
|
|
920
|
36
|
921 static ngx_int_t
|
|
922 ngx_http_core_find_location(ngx_http_request_t *r,
|
|
923 ngx_array_t *locations, size_t len)
|
0
|
924 {
|
|
925 ngx_int_t n, rc;
|
16
|
926 ngx_uint_t i, found, noregex;
|
0
|
927 ngx_http_core_loc_conf_t *clcf, **clcfp;
|
|
928
|
104
|
929 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
930 "find location for \"%V\"", &r->uri);
|
0
|
931
|
|
932 found = 0;
|
16
|
933 noregex = 0;
|
0
|
934
|
|
935 clcfp = locations->elts;
|
|
936 for (i = 0; i < locations->nelts; i++) {
|
|
937
|
4
|
938 #if (NGX_PCRE)
|
0
|
939 if (clcfp[i]->regex) {
|
|
940 break;
|
|
941 }
|
|
942 #endif
|
|
943
|
34
|
944 if (clcfp[i]->noname) {
|
|
945 break;
|
|
946 }
|
|
947
|
0
|
948 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
10
|
949 "find location: %s\"%V\"",
|
|
950 clcfp[i]->exact_match ? "= " : "", &clcfp[i]->name);
|
0
|
951
|
|
952 if (clcfp[i]->auto_redirect
|
|
953 && r->uri.len == clcfp[i]->name.len - 1
|
|
954 && ngx_strncmp(r->uri.data, clcfp[i]->name.data,
|
274
|
955 clcfp[i]->name.len - 1)
|
|
956 == 0)
|
0
|
957 {
|
|
958 /* the locations are lexicographically sorted */
|
|
959
|
|
960 r->loc_conf = clcfp[i]->loc_conf;
|
|
961
|
|
962 return NGX_HTTP_LOCATION_AUTO_REDIRECT;
|
|
963 }
|
|
964
|
|
965 if (r->uri.len < clcfp[i]->name.len) {
|
|
966 continue;
|
|
967 }
|
|
968
|
|
969 n = ngx_strncmp(r->uri.data, clcfp[i]->name.data, clcfp[i]->name.len);
|
|
970
|
|
971 if (n < 0) {
|
|
972 /* the locations are lexicographically sorted */
|
|
973 break;
|
|
974 }
|
|
975
|
|
976 if (n == 0) {
|
34
|
977 if (clcfp[i]->exact_match) {
|
|
978
|
|
979 if (r->uri.len == clcfp[i]->name.len) {
|
|
980 r->loc_conf = clcfp[i]->loc_conf;
|
|
981 return NGX_HTTP_LOCATION_EXACT;
|
|
982 }
|
|
983
|
|
984 continue;
|
0
|
985 }
|
|
986
|
|
987 if (len > clcfp[i]->name.len) {
|
|
988 /* the previous match is longer */
|
|
989 break;
|
|
990 }
|
|
991
|
|
992 r->loc_conf = clcfp[i]->loc_conf;
|
16
|
993 noregex = clcfp[i]->noregex;
|
0
|
994 found = 1;
|
|
995 }
|
|
996 }
|
|
997
|
|
998 if (found) {
|
|
999 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1000
|
|
1001 if (clcf->locations.nelts) {
|
34
|
1002 rc = ngx_http_core_find_location(r, &clcf->locations, len);
|
0
|
1003
|
|
1004 if (rc != NGX_OK) {
|
|
1005 return rc;
|
|
1006 }
|
|
1007 }
|
|
1008 }
|
|
1009
|
4
|
1010 #if (NGX_PCRE)
|
0
|
1011
|
16
|
1012 if (noregex) {
|
|
1013 return NGX_HTTP_LOCATION_NOREGEX;
|
|
1014 }
|
|
1015
|
0
|
1016 /* regex matches */
|
|
1017
|
|
1018 for (/* void */; i < locations->nelts; i++) {
|
|
1019
|
|
1020 if (!clcfp[i]->regex) {
|
|
1021 continue;
|
|
1022 }
|
|
1023
|
34
|
1024 if (clcfp[i]->noname) {
|
|
1025 break;
|
|
1026 }
|
|
1027
|
0
|
1028 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
10
|
1029 "find location: ~ \"%V\"", &clcfp[i]->name);
|
0
|
1030
|
|
1031 n = ngx_regex_exec(clcfp[i]->regex, &r->uri, NULL, 0);
|
|
1032
|
30
|
1033 if (n == NGX_REGEX_NO_MATCHED) {
|
0
|
1034 continue;
|
|
1035 }
|
|
1036
|
|
1037 if (n < 0) {
|
|
1038 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
|
1039 ngx_regex_exec_n
|
10
|
1040 " failed: %d on \"%V\" using \"%V\"",
|
|
1041 n, &r->uri, &clcfp[i]->name);
|
0
|
1042 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
1043 }
|
|
1044
|
|
1045 /* match */
|
|
1046
|
|
1047 r->loc_conf = clcfp[i]->loc_conf;
|
|
1048
|
|
1049 return NGX_HTTP_LOCATION_REGEX;
|
|
1050 }
|
|
1051
|
4
|
1052 #endif /* NGX_PCRE */
|
0
|
1053
|
|
1054 return NGX_OK;
|
|
1055 }
|
|
1056
|
|
1057
|
36
|
1058 ngx_int_t
|
|
1059 ngx_http_set_content_type(ngx_http_request_t *r)
|
0
|
1060 {
|
34
|
1061 u_char c, *p, *exten;
|
138
|
1062 ngx_str_t *type;
|
198
|
1063 ngx_uint_t i, hash;
|
0
|
1064 ngx_http_core_loc_conf_t *clcf;
|
|
1065
|
222
|
1066 if (r->headers_out.content_type.len) {
|
|
1067 return NGX_OK;
|
|
1068 }
|
|
1069
|
0
|
1070 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1071
|
|
1072 if (r->exten.len) {
|
34
|
1073
|
198
|
1074 hash = 0;
|
|
1075
|
|
1076 for (i = 0; i < r->exten.len; i++) {
|
|
1077 c = r->exten.data[i];
|
|
1078
|
|
1079 if (c >= 'A' && c <= 'Z') {
|
|
1080
|
50
|
1081 p = ngx_palloc(r->pool, r->exten.len);
|
|
1082 if (p == NULL) {
|
34
|
1083 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
1084 }
|
|
1085
|
198
|
1086 hash = 0;
|
34
|
1087 exten = p;
|
|
1088
|
|
1089 for (i = 0; i < r->exten.len; i++) {
|
198
|
1090 c = ngx_tolower(r->exten.data[i]);
|
|
1091 hash = ngx_hash(hash, c);
|
|
1092 *p++ = c;
|
34
|
1093 }
|
|
1094
|
|
1095 r->exten.data = exten;
|
198
|
1096
|
|
1097 break;
|
34
|
1098 }
|
|
1099
|
198
|
1100 hash = ngx_hash(hash, c);
|
34
|
1101 }
|
|
1102
|
198
|
1103 type = ngx_hash_find(&clcf->types_hash, hash,
|
138
|
1104 r->exten.data, r->exten.len);
|
|
1105
|
|
1106 if (type) {
|
206
|
1107 r->headers_out.content_type_len = type->len;
|
138
|
1108 r->headers_out.content_type = *type;
|
206
|
1109
|
138
|
1110 return NGX_OK;
|
0
|
1111 }
|
|
1112 }
|
|
1113
|
206
|
1114 r->headers_out.content_type_len = clcf->default_type.len;
|
138
|
1115 r->headers_out.content_type = clcf->default_type;
|
0
|
1116
|
|
1117 return NGX_OK;
|
|
1118 }
|
|
1119
|
|
1120
|
36
|
1121 ngx_int_t
|
|
1122 ngx_http_set_exten(ngx_http_request_t *r)
|
0
|
1123 {
|
|
1124 ngx_int_t i;
|
|
1125
|
|
1126 r->exten.len = 0;
|
|
1127 r->exten.data = NULL;
|
|
1128
|
|
1129 for (i = r->uri.len - 1; i > 1; i--) {
|
|
1130 if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {
|
198
|
1131
|
0
|
1132 r->exten.len = r->uri.len - i - 1;
|
198
|
1133 r->exten.data = &r->uri.data[i + 1];
|
0
|
1134
|
|
1135 break;
|
|
1136
|
|
1137 } else if (r->uri.data[i] == '/') {
|
|
1138 break;
|
|
1139 }
|
|
1140 }
|
|
1141
|
|
1142 return NGX_OK;
|
|
1143 }
|
|
1144
|
|
1145
|
36
|
1146 ngx_int_t
|
106
|
1147 ngx_http_send_header(ngx_http_request_t *r)
|
|
1148 {
|
|
1149 if (r->err_status) {
|
|
1150 r->headers_out.status = r->err_status;
|
|
1151 r->headers_out.status_line.len = 0;
|
|
1152 }
|
|
1153
|
|
1154 return ngx_http_top_header_filter(r);
|
|
1155 }
|
|
1156
|
|
1157
|
|
1158 ngx_int_t
|
|
1159 ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
|
1160 {
|
|
1161 ngx_int_t rc;
|
|
1162
|
132
|
1163 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1164 "http output filter \"%V?%V\"", &r->uri, &r->args);
|
106
|
1165
|
|
1166 rc = ngx_http_top_body_filter(r, in);
|
|
1167
|
|
1168 if (rc == NGX_ERROR) {
|
|
1169 /* NGX_ERROR may be returned by any filter */
|
132
|
1170 r->connection->error = 1;
|
106
|
1171 }
|
|
1172
|
|
1173 return rc;
|
|
1174 }
|
|
1175
|
|
1176
|
|
1177 u_char *
|
|
1178 ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,
|
248
|
1179 size_t *root_length, size_t reserved)
|
106
|
1180 {
|
172
|
1181 u_char *last;
|
|
1182 size_t alias;
|
|
1183 ngx_http_core_loc_conf_t *clcf;
|
106
|
1184
|
|
1185 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1186
|
|
1187 alias = clcf->alias ? clcf->name.len : 0;
|
|
1188
|
152
|
1189 if (alias && !r->valid_location) {
|
|
1190 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
|
1191 "\"alias\" could not be used in location \"%V\" "
|
|
1192 "where URI was rewritten", &clcf->name);
|
|
1193 return NULL;
|
|
1194 }
|
|
1195
|
172
|
1196 reserved += r->uri.len - alias + 1;
|
|
1197
|
144
|
1198 if (clcf->root_lengths == NULL) {
|
|
1199
|
248
|
1200 *root_length = clcf->root.len;
|
144
|
1201
|
172
|
1202 path->len = clcf->root.len + reserved;
|
144
|
1203
|
|
1204 path->data = ngx_palloc(r->pool, path->len);
|
|
1205 if (path->data == NULL) {
|
|
1206 return NULL;
|
|
1207 }
|
|
1208
|
|
1209 last = ngx_copy(path->data, clcf->root.data, clcf->root.len);
|
172
|
1210
|
|
1211 } else {
|
216
|
1212 if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved,
|
220
|
1213 clcf->root_values->elts)
|
216
|
1214 == NULL)
|
|
1215 {
|
|
1216 return NULL;
|
|
1217 }
|
|
1218
|
|
1219 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, path) == NGX_ERROR) {
|
172
|
1220 return NULL;
|
|
1221 }
|
|
1222
|
248
|
1223 *root_length = path->len - reserved;
|
|
1224 last = path->data + *root_length;
|
144
|
1225 }
|
|
1226
|
172
|
1227 last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1);
|
106
|
1228
|
|
1229 return last;
|
|
1230 }
|
|
1231
|
|
1232
|
|
1233 ngx_int_t
|
88
|
1234 ngx_http_auth_basic_user(ngx_http_request_t *r)
|
|
1235 {
|
|
1236 ngx_str_t auth, encoded;
|
|
1237 ngx_uint_t len;
|
|
1238
|
|
1239 if (r->headers_in.user.len == 0 && r->headers_in.user.data != NULL) {
|
|
1240 return NGX_DECLINED;
|
|
1241 }
|
|
1242
|
|
1243 if (r->headers_in.authorization == NULL) {
|
|
1244 r->headers_in.user.data = (u_char *) "";
|
|
1245 return NGX_DECLINED;
|
|
1246 }
|
|
1247
|
|
1248 encoded = r->headers_in.authorization->value;
|
|
1249
|
|
1250 if (encoded.len < sizeof("Basic ") - 1
|
286
|
1251 || ngx_strncasecmp(encoded.data, (u_char *) "Basic ",
|
|
1252 sizeof("Basic ") - 1)
|
|
1253 != 0)
|
88
|
1254 {
|
|
1255 r->headers_in.user.data = (u_char *) "";
|
|
1256 return NGX_DECLINED;
|
|
1257 }
|
|
1258
|
|
1259 encoded.len -= sizeof("Basic ") - 1;
|
|
1260 encoded.data += sizeof("Basic ") - 1;
|
|
1261
|
|
1262 while (encoded.len && encoded.data[0] == ' ') {
|
|
1263 encoded.len--;
|
|
1264 encoded.data++;
|
|
1265 }
|
|
1266
|
|
1267 if (encoded.len == 0) {
|
|
1268 r->headers_in.user.data = (u_char *) "";
|
|
1269 return NGX_DECLINED;
|
|
1270 }
|
126
|
1271
|
88
|
1272 auth.len = ngx_base64_decoded_length(encoded.len);
|
126
|
1273 auth.data = ngx_palloc(r->pool, auth.len + 1);
|
88
|
1274 if (auth.data == NULL) {
|
|
1275 return NGX_ERROR;
|
|
1276 }
|
|
1277
|
|
1278 if (ngx_decode_base64(&auth, &encoded) != NGX_OK) {
|
|
1279 r->headers_in.user.data = (u_char *) "";
|
|
1280 return NGX_DECLINED;
|
|
1281 }
|
126
|
1282
|
88
|
1283 auth.data[auth.len] = '\0';
|
126
|
1284
|
|
1285 for (len = 0; len < auth.len; len++) {
|
88
|
1286 if (auth.data[len] == ':') {
|
|
1287 break;
|
|
1288 }
|
|
1289 }
|
126
|
1290
|
122
|
1291 if (len == 0 || len == auth.len) {
|
88
|
1292 r->headers_in.user.data = (u_char *) "";
|
|
1293 return NGX_DECLINED;
|
|
1294 }
|
|
1295
|
|
1296 r->headers_in.user.len = len;
|
|
1297 r->headers_in.user.data = auth.data;
|
|
1298 r->headers_in.passwd.len = auth.len - len - 1;
|
|
1299 r->headers_in.passwd.data = &auth.data[len + 1];
|
|
1300
|
|
1301 return NGX_OK;
|
|
1302 }
|
|
1303
|
|
1304
|
|
1305 ngx_int_t
|
58
|
1306 ngx_http_subrequest(ngx_http_request_t *r,
|
244
|
1307 ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **psr,
|
248
|
1308 ngx_http_post_subrequest_t *ps, ngx_uint_t flags)
|
58
|
1309 {
|
132
|
1310 ngx_connection_t *c;
|
58
|
1311 ngx_http_request_t *sr;
|
214
|
1312 ngx_http_log_ctx_t *ctx;
|
58
|
1313 ngx_http_core_srv_conf_t *cscf;
|
|
1314 ngx_http_postponed_request_t *pr, *p;
|
|
1315
|
206
|
1316 r->main->subrequests--;
|
|
1317
|
|
1318 if (r->main->subrequests == 0) {
|
|
1319 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
228
|
1320 "subrequests cycle while processing \"%V\"", uri);
|
256
|
1321 r->main->subrequests = 1;
|
206
|
1322 return NGX_ERROR;
|
|
1323 }
|
|
1324
|
58
|
1325 sr = ngx_pcalloc(r->pool, sizeof(ngx_http_request_t));
|
|
1326 if (sr == NULL) {
|
194
|
1327 return NGX_ERROR;
|
58
|
1328 }
|
|
1329
|
|
1330 sr->signature = NGX_HTTP_MODULE;
|
132
|
1331
|
|
1332 c = r->connection;
|
|
1333 sr->connection = c;
|
58
|
1334
|
|
1335 sr->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
|
|
1336 if (sr->ctx == NULL) {
|
194
|
1337 return NGX_ERROR;
|
58
|
1338 }
|
|
1339
|
|
1340 if (ngx_list_init(&sr->headers_out.headers, r->pool, 20,
|
130
|
1341 sizeof(ngx_table_elt_t))
|
|
1342 == NGX_ERROR)
|
58
|
1343 {
|
194
|
1344 return NGX_ERROR;
|
58
|
1345 }
|
|
1346
|
|
1347 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
|
1348 sr->main_conf = cscf->ctx->main_conf;
|
|
1349 sr->srv_conf = cscf->ctx->srv_conf;
|
|
1350 sr->loc_conf = cscf->ctx->loc_conf;
|
|
1351
|
|
1352 sr->pool = r->pool;
|
|
1353
|
|
1354 sr->headers_in = r->headers_in;
|
|
1355
|
126
|
1356 ngx_http_clear_content_length(sr);
|
|
1357 ngx_http_clear_accept_ranges(sr);
|
|
1358 ngx_http_clear_last_modified(sr);
|
58
|
1359
|
|
1360 sr->request_body = r->request_body;
|
|
1361
|
|
1362 sr->method = NGX_HTTP_GET;
|
|
1363 sr->http_version = r->http_version;
|
|
1364
|
|
1365 sr->request_line = r->request_line;
|
|
1366 sr->uri = *uri;
|
122
|
1367
|
58
|
1368 if (args) {
|
|
1369 sr->args = *args;
|
|
1370 }
|
122
|
1371
|
132
|
1372 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
|
1373 "http subrequest \"%V?%V\"", uri, &sr->args);
|
|
1374
|
248
|
1375 sr->zero_in_uri = (flags & NGX_HTTP_ZERO_IN_URI) != 0;
|
|
1376 sr->subrequest_in_memory = (flags & NGX_HTTP_SUBREQUEST_IN_MEMORY) != 0;
|
122
|
1377
|
58
|
1378 sr->unparsed_uri = r->unparsed_uri;
|
|
1379 sr->method_name = r->method_name;
|
|
1380 sr->http_protocol = r->http_protocol;
|
|
1381
|
|
1382 if (ngx_http_set_exten(sr) != NGX_OK) {
|
194
|
1383 return NGX_ERROR;
|
58
|
1384 }
|
|
1385
|
102
|
1386 sr->main = r->main;
|
58
|
1387 sr->parent = r;
|
248
|
1388 sr->post_subrequest = ps;
|
58
|
1389 sr->read_event_handler = ngx_http_request_empty_handler;
|
|
1390 sr->write_event_handler = ngx_http_request_empty_handler;
|
|
1391
|
132
|
1392 if (c->data == r) {
|
|
1393 c->data = sr;
|
58
|
1394 }
|
|
1395
|
|
1396 sr->in_addr = r->in_addr;
|
|
1397 sr->port = r->port;
|
|
1398 sr->port_text = r->port_text;
|
|
1399 sr->server_name = r->server_name;
|
|
1400
|
|
1401 sr->variables = r->variables;
|
|
1402
|
|
1403 sr->log_handler = r->log_handler;
|
|
1404
|
|
1405 pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t));
|
|
1406 if (pr == NULL) {
|
194
|
1407 return NGX_ERROR;
|
58
|
1408 }
|
|
1409
|
|
1410 pr->request = sr;
|
|
1411 pr->out = NULL;
|
|
1412 pr->next = NULL;
|
|
1413
|
|
1414 if (r->postponed) {
|
|
1415 for (p = r->postponed; p->next; p = p->next) { /* void */ }
|
|
1416 p->next = pr;
|
|
1417
|
|
1418 } else {
|
|
1419 r->postponed = pr;
|
|
1420 }
|
|
1421
|
214
|
1422 ctx = c->log->data;
|
|
1423 ctx->current_request = sr;
|
|
1424
|
58
|
1425 sr->internal = 1;
|
146
|
1426 sr->fast_subrequest = 1;
|
58
|
1427
|
92
|
1428 sr->discard_body = r->discard_body;
|
62
|
1429 sr->main_filter_need_in_memory = r->main_filter_need_in_memory;
|
|
1430
|
200
|
1431 sr->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1;
|
|
1432
|
58
|
1433 ngx_http_handler(sr);
|
|
1434
|
132
|
1435 if (!c->destroyed) {
|
|
1436 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
|
1437 "http subrequest done \"%V?%V\"", uri, &sr->args);
|
194
|
1438
|
256
|
1439 r->main->subrequests++;
|
|
1440
|
244
|
1441 *psr = sr;
|
|
1442
|
194
|
1443 if (sr->fast_subrequest) {
|
|
1444 sr->fast_subrequest = 0;
|
|
1445
|
|
1446 if (sr->done) {
|
|
1447 return NGX_OK;
|
|
1448 }
|
|
1449 }
|
|
1450
|
|
1451 return NGX_AGAIN;
|
132
|
1452 }
|
58
|
1453
|
248
|
1454 return NGX_DONE;
|
58
|
1455 }
|
|
1456
|
|
1457
|
|
1458 ngx_int_t
|
36
|
1459 ngx_http_internal_redirect(ngx_http_request_t *r,
|
|
1460 ngx_str_t *uri, ngx_str_t *args)
|
0
|
1461 {
|
36
|
1462 ngx_http_core_srv_conf_t *cscf;
|
|
1463
|
226
|
1464 r->uri_changes--;
|
|
1465
|
|
1466 if (r->uri_changes == 0) {
|
|
1467 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
228
|
1468 "rewrite or internal redirection cycle "
|
|
1469 "while internal redirect to \"%V\"", uri);
|
|
1470
|
226
|
1471 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
1472 return NGX_DONE;
|
|
1473 }
|
|
1474
|
10
|
1475 r->uri = *uri;
|
0
|
1476
|
|
1477 if (args) {
|
10
|
1478 r->args = *args;
|
58
|
1479
|
|
1480 } else {
|
|
1481 r->args.len = 0;
|
|
1482 r->args.data = NULL;
|
0
|
1483 }
|
|
1484
|
132
|
1485 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1486 "internal redirect: \"%V?%V\"", uri, &r->args);
|
|
1487
|
0
|
1488 if (ngx_http_set_exten(r) != NGX_OK) {
|
226
|
1489 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
1490 return NGX_DONE;
|
0
|
1491 }
|
|
1492
|
224
|
1493 /* clear the modules contexts */
|
|
1494 ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
|
0
|
1495
|
36
|
1496 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
|
1497 r->loc_conf = cscf->ctx->loc_conf;
|
|
1498
|
84
|
1499 ngx_http_update_location_config(r);
|
|
1500
|
58
|
1501 r->internal = 1;
|
|
1502
|
0
|
1503 ngx_http_handler(r);
|
|
1504
|
|
1505 return NGX_DONE;
|
|
1506 }
|
|
1507
|
|
1508
|
118
|
1509 ngx_http_cleanup_t *
|
|
1510 ngx_http_cleanup_add(ngx_http_request_t *r, size_t size)
|
0
|
1511 {
|
118
|
1512 ngx_http_cleanup_t *cln;
|
|
1513
|
|
1514 r = r->main;
|
|
1515
|
|
1516 cln = ngx_palloc(r->pool, sizeof(ngx_http_cleanup_t));
|
|
1517 if (cln == NULL) {
|
|
1518 return NULL;
|
0
|
1519 }
|
|
1520
|
118
|
1521 if (size) {
|
|
1522 cln->data = ngx_palloc(r->pool, size);
|
|
1523 if (cln->data == NULL) {
|
|
1524 return NULL;
|
|
1525 }
|
|
1526
|
|
1527 } else {
|
|
1528 cln->data = NULL;
|
|
1529 }
|
|
1530
|
|
1531 cln->handler = NULL;
|
|
1532 cln->next = r->cleanup;
|
|
1533
|
|
1534 r->cleanup = cln;
|
|
1535
|
|
1536 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1537 "http cleanup add: %p", cln);
|
|
1538
|
|
1539 return cln;
|
0
|
1540 }
|
|
1541
|
|
1542
|
36
|
1543 static char *
|
|
1544 ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
0
|
1545 {
|
36
|
1546 char *rv;
|
|
1547 void *mconf;
|
70
|
1548 ngx_uint_t m;
|
|
1549 ngx_conf_t pcf;
|
36
|
1550 ngx_http_module_t *module;
|
|
1551 ngx_http_conf_ctx_t *ctx, *http_ctx;
|
|
1552 ngx_http_core_srv_conf_t *cscf, **cscfp;
|
|
1553 ngx_http_core_main_conf_t *cmcf;
|
|
1554
|
50
|
1555 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
|
|
1556 if (ctx == NULL) {
|
36
|
1557 return NGX_CONF_ERROR;
|
|
1558 }
|
0
|
1559
|
|
1560 http_ctx = cf->ctx;
|
|
1561 ctx->main_conf = http_ctx->main_conf;
|
|
1562
|
|
1563 /* the server{}'s srv_conf */
|
|
1564
|
36
|
1565 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
1566 if (ctx->srv_conf == NULL) {
|
|
1567 return NGX_CONF_ERROR;
|
|
1568 }
|
0
|
1569
|
|
1570 /* the server{}'s loc_conf */
|
|
1571
|
36
|
1572 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
1573 if (ctx->loc_conf == NULL) {
|
|
1574 return NGX_CONF_ERROR;
|
|
1575 }
|
0
|
1576
|
|
1577 for (m = 0; ngx_modules[m]; m++) {
|
|
1578 if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
|
|
1579 continue;
|
|
1580 }
|
|
1581
|
|
1582 module = ngx_modules[m]->ctx;
|
|
1583
|
|
1584 if (module->create_srv_conf) {
|
50
|
1585 mconf = module->create_srv_conf(cf);
|
|
1586 if (mconf == NULL) {
|
36
|
1587 return NGX_CONF_ERROR;
|
|
1588 }
|
|
1589
|
|
1590 ctx->srv_conf[ngx_modules[m]->ctx_index] = mconf;
|
0
|
1591 }
|
|
1592
|
|
1593 if (module->create_loc_conf) {
|
50
|
1594 mconf = module->create_loc_conf(cf);
|
|
1595 if (mconf == NULL) {
|
36
|
1596 return NGX_CONF_ERROR;
|
|
1597 }
|
|
1598
|
|
1599 ctx->loc_conf[ngx_modules[m]->ctx_index] = mconf;
|
0
|
1600 }
|
|
1601 }
|
|
1602
|
36
|
1603
|
|
1604 /* the server configuration context */
|
0
|
1605
|
|
1606 cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
|
|
1607 cscf->ctx = ctx;
|
|
1608
|
36
|
1609
|
0
|
1610 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
|
36
|
1611
|
50
|
1612 cscfp = ngx_array_push(&cmcf->servers);
|
|
1613 if (cscfp == NULL) {
|
36
|
1614 return NGX_CONF_ERROR;
|
|
1615 }
|
|
1616
|
0
|
1617 *cscfp = cscf;
|
|
1618
|
36
|
1619
|
0
|
1620 /* parse inside server{} */
|
|
1621
|
70
|
1622 pcf = *cf;
|
0
|
1623 cf->ctx = ctx;
|
|
1624 cf->cmd_type = NGX_HTTP_SRV_CONF;
|
34
|
1625
|
0
|
1626 rv = ngx_conf_parse(cf, NULL);
|
34
|
1627
|
70
|
1628 *cf = pcf;
|
0
|
1629
|
|
1630 if (rv != NGX_CONF_OK) {
|
|
1631 return rv;
|
|
1632 }
|
|
1633
|
|
1634 ngx_qsort(cscf->locations.elts, (size_t) cscf->locations.nelts,
|
34
|
1635 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations);
|
0
|
1636
|
|
1637 return rv;
|
|
1638 }
|
|
1639
|
|
1640
|
36
|
1641 static char *
|
|
1642 ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
0
|
1643 {
|
|
1644 char *rv;
|
|
1645 ngx_int_t m;
|
|
1646 ngx_str_t *value;
|
34
|
1647 ngx_conf_t save;
|
0
|
1648 ngx_http_module_t *module;
|
|
1649 ngx_http_conf_ctx_t *ctx, *pctx;
|
|
1650 ngx_http_core_srv_conf_t *cscf;
|
|
1651 ngx_http_core_loc_conf_t *clcf, *pclcf, **clcfp;
|
4
|
1652 #if (NGX_PCRE)
|
0
|
1653 ngx_str_t err;
|
|
1654 u_char errstr[NGX_MAX_CONF_ERRSTR];
|
|
1655 #endif
|
|
1656
|
50
|
1657 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
|
|
1658 if (ctx == NULL) {
|
0
|
1659 return NGX_CONF_ERROR;
|
|
1660 }
|
|
1661
|
|
1662 pctx = cf->ctx;
|
|
1663 ctx->main_conf = pctx->main_conf;
|
|
1664 ctx->srv_conf = pctx->srv_conf;
|
|
1665
|
|
1666 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
1667 if (ctx->loc_conf == NULL) {
|
|
1668 return NGX_CONF_ERROR;
|
|
1669 }
|
|
1670
|
|
1671 for (m = 0; ngx_modules[m]; m++) {
|
|
1672 if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
|
|
1673 continue;
|
|
1674 }
|
|
1675
|
|
1676 module = ngx_modules[m]->ctx;
|
|
1677
|
|
1678 if (module->create_loc_conf) {
|
|
1679 ctx->loc_conf[ngx_modules[m]->ctx_index] =
|
|
1680 module->create_loc_conf(cf);
|
|
1681 if (ctx->loc_conf[ngx_modules[m]->ctx_index] == NULL) {
|
|
1682 return NGX_CONF_ERROR;
|
|
1683 }
|
|
1684 }
|
|
1685 }
|
|
1686
|
|
1687 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
|
|
1688 clcf->loc_conf = ctx->loc_conf;
|
|
1689
|
|
1690 value = cf->args->elts;
|
|
1691
|
|
1692 if (cf->args->nelts == 3) {
|
|
1693 if (value[1].len == 1 && value[1].data[0] == '=') {
|
12
|
1694 clcf->name = value[2];
|
0
|
1695 clcf->exact_match = 1;
|
|
1696
|
16
|
1697 } else if (value[1].len == 2
|
|
1698 && value[1].data[0] == '^'
|
|
1699 && value[1].data[1] == '~')
|
|
1700 {
|
|
1701 clcf->name = value[2];
|
|
1702 clcf->noregex = 1;
|
|
1703
|
0
|
1704 } else if ((value[1].len == 1 && value[1].data[0] == '~')
|
|
1705 || (value[1].len == 2
|
|
1706 && value[1].data[0] == '~'
|
|
1707 && value[1].data[1] == '*'))
|
|
1708 {
|
4
|
1709 #if (NGX_PCRE)
|
0
|
1710 err.len = NGX_MAX_CONF_ERRSTR;
|
|
1711 err.data = errstr;
|
|
1712
|
|
1713 clcf->regex = ngx_regex_compile(&value[2],
|
|
1714 value[1].len == 2 ? NGX_REGEX_CASELESS: 0,
|
|
1715 cf->pool, &err);
|
|
1716
|
|
1717 if (clcf->regex == NULL) {
|
|
1718 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
|
|
1719 return NGX_CONF_ERROR;
|
|
1720 }
|
|
1721
|
|
1722 clcf->name = value[2];
|
|
1723 #else
|
|
1724 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
1725 "the using of the regex \"%V\" "
|
|
1726 "requires PCRE library", &value[2]);
|
0
|
1727 return NGX_CONF_ERROR;
|
|
1728 #endif
|
|
1729
|
|
1730 } else {
|
|
1731 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
1732 "invalid location modifier \"%V\"", &value[1]);
|
0
|
1733 return NGX_CONF_ERROR;
|
|
1734 }
|
|
1735
|
|
1736 } else {
|
12
|
1737 clcf->name = value[1];
|
0
|
1738 }
|
|
1739
|
|
1740 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
|
|
1741
|
|
1742 if (pclcf->name.len == 0) {
|
|
1743 cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
|
50
|
1744
|
|
1745 clcfp = ngx_array_push(&cscf->locations);
|
|
1746 if (clcfp == NULL) {
|
0
|
1747 return NGX_CONF_ERROR;
|
|
1748 }
|
|
1749
|
|
1750 } else {
|
34
|
1751 #if 0
|
0
|
1752 clcf->prev_location = pclcf;
|
34
|
1753 #endif
|
0
|
1754
|
|
1755 if (pclcf->exact_match) {
|
|
1756 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
1757 "location \"%V\" could not be inside "
|
|
1758 "the exact location \"%V\"",
|
|
1759 &clcf->name, &pclcf->name);
|
0
|
1760 return NGX_CONF_ERROR;
|
|
1761 }
|
|
1762
|
4
|
1763 #if (NGX_PCRE)
|
0
|
1764 if (clcf->regex == NULL
|
|
1765 && ngx_strncmp(clcf->name.data, pclcf->name.data, pclcf->name.len)
|
|
1766 != 0)
|
|
1767 #else
|
|
1768 if (ngx_strncmp(clcf->name.data, pclcf->name.data, pclcf->name.len)
|
|
1769 != 0)
|
|
1770 #endif
|
|
1771 {
|
|
1772 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
1773 "location \"%V\" is outside location \"%V\"",
|
|
1774 &clcf->name, &pclcf->name);
|
0
|
1775 return NGX_CONF_ERROR;
|
|
1776 }
|
|
1777
|
|
1778 if (pclcf->locations.elts == NULL) {
|
50
|
1779 if (ngx_array_init(&pclcf->locations, cf->pool, 4, sizeof(void *))
|
|
1780 != NGX_OK)
|
|
1781 {
|
|
1782 return NGX_CONF_ERROR;
|
|
1783 }
|
0
|
1784 }
|
|
1785
|
50
|
1786 clcfp = ngx_array_push(&pclcf->locations);
|
|
1787 if (clcfp == NULL) {
|
0
|
1788 return NGX_CONF_ERROR;
|
|
1789 }
|
|
1790 }
|
|
1791
|
|
1792 *clcfp = clcf;
|
|
1793
|
34
|
1794 save = *cf;
|
0
|
1795 cf->ctx = ctx;
|
|
1796 cf->cmd_type = NGX_HTTP_LOC_CONF;
|
34
|
1797
|
0
|
1798 rv = ngx_conf_parse(cf, NULL);
|
34
|
1799
|
|
1800 *cf = save;
|
|
1801
|
|
1802 if (rv != NGX_CONF_OK) {
|
|
1803 return rv;
|
|
1804 }
|
|
1805
|
|
1806 ngx_qsort(clcf->locations.elts, (size_t) clcf->locations.nelts,
|
|
1807 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations);
|
0
|
1808
|
|
1809 return rv;
|
|
1810 }
|
|
1811
|
|
1812
|
52
|
1813 static int ngx_libc_cdecl
|
36
|
1814 ngx_http_core_cmp_locations(const void *one, const void *two)
|
34
|
1815 {
|
|
1816 ngx_int_t rc;
|
|
1817 ngx_http_core_loc_conf_t *first, *second;
|
|
1818
|
|
1819 first = *(ngx_http_core_loc_conf_t **) one;
|
|
1820 second = *(ngx_http_core_loc_conf_t **) two;
|
|
1821
|
|
1822 if (first->noname && !second->noname) {
|
|
1823 /* shift no named locations to the end */
|
|
1824 return 1;
|
|
1825 }
|
|
1826
|
|
1827 if (!first->noname && second->noname) {
|
|
1828 /* shift no named locations to the end */
|
|
1829 return -1;
|
|
1830 }
|
|
1831
|
|
1832 if (first->noname || second->noname) {
|
|
1833 /* do not sort no named locations */
|
|
1834 return 0;
|
|
1835 }
|
|
1836
|
|
1837 #if (NGX_PCRE)
|
|
1838
|
|
1839 if (first->regex && !second->regex) {
|
|
1840 /* shift the regex matches to the end */
|
|
1841 return 1;
|
|
1842 }
|
|
1843
|
|
1844 if (!first->regex && second->regex) {
|
|
1845 /* shift the regex matches to the end */
|
|
1846 return -1;
|
|
1847 }
|
|
1848
|
|
1849 if (first->regex || second->regex) {
|
|
1850 /* do not sort the regex matches */
|
|
1851 return 0;
|
|
1852 }
|
|
1853
|
|
1854 #endif
|
|
1855
|
|
1856 rc = ngx_strcmp(first->name.data, second->name.data);
|
|
1857
|
|
1858 if (rc == 0 && second->exact_match) {
|
|
1859 /* an exact match must be before the same inclusive one */
|
|
1860 return 1;
|
|
1861 }
|
|
1862
|
|
1863 return (int) rc;
|
|
1864 }
|
|
1865
|
|
1866
|
36
|
1867 static char *
|
|
1868 ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
1869 {
|
186
|
1870 ngx_http_core_loc_conf_t *lcf = conf;
|
|
1871
|
0
|
1872 char *rv;
|
34
|
1873 ngx_conf_t save;
|
0
|
1874
|
186
|
1875 if (lcf->types == NULL) {
|
|
1876 lcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t));
|
|
1877 if (lcf->types == NULL) {
|
|
1878 return NGX_CONF_ERROR;
|
|
1879 }
|
|
1880 }
|
|
1881
|
34
|
1882 save = *cf;
|
|
1883 cf->handler = ngx_http_core_type;
|
0
|
1884 cf->handler_conf = conf;
|
34
|
1885
|
0
|
1886 rv = ngx_conf_parse(cf, NULL);
|
34
|
1887
|
|
1888 *cf = save;
|
0
|
1889
|
|
1890 return rv;
|
|
1891 }
|
|
1892
|
|
1893
|
36
|
1894 static char *
|
|
1895 ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
|
0
|
1896 {
|
|
1897 ngx_http_core_loc_conf_t *lcf = conf;
|
|
1898
|
294
|
1899 ngx_str_t *value, *content_type, *old, file;
|
138
|
1900 ngx_uint_t i, n;
|
|
1901 ngx_hash_key_t *type;
|
0
|
1902
|
294
|
1903 value = cf->args->elts;
|
|
1904
|
|
1905 if (ngx_strcmp(value[0].data, "include") == 0) {
|
|
1906 file = value[1];
|
|
1907
|
|
1908 if (ngx_conf_full_name(cf->cycle, &file) == NGX_ERROR){
|
|
1909 return NGX_CONF_ERROR;
|
|
1910 }
|
|
1911
|
|
1912 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
|
|
1913
|
|
1914 return ngx_conf_parse(cf, &file);
|
|
1915 }
|
|
1916
|
138
|
1917 content_type = ngx_palloc(cf->pool, sizeof(ngx_str_t));
|
|
1918 if (content_type == NULL) {
|
|
1919 return NGX_CONF_ERROR;
|
0
|
1920 }
|
|
1921
|
138
|
1922 *content_type = value[0];
|
0
|
1923
|
|
1924 for (i = 1; i < cf->args->nelts; i++) {
|
138
|
1925
|
|
1926 for (n = 0; n < value[i].len; n++) {
|
|
1927 value[i].data[n] = ngx_tolower(value[i].data[n]);
|
|
1928 }
|
|
1929
|
|
1930 type = lcf->types->elts;
|
|
1931 for (n = 0; n < lcf->types->nelts; n++) {
|
|
1932 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) {
|
|
1933 old = type[n].value;
|
|
1934 type[n].value = content_type;
|
|
1935
|
|
1936 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
1937 "duplicate extention \"%V\", "
|
|
1938 "content type: \"%V\", "
|
|
1939 "old content type: \"%V\"",
|
|
1940 &value[i], content_type, old);
|
|
1941 continue;
|
|
1942 }
|
|
1943 }
|
|
1944
|
|
1945
|
|
1946 type = ngx_array_push(lcf->types);
|
50
|
1947 if (type == NULL) {
|
0
|
1948 return NGX_CONF_ERROR;
|
|
1949 }
|
|
1950
|
138
|
1951 type->key = value[i];
|
|
1952 type->key_hash = ngx_hash_key(value[i].data, value[i].len);
|
|
1953 type->value = content_type;
|
0
|
1954 }
|
|
1955
|
|
1956 return NGX_CONF_OK;
|
|
1957 }
|
|
1958
|
|
1959
|
58
|
1960 static ngx_int_t
|
|
1961 ngx_http_core_preconfiguration(ngx_conf_t *cf)
|
|
1962 {
|
|
1963 return ngx_http_variables_add_core_vars(cf);
|
|
1964 }
|
|
1965
|
|
1966
|
36
|
1967 static void *
|
|
1968 ngx_http_core_create_main_conf(ngx_conf_t *cf)
|
0
|
1969 {
|
34
|
1970 ngx_http_core_main_conf_t *cmcf;
|
|
1971
|
50
|
1972 cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t));
|
|
1973 if (cmcf == NULL) {
|
34
|
1974 return NGX_CONF_ERROR;
|
|
1975 }
|
0
|
1976
|
48
|
1977 if (ngx_array_init(&cmcf->servers, cf->pool, 4,
|
118
|
1978 sizeof(ngx_http_core_srv_conf_t *))
|
200
|
1979 != NGX_OK)
|
34
|
1980 {
|
|
1981 return NGX_CONF_ERROR;
|
|
1982 }
|
0
|
1983
|
142
|
1984 cmcf->server_names_hash_max_size = NGX_CONF_UNSET_UINT;
|
|
1985 cmcf->server_names_hash_bucket_size = NGX_CONF_UNSET_UINT;
|
26
|
1986
|
160
|
1987 cmcf->variables_hash_max_size = NGX_CONF_UNSET_UINT;
|
|
1988 cmcf->variables_hash_bucket_size = NGX_CONF_UNSET_UINT;
|
|
1989
|
0
|
1990 return cmcf;
|
|
1991 }
|
|
1992
|
|
1993
|
36
|
1994 static char *
|
|
1995 ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf)
|
0
|
1996 {
|
|
1997 ngx_http_core_main_conf_t *cmcf = conf;
|
|
1998
|
142
|
1999 if (cmcf->server_names_hash_max_size == NGX_CONF_UNSET_UINT) {
|
|
2000 cmcf->server_names_hash_max_size = 512;
|
26
|
2001 }
|
|
2002
|
142
|
2003 if (cmcf->server_names_hash_bucket_size == NGX_CONF_UNSET_UINT) {
|
|
2004 cmcf->server_names_hash_bucket_size = ngx_cacheline_size;
|
26
|
2005 }
|
0
|
2006
|
142
|
2007 cmcf->server_names_hash_bucket_size =
|
|
2008 ngx_align(cmcf->server_names_hash_bucket_size, ngx_cacheline_size);
|
|
2009
|
160
|
2010
|
|
2011 if (cmcf->variables_hash_max_size == NGX_CONF_UNSET_UINT) {
|
|
2012 cmcf->variables_hash_max_size = 512;
|
|
2013 }
|
|
2014
|
|
2015 if (cmcf->variables_hash_bucket_size == NGX_CONF_UNSET_UINT) {
|
|
2016 cmcf->variables_hash_bucket_size = 64;
|
|
2017 }
|
|
2018
|
|
2019 cmcf->variables_hash_bucket_size =
|
|
2020 ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size);
|
|
2021
|
0
|
2022 return NGX_CONF_OK;
|
|
2023 }
|
|
2024
|
|
2025
|
36
|
2026 static void *
|
|
2027 ngx_http_core_create_srv_conf(ngx_conf_t *cf)
|
0
|
2028 {
|
|
2029 ngx_http_core_srv_conf_t *cscf;
|
|
2030
|
50
|
2031 cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t));
|
|
2032 if (cscf == NULL) {
|
36
|
2033 return NGX_CONF_ERROR;
|
|
2034 }
|
|
2035
|
0
|
2036 /*
|
36
|
2037 * set by ngx_pcalloc():
|
28
|
2038 *
|
|
2039 * conf->client_large_buffers.num = 0;
|
|
2040 */
|
0
|
2041
|
48
|
2042 if (ngx_array_init(&cscf->locations, cf->pool, 4, sizeof(void *))
|
142
|
2043 == NGX_ERROR)
|
36
|
2044 {
|
|
2045 return NGX_CONF_ERROR;
|
|
2046 }
|
|
2047
|
48
|
2048 if (ngx_array_init(&cscf->listen, cf->pool, 4, sizeof(ngx_http_listen_t))
|
142
|
2049 == NGX_ERROR)
|
36
|
2050 {
|
|
2051 return NGX_CONF_ERROR;
|
|
2052 }
|
|
2053
|
230
|
2054 if (ngx_array_init(&cscf->server_names, cf->temp_pool, 4,
|
142
|
2055 sizeof(ngx_http_server_name_t))
|
|
2056 == NGX_ERROR)
|
36
|
2057 {
|
|
2058 return NGX_CONF_ERROR;
|
|
2059 }
|
0
|
2060
|
|
2061 cscf->connection_pool_size = NGX_CONF_UNSET_SIZE;
|
|
2062 cscf->request_pool_size = NGX_CONF_UNSET_SIZE;
|
|
2063 cscf->client_header_timeout = NGX_CONF_UNSET_MSEC;
|
|
2064 cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE;
|
158
|
2065 cscf->optimize_server_names = NGX_CONF_UNSET;
|
60
|
2066 cscf->ignore_invalid_headers = NGX_CONF_UNSET;
|
0
|
2067
|
|
2068 return cscf;
|
|
2069 }
|
|
2070
|
|
2071
|
36
|
2072 static char *
|
|
2073 ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
0
|
2074 {
|
|
2075 ngx_http_core_srv_conf_t *prev = parent;
|
|
2076 ngx_http_core_srv_conf_t *conf = child;
|
|
2077
|
142
|
2078 ngx_http_listen_t *ls;
|
|
2079 ngx_http_server_name_t *sn;
|
0
|
2080
|
|
2081 /* TODO: it does not merge, it inits only */
|
|
2082
|
|
2083 if (conf->listen.nelts == 0) {
|
50
|
2084 ls = ngx_array_push(&conf->listen);
|
|
2085 if (ls == NULL) {
|
36
|
2086 return NGX_CONF_ERROR;
|
|
2087 }
|
|
2088
|
72
|
2089 ngx_memzero(ls, sizeof(ngx_http_listen_t));
|
|
2090
|
36
|
2091 ls->addr = INADDR_ANY;
|
10
|
2092 #if (NGX_WIN32)
|
36
|
2093 ls->port = 80;
|
0
|
2094 #else
|
|
2095 /* STUB: getuid() should be cached */
|
36
|
2096 ls->port = (getuid() == 0) ? 80 : 8000;
|
0
|
2097 #endif
|
36
|
2098 ls->family = AF_INET;
|
118
|
2099
|
|
2100 ls->conf.backlog = -1;
|
|
2101 ls->conf.rcvbuf = -1;
|
|
2102 ls->conf.sndbuf = -1;
|
0
|
2103 }
|
|
2104
|
154
|
2105 if (conf->server_name.data == NULL) {
|
|
2106 conf->server_name.data = ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN);
|
|
2107 if (conf->server_name.data == NULL) {
|
|
2108 return NGX_CONF_ERROR;
|
|
2109 }
|
|
2110
|
|
2111 if (gethostname((char *) conf->server_name.data, NGX_MAXHOSTNAMELEN)
|
|
2112 == -1)
|
|
2113 {
|
|
2114 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
|
|
2115 "gethostname() failed");
|
|
2116 return NGX_CONF_ERROR;
|
|
2117 }
|
|
2118
|
|
2119 conf->server_name.len = ngx_strlen(conf->server_name.data);
|
|
2120
|
50
|
2121 sn = ngx_array_push(&conf->server_names);
|
|
2122 if (sn == NULL) {
|
36
|
2123 return NGX_CONF_ERROR;
|
|
2124 }
|
|
2125
|
154
|
2126 sn->name.len = conf->server_name.len;
|
|
2127 sn->name.data = conf->server_name.data;
|
36
|
2128 sn->core_srv_conf = conf;
|
0
|
2129 }
|
|
2130
|
|
2131 ngx_conf_merge_size_value(conf->connection_pool_size,
|
|
2132 prev->connection_pool_size, 256);
|
|
2133 ngx_conf_merge_size_value(conf->request_pool_size,
|
|
2134 prev->request_pool_size, 4096);
|
|
2135 ngx_conf_merge_msec_value(conf->client_header_timeout,
|
|
2136 prev->client_header_timeout, 60000);
|
|
2137 ngx_conf_merge_size_value(conf->client_header_buffer_size,
|
|
2138 prev->client_header_buffer_size, 1024);
|
|
2139 ngx_conf_merge_bufs_value(conf->large_client_header_buffers,
|
|
2140 prev->large_client_header_buffers,
|
|
2141 4, ngx_pagesize);
|
|
2142
|
|
2143 if (conf->large_client_header_buffers.size < conf->connection_pool_size) {
|
|
2144 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2145 "the \"large_client_header_buffers\" size must be "
|
|
2146 "equal to or bigger than \"connection_pool_size\"");
|
|
2147 return NGX_CONF_ERROR;
|
|
2148 }
|
|
2149
|
158
|
2150 ngx_conf_merge_value(conf->optimize_server_names,
|
|
2151 prev->optimize_server_names, 1);
|
152
|
2152
|
60
|
2153 ngx_conf_merge_value(conf->ignore_invalid_headers,
|
|
2154 prev->ignore_invalid_headers, 1);
|
|
2155
|
0
|
2156 return NGX_CONF_OK;
|
|
2157 }
|
|
2158
|
|
2159
|
36
|
2160 static void *
|
|
2161 ngx_http_core_create_loc_conf(ngx_conf_t *cf)
|
0
|
2162 {
|
34
|
2163 ngx_http_core_loc_conf_t *lcf;
|
0
|
2164
|
50
|
2165 lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t));
|
|
2166 if (lcf == NULL) {
|
36
|
2167 return NGX_CONF_ERROR;
|
|
2168 }
|
0
|
2169
|
28
|
2170 /*
|
|
2171 * set by ngx_pcalloc():
|
|
2172 *
|
126
|
2173 * lcf->root = { 0, NULL };
|
180
|
2174 * lcf->limit_except = 0;
|
126
|
2175 * lcf->post_action = { 0, NULL };
|
28
|
2176 * lcf->types = NULL;
|
126
|
2177 * lcf->default_type = { 0, NULL };
|
28
|
2178 * lcf->err_log = NULL;
|
|
2179 * lcf->error_pages = NULL;
|
|
2180 * lcf->client_body_path = NULL;
|
|
2181 * lcf->regex = NULL;
|
|
2182 * lcf->exact_match = 0;
|
|
2183 * lcf->auto_redirect = 0;
|
|
2184 * lcf->alias = 0;
|
|
2185 */
|
0
|
2186
|
212
|
2187 lcf->client_max_body_size = NGX_CONF_UNSET;
|
0
|
2188 lcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE;
|
|
2189 lcf->client_body_timeout = NGX_CONF_UNSET_MSEC;
|
92
|
2190 lcf->satisfy_any = NGX_CONF_UNSET;
|
58
|
2191 lcf->internal = NGX_CONF_UNSET;
|
182
|
2192 lcf->client_body_in_file_only = NGX_CONF_UNSET;
|
0
|
2193 lcf->sendfile = NGX_CONF_UNSET;
|
|
2194 lcf->tcp_nopush = NGX_CONF_UNSET;
|
2
|
2195 lcf->tcp_nodelay = NGX_CONF_UNSET;
|
0
|
2196 lcf->send_timeout = NGX_CONF_UNSET_MSEC;
|
|
2197 lcf->send_lowat = NGX_CONF_UNSET_SIZE;
|
|
2198 lcf->postpone_output = NGX_CONF_UNSET_SIZE;
|
|
2199 lcf->limit_rate = NGX_CONF_UNSET_SIZE;
|
|
2200 lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
|
|
2201 lcf->keepalive_header = NGX_CONF_UNSET;
|
|
2202 lcf->lingering_time = NGX_CONF_UNSET_MSEC;
|
|
2203 lcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
|
|
2204 lcf->reset_timedout_connection = NGX_CONF_UNSET;
|
70
|
2205 lcf->port_in_redirect = NGX_CONF_UNSET;
|
0
|
2206 lcf->msie_padding = NGX_CONF_UNSET;
|
228
|
2207 lcf->msie_refresh = NGX_CONF_UNSET;
|
76
|
2208 lcf->log_not_found = NGX_CONF_UNSET;
|
228
|
2209 lcf->recursive_error_pages = NGX_CONF_UNSET;
|
138
|
2210 lcf->types_hash_max_size = NGX_CONF_UNSET_UINT;
|
|
2211 lcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT;
|
0
|
2212
|
|
2213 return lcf;
|
|
2214 }
|
|
2215
|
|
2216
|
138
|
2217 static ngx_str_t ngx_http_core_text_html_type = ngx_string("text/html");
|
|
2218 static ngx_str_t ngx_http_core_image_gif_type = ngx_string("image/gif");
|
|
2219 static ngx_str_t ngx_http_core_image_jpeg_type = ngx_string("image/jpeg");
|
|
2220
|
|
2221 static ngx_hash_key_t ngx_http_core_default_types[] = {
|
|
2222 { ngx_string("html"), 0, &ngx_http_core_text_html_type },
|
|
2223 { ngx_string("gif"), 0, &ngx_http_core_image_gif_type },
|
|
2224 { ngx_string("jpg"), 0, &ngx_http_core_image_jpeg_type },
|
|
2225 { ngx_null_string, 0, NULL }
|
0
|
2226 };
|
|
2227
|
|
2228
|
36
|
2229 static char *
|
138
|
2230 ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
0
|
2231 {
|
|
2232 ngx_http_core_loc_conf_t *prev = parent;
|
|
2233 ngx_http_core_loc_conf_t *conf = child;
|
|
2234
|
36
|
2235 ngx_uint_t i;
|
138
|
2236 ngx_hash_key_t *type;
|
|
2237 ngx_hash_init_t types_hash;
|
0
|
2238
|
152
|
2239 if (conf->root.data == NULL) {
|
|
2240
|
174
|
2241 conf->alias = prev->alias;
|
152
|
2242 conf->root = prev->root;
|
|
2243 conf->root_lengths = prev->root_lengths;
|
|
2244 conf->root_values = prev->root_values;
|
|
2245
|
|
2246 if (prev->root.data == NULL) {
|
|
2247 conf->root.len = sizeof("html") - 1;
|
|
2248 conf->root.data = (u_char *) "html";
|
|
2249
|
|
2250 if (ngx_conf_full_name(cf->cycle, &conf->root) == NGX_ERROR) {
|
|
2251 return NGX_CONF_ERROR;
|
|
2252 }
|
|
2253 }
|
0
|
2254 }
|
|
2255
|
126
|
2256 if (conf->post_action.data == NULL) {
|
|
2257 conf->post_action = prev->post_action;
|
|
2258 }
|
|
2259
|
212
|
2260 ngx_conf_merge_uint_value(conf->types_hash_max_size,
|
|
2261 prev->types_hash_max_size, 1024);
|
|
2262
|
|
2263 ngx_conf_merge_uint_value(conf->types_hash_bucket_size,
|
|
2264 prev->types_hash_bucket_size,
|
|
2265 ngx_cacheline_size);
|
138
|
2266
|
|
2267 conf->types_hash_bucket_size = ngx_align(conf->types_hash_bucket_size,
|
|
2268 ngx_cacheline_size);
|
|
2269
|
|
2270 /*
|
|
2271 * the special handling the "types" directive in the "http" section
|
|
2272 * to inherit the http's conf->types_hash to all servers
|
|
2273 */
|
|
2274
|
|
2275 if (prev->types && prev->types_hash.buckets == NULL) {
|
|
2276
|
|
2277 types_hash.hash = &prev->types_hash;
|
|
2278 types_hash.key = ngx_hash_key_lc;
|
|
2279 types_hash.max_size = conf->types_hash_max_size;
|
|
2280 types_hash.bucket_size = conf->types_hash_bucket_size;
|
144
|
2281 types_hash.name = "types_hash";
|
138
|
2282 types_hash.pool = cf->pool;
|
|
2283 types_hash.temp_pool = NULL;
|
|
2284
|
|
2285 if (ngx_hash_init(&types_hash, prev->types->elts, prev->types->nelts)
|
|
2286 != NGX_OK)
|
|
2287 {
|
|
2288 return NGX_CONF_ERROR;
|
|
2289 }
|
|
2290 }
|
|
2291
|
0
|
2292 if (conf->types == NULL) {
|
138
|
2293 conf->types = prev->types;
|
|
2294 conf->types_hash = prev->types_hash;
|
|
2295 }
|
|
2296
|
|
2297 if (conf->types == NULL) {
|
|
2298 conf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_hash_key_t));
|
|
2299 if (conf->types == NULL) {
|
|
2300 return NGX_CONF_ERROR;
|
|
2301 }
|
|
2302
|
|
2303 for (i = 0; ngx_http_core_default_types[i].key.len; i++) {
|
|
2304 type = ngx_array_push(conf->types);
|
|
2305 if (type == NULL) {
|
36
|
2306 return NGX_CONF_ERROR;
|
|
2307 }
|
0
|
2308
|
138
|
2309 type->key = ngx_http_core_default_types[i].key;
|
|
2310 type->key_hash =
|
|
2311 ngx_hash_key_lc(ngx_http_core_default_types[i].key.data,
|
|
2312 ngx_http_core_default_types[i].key.len);
|
|
2313 type->value = ngx_http_core_default_types[i].value;
|
|
2314 }
|
|
2315 }
|
|
2316
|
|
2317 if (conf->types_hash.buckets == NULL) {
|
|
2318
|
|
2319 types_hash.hash = &conf->types_hash;
|
|
2320 types_hash.key = ngx_hash_key_lc;
|
|
2321 types_hash.max_size = conf->types_hash_max_size;
|
|
2322 types_hash.bucket_size = conf->types_hash_bucket_size;
|
144
|
2323 types_hash.name = "mime_types_hash";
|
138
|
2324 types_hash.pool = cf->pool;
|
|
2325 types_hash.temp_pool = NULL;
|
|
2326
|
|
2327 if (ngx_hash_init(&types_hash, conf->types->elts, conf->types->nelts)
|
|
2328 != NGX_OK)
|
|
2329 {
|
|
2330 return NGX_CONF_ERROR;
|
0
|
2331 }
|
|
2332 }
|
|
2333
|
|
2334 if (conf->err_log == NULL) {
|
|
2335 if (prev->err_log) {
|
|
2336 conf->err_log = prev->err_log;
|
|
2337 } else {
|
|
2338 conf->err_log = cf->cycle->new_log;
|
|
2339 }
|
|
2340 }
|
|
2341
|
|
2342 if (conf->error_pages == NULL && prev->error_pages) {
|
|
2343 conf->error_pages = prev->error_pages;
|
|
2344 }
|
|
2345
|
|
2346 ngx_conf_merge_str_value(conf->default_type,
|
36
|
2347 prev->default_type, "text/plain");
|
0
|
2348
|
212
|
2349 ngx_conf_merge_off_value(conf->client_max_body_size,
|
0
|
2350 prev->client_max_body_size, 1 * 1024 * 1024);
|
|
2351 ngx_conf_merge_size_value(conf->client_body_buffer_size,
|
|
2352 prev->client_body_buffer_size,
|
|
2353 (size_t) 2 * ngx_pagesize);
|
|
2354 ngx_conf_merge_msec_value(conf->client_body_timeout,
|
|
2355 prev->client_body_timeout, 60000);
|
58
|
2356
|
92
|
2357 ngx_conf_merge_value(conf->satisfy_any, prev->satisfy_any, 0);
|
58
|
2358 ngx_conf_merge_value(conf->internal, prev->internal, 0);
|
182
|
2359 ngx_conf_merge_value(conf->client_body_in_file_only,
|
|
2360 prev->client_body_in_file_only, 0);
|
0
|
2361 ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
|
|
2362 ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0);
|
228
|
2363 ngx_conf_merge_value(conf->tcp_nodelay, prev->tcp_nodelay, 1);
|
58
|
2364
|
0
|
2365 ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000);
|
|
2366 ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0);
|
|
2367 ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output,
|
|
2368 1460);
|
|
2369 ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0);
|
|
2370 ngx_conf_merge_msec_value(conf->keepalive_timeout,
|
|
2371 prev->keepalive_timeout, 75000);
|
|
2372 ngx_conf_merge_sec_value(conf->keepalive_header,
|
|
2373 prev->keepalive_header, 0);
|
|
2374 ngx_conf_merge_msec_value(conf->lingering_time,
|
|
2375 prev->lingering_time, 30000);
|
|
2376 ngx_conf_merge_msec_value(conf->lingering_timeout,
|
|
2377 prev->lingering_timeout, 5000);
|
|
2378
|
28
|
2379 ngx_conf_merge_path_value(conf->client_body_temp_path,
|
|
2380 prev->client_body_temp_path,
|
|
2381 NGX_HTTP_CLIENT_TEMP_PATH, 0, 0, 0,
|
|
2382 ngx_garbage_collector_temp_handler, cf);
|
|
2383
|
0
|
2384 ngx_conf_merge_value(conf->reset_timedout_connection,
|
36
|
2385 prev->reset_timedout_connection, 0);
|
70
|
2386 ngx_conf_merge_value(conf->port_in_redirect, prev->port_in_redirect, 1);
|
0
|
2387 ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1);
|
228
|
2388 ngx_conf_merge_value(conf->msie_refresh, prev->msie_refresh, 0);
|
76
|
2389 ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1);
|
228
|
2390 ngx_conf_merge_value(conf->recursive_error_pages,
|
|
2391 prev->recursive_error_pages, 0);
|
0
|
2392
|
|
2393 if (conf->open_files == NULL) {
|
|
2394 conf->open_files = prev->open_files;
|
|
2395 }
|
|
2396
|
|
2397 return NGX_CONF_OK;
|
|
2398 }
|
|
2399
|
|
2400
|
72
|
2401 /* AF_INET only */
|
|
2402
|
36
|
2403 static char *
|
|
2404 ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
2405 {
|
|
2406 ngx_http_core_srv_conf_t *scf = conf;
|
|
2407
|
252
|
2408 ngx_str_t *value, size;
|
|
2409 ngx_url_t u;
|
|
2410 ngx_uint_t n;
|
|
2411 ngx_http_listen_t *ls;
|
0
|
2412
|
|
2413 /*
|
|
2414 * TODO: check duplicate 'listen' directives,
|
|
2415 * add resolved name to server names ???
|
|
2416 */
|
|
2417
|
72
|
2418 value = cf->args->elts;
|
126
|
2419
|
252
|
2420 ngx_memzero(&u, sizeof(ngx_url_t));
|
|
2421
|
|
2422 u.url = value[1];
|
|
2423 u.listen = 1;
|
266
|
2424 u.default_port = 80;
|
252
|
2425
|
|
2426 if (ngx_parse_url(cf, &u) != NGX_OK) {
|
|
2427 if (u.err) {
|
|
2428 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2429 "%s in \"%V\" of the \"listen\" directive",
|
|
2430 u.err, &u.url);
|
|
2431 }
|
|
2432
|
126
|
2433 return NGX_CONF_ERROR;
|
72
|
2434 }
|
|
2435
|
50
|
2436 ls = ngx_array_push(&scf->listen);
|
|
2437 if (ls == NULL) {
|
0
|
2438 return NGX_CONF_ERROR;
|
|
2439 }
|
|
2440
|
72
|
2441 ngx_memzero(ls, sizeof(ngx_http_listen_t));
|
0
|
2442
|
|
2443 ls->family = AF_INET;
|
252
|
2444 ls->addr = u.addr.in_addr;
|
266
|
2445 ls->port = u.port;
|
0
|
2446 ls->file_name = cf->conf_file->file.name;
|
|
2447 ls->line = cf->conf_file->line;
|
72
|
2448 ls->conf.backlog = -1;
|
112
|
2449 ls->conf.rcvbuf = -1;
|
|
2450 ls->conf.sndbuf = -1;
|
72
|
2451
|
180
|
2452 n = ngx_inet_ntop(AF_INET, &ls->addr, ls->conf.addr, INET_ADDRSTRLEN + 6);
|
|
2453 ngx_sprintf(&ls->conf.addr[n], ":%ui", ls->port);
|
|
2454
|
72
|
2455 if (cf->args->nelts == 2) {
|
|
2456 return NGX_CONF_OK;
|
|
2457 }
|
|
2458
|
|
2459 if (ngx_strcmp(value[2].data, "default") == 0) {
|
|
2460 ls->conf.default_server = 1;
|
|
2461 n = 3;
|
138
|
2462
|
72
|
2463 } else {
|
|
2464 n = 2;
|
0
|
2465 }
|
|
2466
|
72
|
2467 for ( /* void */ ; n < cf->args->nelts; n++) {
|
|
2468
|
|
2469 if (ls->conf.default_server == 0) {
|
|
2470 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2471 "\"%V\" parameter can be specified for "
|
|
2472 "the default \"listen\" directive only",
|
|
2473 &value[n]);
|
|
2474 return NGX_CONF_ERROR;
|
|
2475 }
|
|
2476
|
|
2477 if (ngx_strcmp(value[n].data, "bind") == 0) {
|
|
2478 ls->conf.bind = 1;
|
|
2479 continue;
|
|
2480 }
|
|
2481
|
112
|
2482 if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) {
|
|
2483 ls->conf.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8);
|
72
|
2484 ls->conf.bind = 1;
|
|
2485
|
|
2486 if (ls->conf.backlog == NGX_ERROR || ls->conf.backlog == 0) {
|
|
2487 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2488 "invalid backlog \"%V\"", &value[n]);
|
|
2489 return NGX_CONF_ERROR;
|
|
2490 }
|
|
2491
|
|
2492 continue;
|
|
2493 }
|
|
2494
|
112
|
2495 if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) {
|
|
2496 size.len = value[n].len - 7;
|
|
2497 size.data = value[n].data + 7;
|
|
2498
|
|
2499 ls->conf.rcvbuf = ngx_parse_size(&size);
|
|
2500 ls->conf.bind = 1;
|
|
2501
|
|
2502 if (ls->conf.rcvbuf == NGX_ERROR) {
|
|
2503 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2504 "invalid rcvbuf \"%V\"", &value[n]);
|
|
2505 return NGX_CONF_ERROR;
|
|
2506 }
|
|
2507
|
|
2508 continue;
|
|
2509 }
|
|
2510
|
|
2511 if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) {
|
|
2512 size.len = value[n].len - 7;
|
|
2513 size.data = value[n].data + 7;
|
|
2514
|
|
2515 ls->conf.sndbuf = ngx_parse_size(&size);
|
|
2516 ls->conf.bind = 1;
|
|
2517
|
|
2518 if (ls->conf.sndbuf == NGX_ERROR) {
|
|
2519 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2520 "invalid sndbuf \"%V\"", &value[n]);
|
|
2521 return NGX_CONF_ERROR;
|
|
2522 }
|
|
2523
|
|
2524 continue;
|
|
2525 }
|
|
2526
|
|
2527 if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) {
|
72
|
2528 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
|
112
|
2529 ls->conf.accept_filter = (char *) &value[n].data[14];
|
72
|
2530 ls->conf.bind = 1;
|
|
2531 #else
|
|
2532 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2533 "accept filters \"%V\" are not supported "
|
|
2534 "on this platform, ignored",
|
|
2535 &value[n]);
|
|
2536 #endif
|
|
2537 continue;
|
|
2538 }
|
|
2539
|
|
2540 if (ngx_strcmp(value[n].data, "deferred") == 0) {
|
|
2541 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
|
|
2542 ls->conf.deferred_accept = 1;
|
|
2543 ls->conf.bind = 1;
|
|
2544 #else
|
|
2545 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2546 "the deferred accept is not supported "
|
|
2547 "on this platform, ignored");
|
|
2548 #endif
|
|
2549 continue;
|
|
2550 }
|
0
|
2551
|
|
2552 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
72
|
2553 "the invalid \"%V\" parameter", &value[n]);
|
0
|
2554 return NGX_CONF_ERROR;
|
|
2555 }
|
|
2556
|
|
2557 return NGX_CONF_OK;
|
|
2558 }
|
|
2559
|
|
2560
|
36
|
2561 static char *
|
|
2562 ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
2563 {
|
142
|
2564 ngx_http_core_srv_conf_t *cscf = conf;
|
|
2565
|
|
2566 u_char ch;
|
|
2567 ngx_str_t *value, name;
|
|
2568 ngx_uint_t i;
|
|
2569 ngx_http_server_name_t *sn;
|
0
|
2570
|
|
2571 value = cf->args->elts;
|
|
2572
|
142
|
2573 ch = value[1].data[0];
|
|
2574
|
|
2575 if (cscf->server_name.data == NULL && value[1].len) {
|
|
2576 if (ch == '*') {
|
0
|
2577 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
142
|
2578 "first server name \"%V\" must not be wildcard",
|
|
2579 &value[1]);
|
0
|
2580 return NGX_CONF_ERROR;
|
|
2581 }
|
|
2582
|
142
|
2583 name = value[1];
|
|
2584
|
|
2585 if (ch == '.') {
|
|
2586 name.len--;
|
|
2587 name.data++;
|
|
2588 }
|
|
2589
|
|
2590 cscf->server_name.len = name.len;
|
|
2591 cscf->server_name.data = ngx_pstrdup(cf->pool, &name);
|
|
2592 if (cscf->server_name.data == NULL) {
|
|
2593 return NGX_CONF_ERROR;
|
|
2594 }
|
|
2595 }
|
|
2596
|
|
2597 for (i = 1; i < cf->args->nelts; i++) {
|
|
2598
|
|
2599 ch = value[i].data[0];
|
|
2600
|
212
|
2601 if (value[i].len == 1 && ch == '*') {
|
|
2602 cscf->wildcard = 1;
|
|
2603 continue;
|
|
2604 }
|
|
2605
|
142
|
2606 if (value[i].len == 0
|
|
2607 || (ch == '*' && (value[i].len < 3 || value[i].data[1] != '.'))
|
|
2608 || (ch == '.' && value[i].len < 2))
|
|
2609 {
|
|
2610 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2611 "server name \"%V\" is invalid", &value[i]);
|
|
2612 return NGX_CONF_ERROR;
|
|
2613 }
|
|
2614
|
294
|
2615 if (ngx_strchr(value[i].data, '/')) {
|
|
2616 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
2617 "server name \"%V\" has strange symbols",
|
|
2618 &value[i]);
|
|
2619 }
|
|
2620
|
142
|
2621 sn = ngx_array_push(&cscf->server_names);
|
50
|
2622 if (sn == NULL) {
|
4
|
2623 return NGX_CONF_ERROR;
|
|
2624 }
|
0
|
2625
|
|
2626 sn->name.len = value[i].len;
|
|
2627 sn->name.data = value[i].data;
|
142
|
2628 sn->core_srv_conf = cscf;
|
0
|
2629 }
|
|
2630
|
|
2631 return NGX_CONF_OK;
|
|
2632 }
|
|
2633
|
|
2634
|
36
|
2635 static char *
|
|
2636 ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
2637 {
|
|
2638 ngx_http_core_loc_conf_t *lcf = conf;
|
|
2639
|
144
|
2640 ngx_str_t *value;
|
|
2641 ngx_uint_t alias, n;
|
|
2642 ngx_http_script_compile_t sc;
|
0
|
2643
|
|
2644 alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0;
|
|
2645
|
|
2646 if (lcf->root.data) {
|
|
2647
|
|
2648 /* the (ngx_uint_t) cast is required by gcc 2.7.2.3 */
|
|
2649
|
|
2650 if ((ngx_uint_t) lcf->alias == alias) {
|
|
2651 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
2652 "\"%V\" directive is duplicate",
|
|
2653 &cmd->name);
|
0
|
2654 } else {
|
|
2655 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
2656 "\"%V\" directive is duplicate, "
|
0
|
2657 "\"%s\" directive is specified before",
|
10
|
2658 &cmd->name, lcf->alias ? "alias" : "root");
|
0
|
2659 }
|
|
2660
|
|
2661 return NGX_CONF_ERROR;
|
|
2662 }
|
|
2663
|
|
2664 value = cf->args->elts;
|
|
2665
|
294
|
2666 if (ngx_strstr(value[1].data, "$document_root")
|
|
2667 || ngx_strstr(value[1].data, "${document_root}"))
|
|
2668 {
|
|
2669 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2670 "the $document_root variable may not be used "
|
|
2671 "in the \"%V\" directive",
|
|
2672 &cmd->name);
|
|
2673
|
|
2674 return NGX_CONF_ERROR;
|
|
2675 }
|
|
2676
|
0
|
2677 lcf->alias = alias;
|
|
2678 lcf->root = value[1];
|
|
2679
|
|
2680 if (!alias && lcf->root.data[lcf->root.len - 1] == '/') {
|
|
2681 lcf->root.len--;
|
|
2682 }
|
|
2683
|
216
|
2684 if (lcf->root.data[0] != '$') {
|
|
2685 if (ngx_conf_full_name(cf->cycle, &lcf->root) == NGX_ERROR) {
|
|
2686 return NGX_CONF_ERROR;
|
|
2687 }
|
152
|
2688 }
|
|
2689
|
|
2690 n = ngx_http_script_variables_count(&lcf->root);
|
144
|
2691
|
|
2692 if (n == 0) {
|
|
2693 return NGX_CONF_OK;
|
|
2694 }
|
|
2695
|
|
2696 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
2697
|
|
2698 sc.cf = cf;
|
152
|
2699 sc.source = &lcf->root;
|
144
|
2700 sc.lengths = &lcf->root_lengths;
|
|
2701 sc.values = &lcf->root_values;
|
|
2702 sc.variables = n;
|
|
2703 sc.complete_lengths = 1;
|
|
2704 sc.complete_values = 1;
|
|
2705
|
|
2706 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
2707 return NGX_CONF_ERROR;
|
|
2708 }
|
|
2709
|
0
|
2710 return NGX_CONF_OK;
|
|
2711 }
|
|
2712
|
|
2713
|
180
|
2714 static ngx_http_method_name_t ngx_methods_names[] = {
|
286
|
2715 { (u_char *) "GET", (uint32_t) ~NGX_HTTP_GET },
|
|
2716 { (u_char *) "HEAD", (uint32_t) ~NGX_HTTP_HEAD },
|
|
2717 { (u_char *) "POST", (uint32_t) ~NGX_HTTP_POST },
|
|
2718 { (u_char *) "PUT", (uint32_t) ~NGX_HTTP_PUT },
|
|
2719 { (u_char *) "DELETE", (uint32_t) ~NGX_HTTP_DELETE },
|
|
2720 { (u_char *) "MKCOL", (uint32_t) ~NGX_HTTP_MKCOL },
|
|
2721 { (u_char *) "COPY", (uint32_t) ~NGX_HTTP_COPY },
|
|
2722 { (u_char *) "MOVE", (uint32_t) ~NGX_HTTP_MOVE },
|
|
2723 { (u_char *) "OPTIONS", (uint32_t) ~NGX_HTTP_OPTIONS },
|
|
2724 { (u_char *) "PROPFIND" , (uint32_t) ~NGX_HTTP_PROPFIND },
|
|
2725 { (u_char *) "PROPPATCH", (uint32_t) ~NGX_HTTP_PROPPATCH },
|
|
2726 { (u_char *) "LOCK", (uint32_t) ~NGX_HTTP_LOCK },
|
|
2727 { (u_char *) "UNLOCK", (uint32_t) ~NGX_HTTP_UNLOCK },
|
180
|
2728 { NULL, 0 }
|
|
2729 };
|
|
2730
|
|
2731
|
|
2732 static char *
|
|
2733 ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
2734 {
|
|
2735 ngx_http_core_loc_conf_t *clcf = conf;
|
|
2736
|
|
2737 char *rv;
|
|
2738 void *mconf;
|
|
2739 ngx_str_t *value;
|
|
2740 ngx_uint_t i;
|
|
2741 ngx_conf_t save;
|
|
2742 ngx_http_module_t *module;
|
|
2743 ngx_http_conf_ctx_t *ctx, *pctx;
|
|
2744 ngx_http_method_name_t *name;
|
|
2745 ngx_http_core_loc_conf_t *lcf, **clcfp;
|
|
2746
|
|
2747 if (clcf->limit_except) {
|
|
2748 return "duplicate";
|
|
2749 }
|
|
2750
|
|
2751 clcf->limit_except = 0xffffffff;
|
|
2752
|
|
2753 value = cf->args->elts;
|
|
2754
|
|
2755 for (i = 1; i < cf->args->nelts; i++) {
|
|
2756 for (name = ngx_methods_names; name->name; name++) {
|
|
2757
|
|
2758 if (ngx_strcasecmp(value[i].data, name->name) == 0) {
|
|
2759 clcf->limit_except &= name->method;
|
|
2760 goto next;
|
|
2761 }
|
|
2762 }
|
|
2763
|
|
2764 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2765 "invalid method \"%V\"", &value[i]);
|
|
2766 return NGX_CONF_ERROR;
|
|
2767
|
|
2768 next:
|
|
2769 continue;
|
|
2770 }
|
|
2771
|
|
2772 if (!(clcf->limit_except & NGX_HTTP_GET)) {
|
|
2773 clcf->limit_except &= (uint32_t) ~NGX_HTTP_HEAD;
|
|
2774 }
|
|
2775
|
|
2776 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
|
|
2777 if (ctx == NULL) {
|
|
2778 return NGX_CONF_ERROR;
|
|
2779 }
|
|
2780
|
|
2781 pctx = cf->ctx;
|
|
2782 ctx->main_conf = pctx->main_conf;
|
|
2783 ctx->srv_conf = pctx->srv_conf;
|
|
2784
|
|
2785 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
2786 if (ctx->loc_conf == NULL) {
|
|
2787 return NGX_CONF_ERROR;
|
|
2788 }
|
|
2789
|
|
2790 for (i = 0; ngx_modules[i]; i++) {
|
|
2791 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
|
|
2792 continue;
|
|
2793 }
|
|
2794
|
|
2795 module = ngx_modules[i]->ctx;
|
|
2796
|
|
2797 if (module->create_loc_conf) {
|
|
2798
|
|
2799 mconf = module->create_loc_conf(cf);
|
|
2800 if (mconf == NULL) {
|
|
2801 return NGX_CONF_ERROR;
|
|
2802 }
|
|
2803
|
|
2804 ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
|
|
2805 }
|
|
2806 }
|
|
2807
|
|
2808
|
|
2809 lcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
|
|
2810 clcf->limit_except_loc_conf = ctx->loc_conf;
|
|
2811 lcf->loc_conf = ctx->loc_conf;
|
|
2812 lcf->name = clcf->name;
|
|
2813 lcf->noname = 1;
|
|
2814
|
|
2815 if (clcf->locations.elts == NULL) {
|
|
2816 if (ngx_array_init(&clcf->locations, cf->pool, 4, sizeof(void *))
|
|
2817 == NGX_ERROR)
|
|
2818 {
|
|
2819 return NGX_CONF_ERROR;
|
|
2820 }
|
|
2821 }
|
|
2822
|
|
2823 clcfp = ngx_array_push(&clcf->locations);
|
|
2824 if (clcfp == NULL) {
|
|
2825 return NGX_CONF_ERROR;
|
|
2826 }
|
|
2827
|
|
2828 *clcfp = lcf;
|
|
2829
|
|
2830
|
|
2831 save = *cf;
|
|
2832 cf->ctx = ctx;
|
|
2833 cf->cmd_type = NGX_HTTP_LMT_CONF;
|
|
2834
|
|
2835 rv = ngx_conf_parse(cf, NULL);
|
|
2836
|
|
2837 *cf = save;
|
|
2838
|
|
2839 return rv;
|
|
2840 }
|
|
2841
|
|
2842
|
36
|
2843 static char *
|
|
2844 ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
2845 {
|
|
2846 ngx_http_core_loc_conf_t *lcf = conf;
|
|
2847
|
222
|
2848 ngx_int_t overwrite;
|
|
2849 ngx_str_t *value, uri;
|
|
2850 ngx_uint_t i, n, nvar;
|
|
2851 ngx_array_t *uri_lengths, *uri_values;
|
|
2852 ngx_http_err_page_t *err;
|
|
2853 ngx_http_script_compile_t sc;
|
0
|
2854
|
|
2855 if (lcf->error_pages == NULL) {
|
36
|
2856 lcf->error_pages = ngx_array_create(cf->pool, 4,
|
0
|
2857 sizeof(ngx_http_err_page_t));
|
|
2858 if (lcf->error_pages == NULL) {
|
|
2859 return NGX_CONF_ERROR;
|
|
2860 }
|
|
2861 }
|
|
2862
|
|
2863 value = cf->args->elts;
|
|
2864
|
|
2865 i = cf->args->nelts - 2;
|
|
2866
|
|
2867 if (value[i].data[0] == '=') {
|
|
2868 if (i == 1) {
|
|
2869 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
2870 "invalid value \"%V\"", &value[i]);
|
0
|
2871 return NGX_CONF_ERROR;
|
|
2872 }
|
|
2873
|
104
|
2874 if (value[i].len > 1) {
|
|
2875 overwrite = ngx_atoi(&value[i].data[1], value[i].len - 1);
|
|
2876
|
|
2877 if (overwrite == NGX_ERROR) {
|
|
2878 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2879 "invalid value \"%V\"", &value[i]);
|
|
2880 return NGX_CONF_ERROR;
|
|
2881 }
|
|
2882
|
|
2883 } else {
|
|
2884 overwrite = 0;
|
0
|
2885 }
|
|
2886
|
|
2887 n = 2;
|
|
2888
|
|
2889 } else {
|
104
|
2890 overwrite = -1;
|
0
|
2891 n = 1;
|
|
2892 }
|
|
2893
|
222
|
2894 uri = value[cf->args->nelts - 1];
|
|
2895 uri_lengths = NULL;
|
|
2896 uri_values = NULL;
|
|
2897
|
|
2898 nvar = ngx_http_script_variables_count(&uri);
|
|
2899
|
|
2900 if (nvar) {
|
|
2901 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
2902
|
|
2903 sc.cf = cf;
|
|
2904 sc.source = &uri;
|
|
2905 sc.lengths = &uri_lengths;
|
|
2906 sc.values = &uri_values;
|
|
2907 sc.variables = nvar;
|
|
2908 sc.complete_lengths = 1;
|
|
2909 sc.complete_values = 1;
|
|
2910
|
|
2911 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
2912 return NGX_CONF_ERROR;
|
|
2913 }
|
|
2914 }
|
|
2915
|
0
|
2916 for (i = 1; i < cf->args->nelts - n; i++) {
|
50
|
2917 err = ngx_array_push(lcf->error_pages);
|
|
2918 if (err == NULL) {
|
0
|
2919 return NGX_CONF_ERROR;
|
|
2920 }
|
|
2921
|
|
2922 err->status = ngx_atoi(value[i].data, value[i].len);
|
36
|
2923
|
236
|
2924 if (err->status == NGX_ERROR || err->status == 499) {
|
0
|
2925 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
2926 "invalid value \"%V\"", &value[i]);
|
0
|
2927 return NGX_CONF_ERROR;
|
|
2928 }
|
|
2929
|
|
2930 if (err->status < 400 || err->status > 599) {
|
|
2931 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
2932 "value \"%V\" must be between 400 and 599",
|
|
2933 &value[i]);
|
0
|
2934 return NGX_CONF_ERROR;
|
|
2935 }
|
|
2936
|
104
|
2937 err->overwrite = (overwrite >= 0) ? overwrite : err->status;
|
|
2938
|
222
|
2939 err->uri = uri;
|
|
2940 err->uri_lengths = uri_lengths;
|
|
2941 err->uri_values = uri_values;
|
0
|
2942 }
|
|
2943
|
|
2944 return NGX_CONF_OK;
|
|
2945 }
|
|
2946
|
|
2947
|
36
|
2948 static char *
|
58
|
2949 ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
2950 {
|
|
2951 ngx_http_core_loc_conf_t *lcf = conf;
|
|
2952
|
|
2953 lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args);
|
|
2954 if (lcf->err_log == NULL) {
|
|
2955 return NGX_CONF_ERROR;
|
|
2956 }
|
|
2957
|
|
2958 return ngx_set_error_log_levels(cf, lcf->err_log);
|
|
2959 }
|
|
2960
|
|
2961
|
|
2962 static char *
|
36
|
2963 ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
2964 {
|
|
2965 ngx_http_core_loc_conf_t *lcf = conf;
|
|
2966
|
|
2967 ngx_str_t *value;
|
|
2968
|
|
2969 if (lcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) {
|
|
2970 return "is duplicate";
|
|
2971 }
|
|
2972
|
|
2973 value = cf->args->elts;
|
|
2974
|
|
2975 lcf->keepalive_timeout = ngx_parse_time(&value[1], 0);
|
36
|
2976
|
0
|
2977 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) {
|
|
2978 return "invalid value";
|
|
2979 }
|
|
2980
|
|
2981 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) {
|
|
2982 return "value must be less than 597 hours";
|
|
2983 }
|
|
2984
|
|
2985 if (cf->args->nelts == 2) {
|
|
2986 return NGX_CONF_OK;
|
|
2987 }
|
|
2988
|
|
2989 lcf->keepalive_header = ngx_parse_time(&value[2], 1);
|
36
|
2990
|
0
|
2991 if (lcf->keepalive_header == NGX_ERROR) {
|
|
2992 return "invalid value";
|
|
2993 }
|
|
2994
|
|
2995 if (lcf->keepalive_header == NGX_PARSE_LARGE_TIME) {
|
|
2996 return "value must be less than 68 years";
|
|
2997 }
|
|
2998
|
|
2999 return NGX_CONF_OK;
|
|
3000 }
|
|
3001
|
|
3002
|
36
|
3003 static char *
|
58
|
3004 ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
3005 {
|
|
3006 ngx_http_core_loc_conf_t *lcf = conf;
|
|
3007
|
58
|
3008 if (lcf->internal != NGX_CONF_UNSET) {
|
|
3009 return "is duplicate";
|
0
|
3010 }
|
|
3011
|
58
|
3012 lcf->internal = 1;
|
|
3013
|
|
3014 return NGX_CONF_OK;
|
0
|
3015 }
|
|
3016
|
|
3017
|
36
|
3018 static char *
|
|
3019 ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data)
|
0
|
3020 {
|
22
|
3021 #if (NGX_FREEBSD)
|
2
|
3022 ssize_t *np = data;
|
0
|
3023
|
222
|
3024 if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) {
|
0
|
3025 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3026 "\"send_lowat\" must be less than %d "
|
|
3027 "(sysctl net.inet.tcp.sendspace)",
|
|
3028 ngx_freebsd_net_inet_tcp_sendspace);
|
|
3029
|
|
3030 return NGX_CONF_ERROR;
|
|
3031 }
|
|
3032
|
18
|
3033 #elif !(NGX_HAVE_SO_SNDLOWAT)
|
22
|
3034 ssize_t *np = data;
|
0
|
3035
|
|
3036 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
3037 "\"send_lowat\" is not supported, ignored");
|
|
3038
|
2
|
3039 *np = 0;
|
|
3040
|
0
|
3041 #endif
|
|
3042
|
|
3043 return NGX_CONF_OK;
|
|
3044 }
|