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