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