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