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);
|
372
|
48 static ngx_int_t ngx_http_core_cmp_locations(const void *first,
|
|
49 const void *second);
|
34
|
50
|
|
51 static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
52 void *conf);
|
34
|
53 static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy,
|
36
|
54 void *conf);
|
0
|
55
|
34
|
56 static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
57 void *conf);
|
34
|
58 static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
59 void *conf);
|
34
|
60 static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
180
|
61 static char *ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
62 void *conf);
|
34
|
63 static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
64 void *conf);
|
384
|
65 static char *ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
66 void *conf);
|
332
|
67 static char *ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
68 void *conf);
|
34
|
69 static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
70 void *conf);
|
34
|
71 static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
|
36
|
72 void *conf);
|
58
|
73 static char *ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
74 void *conf);
|
354
|
75 static char *ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
|
348
|
76 void *conf);
|
358
|
77 #if (NGX_HTTP_GZIP)
|
|
78 static char *ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
79 void *conf);
|
|
80 #endif
|
0
|
81
|
34
|
82 static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data);
|
300
|
83 static char *ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data);
|
34
|
84
|
|
85 static ngx_conf_post_t ngx_http_core_lowat_post =
|
300
|
86 { ngx_http_core_lowat_check };
|
|
87
|
|
88 static ngx_conf_post_handler_pt ngx_http_core_pool_size_p =
|
|
89 ngx_http_core_pool_size;
|
0
|
90
|
158
|
91 static ngx_conf_deprecated_t ngx_conf_deprecated_optimize_host_names = {
|
|
92 ngx_conf_deprecated, "optimize_host_names", "optimize_server_names"
|
|
93 };
|
|
94
|
358
|
95 static ngx_conf_deprecated_t ngx_conf_deprecated_open_file_cache_retest = {
|
|
96 ngx_conf_deprecated, "open_file_cache_retest", "open_file_cache_valid"
|
|
97 };
|
|
98
|
362
|
99 static ngx_conf_deprecated_t ngx_conf_deprecated_satisfy_any = {
|
|
100 ngx_conf_deprecated, "satisfy_any", "satisfy"
|
|
101 };
|
|
102
|
0
|
103
|
278
|
104 static ngx_conf_enum_t ngx_http_core_request_body_in_file[] = {
|
|
105 { ngx_string("off"), NGX_HTTP_REQUEST_BODY_FILE_OFF },
|
|
106 { ngx_string("on"), NGX_HTTP_REQUEST_BODY_FILE_ON },
|
|
107 { ngx_string("clean"), NGX_HTTP_REQUEST_BODY_FILE_CLEAN },
|
|
108 { ngx_null_string, 0 }
|
|
109 };
|
|
110
|
|
111
|
362
|
112 static ngx_conf_enum_t ngx_http_core_satisfy[] = {
|
|
113 { ngx_string("all"), NGX_HTTP_SATISFY_ALL },
|
|
114 { ngx_string("any"), NGX_HTTP_SATISFY_ANY },
|
|
115 { ngx_null_string, 0 }
|
|
116 };
|
|
117
|
|
118
|
384
|
119 static ngx_conf_enum_t ngx_http_core_if_modified_since[] = {
|
|
120 { ngx_string("off"), NGX_HTTP_IMS_OFF },
|
|
121 { ngx_string("exact"), NGX_HTTP_IMS_EXACT },
|
|
122 { ngx_string("before"), NGX_HTTP_IMS_BEFORE },
|
|
123 { ngx_null_string, 0 }
|
|
124 };
|
|
125
|
|
126
|
358
|
127 #if (NGX_HTTP_GZIP)
|
|
128
|
|
129 static ngx_conf_enum_t ngx_http_gzip_http_version[] = {
|
|
130 { ngx_string("1.0"), NGX_HTTP_VERSION_10 },
|
|
131 { ngx_string("1.1"), NGX_HTTP_VERSION_11 },
|
|
132 { ngx_null_string, 0 }
|
|
133 };
|
|
134
|
|
135
|
|
136 static ngx_conf_bitmask_t ngx_http_gzip_proxied_mask[] = {
|
|
137 { ngx_string("off"), NGX_HTTP_GZIP_PROXIED_OFF },
|
|
138 { ngx_string("expired"), NGX_HTTP_GZIP_PROXIED_EXPIRED },
|
|
139 { ngx_string("no-cache"), NGX_HTTP_GZIP_PROXIED_NO_CACHE },
|
|
140 { ngx_string("no-store"), NGX_HTTP_GZIP_PROXIED_NO_STORE },
|
|
141 { ngx_string("private"), NGX_HTTP_GZIP_PROXIED_PRIVATE },
|
|
142 { ngx_string("no_last_modified"), NGX_HTTP_GZIP_PROXIED_NO_LM },
|
|
143 { ngx_string("no_etag"), NGX_HTTP_GZIP_PROXIED_NO_ETAG },
|
|
144 { ngx_string("auth"), NGX_HTTP_GZIP_PROXIED_AUTH },
|
|
145 { ngx_string("any"), NGX_HTTP_GZIP_PROXIED_ANY },
|
|
146 { ngx_null_string, 0 }
|
|
147 };
|
|
148
|
|
149
|
|
150 static ngx_str_t ngx_http_gzip_no_cache = ngx_string("no-cache");
|
|
151 static ngx_str_t ngx_http_gzip_no_store = ngx_string("no-store");
|
|
152 static ngx_str_t ngx_http_gzip_private = ngx_string("private");
|
|
153
|
|
154 #endif
|
|
155
|
|
156
|
0
|
157 static ngx_command_t ngx_http_core_commands[] = {
|
|
158
|
160
|
159 { ngx_string("variables_hash_max_size"),
|
|
160 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
|
161 ngx_conf_set_num_slot,
|
|
162 NGX_HTTP_MAIN_CONF_OFFSET,
|
|
163 offsetof(ngx_http_core_main_conf_t, variables_hash_max_size),
|
|
164 NULL },
|
|
165
|
|
166 { ngx_string("variables_hash_bucket_size"),
|
|
167 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
|
168 ngx_conf_set_num_slot,
|
|
169 NGX_HTTP_MAIN_CONF_OFFSET,
|
|
170 offsetof(ngx_http_core_main_conf_t, variables_hash_bucket_size),
|
|
171 NULL },
|
|
172
|
142
|
173 { ngx_string("server_names_hash_max_size"),
|
26
|
174 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
|
175 ngx_conf_set_num_slot,
|
|
176 NGX_HTTP_MAIN_CONF_OFFSET,
|
142
|
177 offsetof(ngx_http_core_main_conf_t, server_names_hash_max_size),
|
26
|
178 NULL },
|
|
179
|
142
|
180 { ngx_string("server_names_hash_bucket_size"),
|
26
|
181 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
|
182 ngx_conf_set_num_slot,
|
|
183 NGX_HTTP_MAIN_CONF_OFFSET,
|
142
|
184 offsetof(ngx_http_core_main_conf_t, server_names_hash_bucket_size),
|
26
|
185 NULL },
|
|
186
|
0
|
187 { ngx_string("server"),
|
200
|
188 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_MULTI|NGX_CONF_NOARGS,
|
34
|
189 ngx_http_core_server,
|
0
|
190 0,
|
|
191 0,
|
|
192 NULL },
|
|
193
|
|
194 { ngx_string("connection_pool_size"),
|
|
195 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
196 ngx_conf_set_size_slot,
|
|
197 NGX_HTTP_SRV_CONF_OFFSET,
|
|
198 offsetof(ngx_http_core_srv_conf_t, connection_pool_size),
|
300
|
199 &ngx_http_core_pool_size_p },
|
0
|
200
|
|
201 { ngx_string("request_pool_size"),
|
|
202 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
203 ngx_conf_set_size_slot,
|
|
204 NGX_HTTP_SRV_CONF_OFFSET,
|
|
205 offsetof(ngx_http_core_srv_conf_t, request_pool_size),
|
300
|
206 &ngx_http_core_pool_size_p },
|
0
|
207
|
|
208 { ngx_string("client_header_timeout"),
|
|
209 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
210 ngx_conf_set_msec_slot,
|
|
211 NGX_HTTP_SRV_CONF_OFFSET,
|
|
212 offsetof(ngx_http_core_srv_conf_t, client_header_timeout),
|
|
213 NULL },
|
|
214
|
|
215 { ngx_string("client_header_buffer_size"),
|
|
216 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
|
217 ngx_conf_set_size_slot,
|
|
218 NGX_HTTP_SRV_CONF_OFFSET,
|
|
219 offsetof(ngx_http_core_srv_conf_t, client_header_buffer_size),
|
|
220 NULL },
|
|
221
|
|
222 { ngx_string("large_client_header_buffers"),
|
|
223 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE2,
|
|
224 ngx_conf_set_bufs_slot,
|
|
225 NGX_HTTP_SRV_CONF_OFFSET,
|
|
226 offsetof(ngx_http_core_srv_conf_t, large_client_header_buffers),
|
|
227 NULL },
|
|
228
|
158
|
229 { ngx_string("optimize_server_names"),
|
|
230 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
|
|
231 ngx_conf_set_flag_slot,
|
|
232 NGX_HTTP_SRV_CONF_OFFSET,
|
|
233 offsetof(ngx_http_core_srv_conf_t, optimize_server_names),
|
|
234 NULL },
|
|
235
|
152
|
236 { ngx_string("optimize_host_names"),
|
|
237 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
|
|
238 ngx_conf_set_flag_slot,
|
|
239 NGX_HTTP_SRV_CONF_OFFSET,
|
158
|
240 offsetof(ngx_http_core_srv_conf_t, optimize_server_names),
|
|
241 &ngx_conf_deprecated_optimize_host_names },
|
152
|
242
|
60
|
243 { ngx_string("ignore_invalid_headers"),
|
|
244 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
|
|
245 ngx_conf_set_flag_slot,
|
|
246 NGX_HTTP_SRV_CONF_OFFSET,
|
|
247 offsetof(ngx_http_core_srv_conf_t, ignore_invalid_headers),
|
|
248 NULL },
|
|
249
|
342
|
250 { ngx_string("merge_slashes"),
|
|
251 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
|
|
252 ngx_conf_set_flag_slot,
|
|
253 NGX_HTTP_SRV_CONF_OFFSET,
|
|
254 offsetof(ngx_http_core_srv_conf_t, merge_slashes),
|
|
255 NULL },
|
|
256
|
0
|
257 { ngx_string("location"),
|
|
258 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12,
|
34
|
259 ngx_http_core_location,
|
0
|
260 NGX_HTTP_SRV_CONF_OFFSET,
|
|
261 0,
|
|
262 NULL },
|
|
263
|
|
264 { ngx_string("listen"),
|
72
|
265 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
|
34
|
266 ngx_http_core_listen,
|
0
|
267 NGX_HTTP_SRV_CONF_OFFSET,
|
|
268 0,
|
|
269 NULL },
|
|
270
|
|
271 { ngx_string("server_name"),
|
|
272 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
|
34
|
273 ngx_http_core_server_name,
|
0
|
274 NGX_HTTP_SRV_CONF_OFFSET,
|
|
275 0,
|
|
276 NULL },
|
|
277
|
138
|
278 { ngx_string("types_hash_max_size"),
|
|
279 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
280 ngx_conf_set_num_slot,
|
|
281 NGX_HTTP_LOC_CONF_OFFSET,
|
|
282 offsetof(ngx_http_core_loc_conf_t, types_hash_max_size),
|
|
283 NULL },
|
|
284
|
|
285 { ngx_string("types_hash_bucket_size"),
|
|
286 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
287 ngx_conf_set_num_slot,
|
|
288 NGX_HTTP_LOC_CONF_OFFSET,
|
|
289 offsetof(ngx_http_core_loc_conf_t, types_hash_bucket_size),
|
|
290 NULL },
|
|
291
|
0
|
292 { ngx_string("types"),
|
|
293 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF
|
|
294 |NGX_CONF_BLOCK|NGX_CONF_NOARGS,
|
34
|
295 ngx_http_core_types,
|
0
|
296 NGX_HTTP_LOC_CONF_OFFSET,
|
|
297 0,
|
|
298 NULL },
|
|
299
|
|
300 { ngx_string("default_type"),
|
|
301 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
302 ngx_conf_set_str_slot,
|
|
303 NGX_HTTP_LOC_CONF_OFFSET,
|
|
304 offsetof(ngx_http_core_loc_conf_t, default_type),
|
|
305 NULL },
|
|
306
|
|
307 { ngx_string("root"),
|
58
|
308 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
309 |NGX_CONF_TAKE1,
|
34
|
310 ngx_http_core_root,
|
0
|
311 NGX_HTTP_LOC_CONF_OFFSET,
|
|
312 0,
|
|
313 NULL },
|
|
314
|
|
315 { ngx_string("alias"),
|
|
316 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
34
|
317 ngx_http_core_root,
|
0
|
318 NGX_HTTP_LOC_CONF_OFFSET,
|
|
319 0,
|
|
320 NULL },
|
|
321
|
180
|
322 { ngx_string("limit_except"),
|
|
323 NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_1MORE,
|
|
324 ngx_http_core_limit_except,
|
|
325 NGX_HTTP_LOC_CONF_OFFSET,
|
|
326 0,
|
|
327 NULL },
|
|
328
|
0
|
329 { ngx_string("client_max_body_size"),
|
|
330 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
212
|
331 ngx_conf_set_off_slot,
|
0
|
332 NGX_HTTP_LOC_CONF_OFFSET,
|
|
333 offsetof(ngx_http_core_loc_conf_t, client_max_body_size),
|
|
334 NULL },
|
|
335
|
|
336 { ngx_string("client_body_buffer_size"),
|
|
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, client_body_buffer_size),
|
|
341 NULL },
|
|
342
|
|
343 { ngx_string("client_body_timeout"),
|
|
344 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
345 ngx_conf_set_msec_slot,
|
|
346 NGX_HTTP_LOC_CONF_OFFSET,
|
|
347 offsetof(ngx_http_core_loc_conf_t, client_body_timeout),
|
|
348 NULL },
|
|
349
|
28
|
350 { ngx_string("client_body_temp_path"),
|
|
351 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
|
|
352 ngx_conf_set_path_slot,
|
|
353 NGX_HTTP_LOC_CONF_OFFSET,
|
|
354 offsetof(ngx_http_core_loc_conf_t, client_body_temp_path),
|
|
355 (void *) ngx_garbage_collector_temp_handler },
|
|
356
|
182
|
357 { ngx_string("client_body_in_file_only"),
|
|
358 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
278
|
359 ngx_conf_set_enum_slot,
|
182
|
360 NGX_HTTP_LOC_CONF_OFFSET,
|
|
361 offsetof(ngx_http_core_loc_conf_t, client_body_in_file_only),
|
278
|
362 &ngx_http_core_request_body_in_file },
|
182
|
363
|
0
|
364 { ngx_string("sendfile"),
|
278
|
365 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
366 |NGX_CONF_TAKE1,
|
0
|
367 ngx_conf_set_flag_slot,
|
|
368 NGX_HTTP_LOC_CONF_OFFSET,
|
|
369 offsetof(ngx_http_core_loc_conf_t, sendfile),
|
|
370 NULL },
|
|
371
|
300
|
372 { ngx_string("sendfile_max_chunk"),
|
|
373 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
374 ngx_conf_set_size_slot,
|
|
375 NGX_HTTP_LOC_CONF_OFFSET,
|
|
376 offsetof(ngx_http_core_loc_conf_t, sendfile_max_chunk),
|
|
377 NULL },
|
|
378
|
0
|
379 { ngx_string("tcp_nopush"),
|
|
380 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
381 ngx_conf_set_flag_slot,
|
|
382 NGX_HTTP_LOC_CONF_OFFSET,
|
|
383 offsetof(ngx_http_core_loc_conf_t, tcp_nopush),
|
|
384 NULL },
|
|
385
|
2
|
386 { ngx_string("tcp_nodelay"),
|
|
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, tcp_nodelay),
|
|
391 NULL },
|
|
392
|
0
|
393 { ngx_string("send_timeout"),
|
|
394 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
395 ngx_conf_set_msec_slot,
|
|
396 NGX_HTTP_LOC_CONF_OFFSET,
|
|
397 offsetof(ngx_http_core_loc_conf_t, send_timeout),
|
|
398 NULL },
|
|
399
|
|
400 { ngx_string("send_lowat"),
|
|
401 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
402 ngx_conf_set_size_slot,
|
|
403 NGX_HTTP_LOC_CONF_OFFSET,
|
|
404 offsetof(ngx_http_core_loc_conf_t, send_lowat),
|
34
|
405 &ngx_http_core_lowat_post },
|
0
|
406
|
|
407 { ngx_string("postpone_output"),
|
|
408 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
409 ngx_conf_set_size_slot,
|
|
410 NGX_HTTP_LOC_CONF_OFFSET,
|
|
411 offsetof(ngx_http_core_loc_conf_t, postpone_output),
|
|
412 NULL },
|
|
413
|
|
414 { ngx_string("limit_rate"),
|
34
|
415 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
416 |NGX_CONF_TAKE1,
|
0
|
417 ngx_conf_set_size_slot,
|
|
418 NGX_HTTP_LOC_CONF_OFFSET,
|
|
419 offsetof(ngx_http_core_loc_conf_t, limit_rate),
|
|
420 NULL },
|
|
421
|
|
422 { ngx_string("keepalive_timeout"),
|
|
423 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
|
34
|
424 ngx_http_core_keepalive,
|
0
|
425 NGX_HTTP_LOC_CONF_OFFSET,
|
|
426 0,
|
|
427 NULL },
|
|
428
|
362
|
429 { ngx_string("satisfy"),
|
|
430 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
431 ngx_conf_set_enum_slot,
|
|
432 NGX_HTTP_LOC_CONF_OFFSET,
|
|
433 offsetof(ngx_http_core_loc_conf_t, satisfy),
|
|
434 &ngx_http_core_satisfy },
|
|
435
|
92
|
436 { ngx_string("satisfy_any"),
|
|
437 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
438 ngx_conf_set_flag_slot,
|
|
439 NGX_HTTP_LOC_CONF_OFFSET,
|
362
|
440 offsetof(ngx_http_core_loc_conf_t, satisfy),
|
|
441 &ngx_conf_deprecated_satisfy_any },
|
92
|
442
|
58
|
443 { ngx_string("internal"),
|
|
444 NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
|
|
445 ngx_http_core_internal,
|
|
446 NGX_HTTP_LOC_CONF_OFFSET,
|
|
447 0,
|
|
448 NULL },
|
|
449
|
0
|
450 { ngx_string("lingering_time"),
|
|
451 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
452 ngx_conf_set_msec_slot,
|
|
453 NGX_HTTP_LOC_CONF_OFFSET,
|
|
454 offsetof(ngx_http_core_loc_conf_t, lingering_time),
|
|
455 NULL },
|
|
456
|
|
457 { ngx_string("lingering_timeout"),
|
|
458 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
459 ngx_conf_set_msec_slot,
|
|
460 NGX_HTTP_LOC_CONF_OFFSET,
|
|
461 offsetof(ngx_http_core_loc_conf_t, lingering_timeout),
|
|
462 NULL },
|
|
463
|
|
464 { ngx_string("reset_timedout_connection"),
|
|
465 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
466 ngx_conf_set_flag_slot,
|
|
467 NGX_HTTP_LOC_CONF_OFFSET,
|
|
468 offsetof(ngx_http_core_loc_conf_t, reset_timedout_connection),
|
|
469 NULL },
|
|
470
|
362
|
471 { ngx_string("server_name_in_redirect"),
|
|
472 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
473 ngx_conf_set_flag_slot,
|
|
474 NGX_HTTP_LOC_CONF_OFFSET,
|
|
475 offsetof(ngx_http_core_loc_conf_t, server_name_in_redirect),
|
|
476 NULL },
|
|
477
|
70
|
478 { ngx_string("port_in_redirect"),
|
|
479 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
480 ngx_conf_set_flag_slot,
|
|
481 NGX_HTTP_LOC_CONF_OFFSET,
|
|
482 offsetof(ngx_http_core_loc_conf_t, port_in_redirect),
|
|
483 NULL },
|
|
484
|
0
|
485 { ngx_string("msie_padding"),
|
|
486 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
487 ngx_conf_set_flag_slot,
|
|
488 NGX_HTTP_LOC_CONF_OFFSET,
|
|
489 offsetof(ngx_http_core_loc_conf_t, msie_padding),
|
|
490 NULL },
|
|
491
|
228
|
492 { ngx_string("msie_refresh"),
|
|
493 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
494 ngx_conf_set_flag_slot,
|
|
495 NGX_HTTP_LOC_CONF_OFFSET,
|
|
496 offsetof(ngx_http_core_loc_conf_t, msie_refresh),
|
|
497 NULL },
|
|
498
|
76
|
499 { ngx_string("log_not_found"),
|
|
500 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
501 ngx_conf_set_flag_slot,
|
|
502 NGX_HTTP_LOC_CONF_OFFSET,
|
|
503 offsetof(ngx_http_core_loc_conf_t, log_not_found),
|
|
504 NULL },
|
|
505
|
228
|
506 { ngx_string("recursive_error_pages"),
|
|
507 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
508 ngx_conf_set_flag_slot,
|
|
509 NGX_HTTP_LOC_CONF_OFFSET,
|
|
510 offsetof(ngx_http_core_loc_conf_t, recursive_error_pages),
|
|
511 NULL },
|
|
512
|
342
|
513 { ngx_string("server_tokens"),
|
|
514 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
515 ngx_conf_set_flag_slot,
|
|
516 NGX_HTTP_LOC_CONF_OFFSET,
|
|
517 offsetof(ngx_http_core_loc_conf_t, server_tokens),
|
|
518 NULL },
|
|
519
|
384
|
520 { ngx_string("if_modified_since"),
|
|
521 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
522 ngx_conf_set_enum_slot,
|
|
523 NGX_HTTP_LOC_CONF_OFFSET,
|
|
524 offsetof(ngx_http_core_loc_conf_t, if_modified_since),
|
|
525 &ngx_http_core_if_modified_since },
|
|
526
|
0
|
527 { ngx_string("error_page"),
|
58
|
528 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
529 |NGX_CONF_2MORE,
|
34
|
530 ngx_http_core_error_page,
|
0
|
531 NGX_HTTP_LOC_CONF_OFFSET,
|
|
532 0,
|
|
533 NULL },
|
|
534
|
384
|
535 { ngx_string("try_files"),
|
|
536 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_2MORE,
|
|
537 ngx_http_core_try_files,
|
|
538 NGX_HTTP_LOC_CONF_OFFSET,
|
|
539 0,
|
|
540 NULL },
|
|
541
|
126
|
542 { ngx_string("post_action"),
|
|
543 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
544 |NGX_CONF_TAKE1,
|
|
545 ngx_conf_set_str_slot,
|
|
546 NGX_HTTP_LOC_CONF_OFFSET,
|
|
547 offsetof(ngx_http_core_loc_conf_t, post_action),
|
|
548 NULL },
|
|
549
|
0
|
550 { ngx_string("error_log"),
|
|
551 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
34
|
552 ngx_http_core_error_log,
|
0
|
553 NGX_HTTP_LOC_CONF_OFFSET,
|
|
554 0,
|
|
555 NULL },
|
|
556
|
|
557 { ngx_string("open_file_cache"),
|
332
|
558 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
|
|
559 ngx_http_core_open_file_cache,
|
|
560 NGX_HTTP_LOC_CONF_OFFSET,
|
|
561 offsetof(ngx_http_core_loc_conf_t, open_file_cache),
|
|
562 NULL },
|
|
563
|
358
|
564 { ngx_string("open_file_cache_valid"),
|
|
565 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
566 ngx_conf_set_sec_slot,
|
|
567 NGX_HTTP_LOC_CONF_OFFSET,
|
|
568 offsetof(ngx_http_core_loc_conf_t, open_file_cache_valid),
|
|
569 NULL },
|
|
570
|
332
|
571 { ngx_string("open_file_cache_retest"),
|
|
572 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
573 ngx_conf_set_sec_slot,
|
0
|
574 NGX_HTTP_LOC_CONF_OFFSET,
|
358
|
575 offsetof(ngx_http_core_loc_conf_t, open_file_cache_valid),
|
|
576 &ngx_conf_deprecated_open_file_cache_retest },
|
|
577
|
|
578 { ngx_string("open_file_cache_min_uses"),
|
|
579 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
580 ngx_conf_set_num_slot,
|
|
581 NGX_HTTP_LOC_CONF_OFFSET,
|
|
582 offsetof(ngx_http_core_loc_conf_t, open_file_cache_min_uses),
|
0
|
583 NULL },
|
|
584
|
332
|
585 { ngx_string("open_file_cache_errors"),
|
|
586 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
587 ngx_conf_set_flag_slot,
|
|
588 NGX_HTTP_LOC_CONF_OFFSET,
|
|
589 offsetof(ngx_http_core_loc_conf_t, open_file_cache_errors),
|
|
590 NULL },
|
|
591
|
|
592 { ngx_string("open_file_cache_events"),
|
|
593 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
594 ngx_conf_set_flag_slot,
|
|
595 NGX_HTTP_LOC_CONF_OFFSET,
|
|
596 offsetof(ngx_http_core_loc_conf_t, open_file_cache_events),
|
|
597 NULL },
|
0
|
598
|
348
|
599 { ngx_string("resolver"),
|
|
600 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
601 ngx_http_core_resolver,
|
|
602 NGX_HTTP_LOC_CONF_OFFSET,
|
|
603 0,
|
|
604 NULL },
|
|
605
|
|
606 { ngx_string("resolver_timeout"),
|
|
607 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
608 ngx_conf_set_msec_slot,
|
|
609 NGX_HTTP_LOC_CONF_OFFSET,
|
|
610 offsetof(ngx_http_core_loc_conf_t, resolver_timeout),
|
|
611 NULL },
|
|
612
|
358
|
613 #if (NGX_HTTP_GZIP)
|
|
614
|
|
615 { ngx_string("gzip_vary"),
|
|
616 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
617 ngx_conf_set_flag_slot,
|
|
618 NGX_HTTP_LOC_CONF_OFFSET,
|
|
619 offsetof(ngx_http_core_loc_conf_t, gzip_vary),
|
|
620 NULL },
|
|
621
|
|
622 { ngx_string("gzip_http_version"),
|
|
623 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
624 ngx_conf_set_enum_slot,
|
|
625 NGX_HTTP_LOC_CONF_OFFSET,
|
|
626 offsetof(ngx_http_core_loc_conf_t, gzip_http_version),
|
|
627 &ngx_http_gzip_http_version },
|
|
628
|
|
629 { ngx_string("gzip_proxied"),
|
|
630 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
631 ngx_conf_set_bitmask_slot,
|
|
632 NGX_HTTP_LOC_CONF_OFFSET,
|
|
633 offsetof(ngx_http_core_loc_conf_t, gzip_proxied),
|
|
634 &ngx_http_gzip_proxied_mask },
|
|
635
|
|
636 { ngx_string("gzip_disable"),
|
|
637 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
638 ngx_http_gzip_disable,
|
|
639 NGX_HTTP_LOC_CONF_OFFSET,
|
|
640 0,
|
|
641 NULL },
|
|
642
|
|
643 #endif
|
|
644
|
0
|
645 ngx_null_command
|
|
646 };
|
|
647
|
|
648
|
216
|
649 static ngx_http_module_t ngx_http_core_module_ctx = {
|
58
|
650 ngx_http_core_preconfiguration, /* preconfiguration */
|
122
|
651 NULL, /* postconfiguration */
|
0
|
652
|
|
653 ngx_http_core_create_main_conf, /* create main configuration */
|
|
654 ngx_http_core_init_main_conf, /* init main configuration */
|
|
655
|
|
656 ngx_http_core_create_srv_conf, /* create server configuration */
|
|
657 ngx_http_core_merge_srv_conf, /* merge server configuration */
|
|
658
|
|
659 ngx_http_core_create_loc_conf, /* create location configuration */
|
|
660 ngx_http_core_merge_loc_conf /* merge location configuration */
|
|
661 };
|
|
662
|
|
663
|
|
664 ngx_module_t ngx_http_core_module = {
|
58
|
665 NGX_MODULE_V1,
|
0
|
666 &ngx_http_core_module_ctx, /* module context */
|
|
667 ngx_http_core_commands, /* module directives */
|
|
668 NGX_HTTP_MODULE, /* module type */
|
90
|
669 NULL, /* init master */
|
58
|
670 NULL, /* init module */
|
90
|
671 NULL, /* init process */
|
|
672 NULL, /* init thread */
|
|
673 NULL, /* exit thread */
|
|
674 NULL, /* exit process */
|
|
675 NULL, /* exit master */
|
|
676 NGX_MODULE_V1_PADDING
|
0
|
677 };
|
|
678
|
|
679
|
364
|
680 static ngx_str_t ngx_http_core_get_method = { 3, (u_char *) "GET " };
|
|
681
|
|
682
|
36
|
683 void
|
|
684 ngx_http_handler(ngx_http_request_t *r)
|
0
|
685 {
|
230
|
686 ngx_http_core_main_conf_t *cmcf;
|
|
687
|
32
|
688 r->connection->log->action = NULL;
|
0
|
689
|
|
690 r->connection->unexpected_eof = 0;
|
|
691
|
224
|
692 if (!r->internal) {
|
92
|
693 switch (r->headers_in.connection_type) {
|
|
694 case 0:
|
|
695 if (r->http_version > NGX_HTTP_VERSION_10) {
|
|
696 r->keepalive = 1;
|
|
697 } else {
|
|
698 r->keepalive = 0;
|
|
699 }
|
|
700 break;
|
|
701
|
|
702 case NGX_HTTP_CONNECTION_CLOSE:
|
|
703 r->keepalive = 0;
|
|
704 break;
|
|
705
|
|
706 case NGX_HTTP_CONNECTION_KEEP_ALIVE:
|
0
|
707 r->keepalive = 1;
|
92
|
708 break;
|
|
709 }
|
|
710
|
|
711 if (r->keepalive && r->headers_in.msie && r->method == NGX_HTTP_POST) {
|
|
712
|
|
713 /*
|
230
|
714 * MSIE may wait for some time if an response for
|
|
715 * a POST request was sent over a keepalive connection
|
92
|
716 */
|
|
717
|
0
|
718 r->keepalive = 0;
|
|
719 }
|
92
|
720
|
|
721 if (r->headers_in.content_length_n > 0) {
|
|
722 r->lingering_close = 1;
|
|
723
|
|
724 } else {
|
|
725 r->lingering_close = 0;
|
|
726 }
|
236
|
727
|
230
|
728 r->phase_handler = 0;
|
|
729
|
|
730 } else {
|
|
731 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
|
|
732 r->phase_handler = cmcf->phase_engine.server_rewrite_index;
|
|
733 }
|
|
734
|
236
|
735 if (r->unparsed_uri.len) {
|
|
736 r->valid_unparsed_uri = 1;
|
|
737 }
|
|
738
|
|
739 r->valid_location = 1;
|
358
|
740 r->gzip = 0;
|
236
|
741
|
230
|
742 r->write_event_handler = ngx_http_core_run_phases;
|
34
|
743 ngx_http_core_run_phases(r);
|
0
|
744 }
|
|
745
|
|
746
|
230
|
747 void
|
36
|
748 ngx_http_core_run_phases(ngx_http_request_t *r)
|
0
|
749 {
|
|
750 ngx_int_t rc;
|
230
|
751 ngx_http_phase_handler_t *ph;
|
0
|
752 ngx_http_core_main_conf_t *cmcf;
|
|
753
|
|
754 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
|
|
755
|
230
|
756 ph = cmcf->phase_engine.handlers;
|
|
757
|
|
758 while (ph[r->phase_handler].checker) {
|
|
759
|
|
760 rc = ph[r->phase_handler].checker(r, &ph[r->phase_handler]);
|
|
761
|
|
762 if (rc == NGX_OK) {
|
92
|
763 return;
|
0
|
764 }
|
|
765 }
|
|
766 }
|
|
767
|
|
768
|
36
|
769 ngx_int_t
|
230
|
770 ngx_http_core_generic_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
|
|
771 {
|
|
772 ngx_int_t rc;
|
|
773
|
|
774 /*
|
|
775 * generic phase checker,
|
|
776 * used by the post read, server rewrite, rewrite, and pre-access phases
|
|
777 */
|
|
778
|
|
779 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
780 "generic phase: %ui", r->phase_handler);
|
|
781
|
|
782 rc = ph->handler(r);
|
|
783
|
|
784 if (rc == NGX_OK) {
|
|
785 r->phase_handler = ph->next;
|
|
786 return NGX_AGAIN;
|
|
787 }
|
|
788
|
|
789 if (rc == NGX_DECLINED) {
|
|
790 r->phase_handler++;
|
|
791 return NGX_AGAIN;
|
|
792 }
|
|
793
|
|
794 if (rc == NGX_AGAIN || rc == NGX_DONE) {
|
|
795 return NGX_OK;
|
|
796 }
|
|
797
|
|
798 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
|
|
799
|
|
800 ngx_http_finalize_request(r, rc);
|
|
801
|
|
802 return NGX_OK;
|
|
803 }
|
|
804
|
|
805
|
|
806 ngx_int_t
|
|
807 ngx_http_core_find_config_phase(ngx_http_request_t *r,
|
|
808 ngx_http_phase_handler_t *ph)
|
0
|
809 {
|
328
|
810 u_char *p;
|
|
811 size_t len;
|
382
|
812 ngx_int_t rc;
|
0
|
813 ngx_http_core_loc_conf_t *clcf;
|
|
814 ngx_http_core_srv_conf_t *cscf;
|
|
815
|
38
|
816 r->content_handler = NULL;
|
|
817 r->uri_changed = 0;
|
|
818
|
0
|
819 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
|
820
|
308
|
821 rc = ngx_http_core_find_location(r, &cscf->locations, cscf->regex_start, 0);
|
0
|
822
|
|
823 if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) {
|
230
|
824 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
825 return NGX_OK;
|
0
|
826 }
|
|
827
|
|
828 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
829
|
58
|
830 if (!r->internal && clcf->internal) {
|
230
|
831 ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
|
|
832 return NGX_OK;
|
58
|
833 }
|
|
834
|
104
|
835 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
836 "using configuration \"%s%V\"",
|
|
837 (clcf->noname ? "*" : (clcf->exact_match ? "=" : "")),
|
|
838 &clcf->name);
|
|
839
|
84
|
840 ngx_http_update_location_config(r);
|
0
|
841
|
|
842 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
212
|
843 "http cl:%O max:%O",
|
10
|
844 r->headers_in.content_length_n, clcf->client_max_body_size);
|
0
|
845
|
|
846 if (r->headers_in.content_length_n != -1
|
222
|
847 && !r->discard_body
|
0
|
848 && clcf->client_max_body_size
|
212
|
849 && clcf->client_max_body_size < r->headers_in.content_length_n)
|
0
|
850 {
|
|
851 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
342
|
852 "client intended to send too large body: %O bytes",
|
0
|
853 r->headers_in.content_length_n);
|
|
854
|
230
|
855 ngx_http_finalize_request(r, NGX_HTTP_REQUEST_ENTITY_TOO_LARGE);
|
|
856 return NGX_OK;
|
0
|
857 }
|
|
858
|
|
859 if (rc == NGX_HTTP_LOCATION_AUTO_REDIRECT) {
|
|
860 r->headers_out.location = ngx_list_push(&r->headers_out.headers);
|
|
861 if (r->headers_out.location == NULL) {
|
230
|
862 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
863 return NGX_OK;
|
0
|
864 }
|
|
865
|
58
|
866 /*
|
|
867 * we do not need to set the r->headers_out.location->hash and
|
|
868 * r->headers_out.location->key fields
|
|
869 */
|
|
870
|
328
|
871 if (r->args.len == 0) {
|
|
872 r->headers_out.location->value = clcf->name;
|
|
873
|
|
874 } else {
|
|
875 len = clcf->name.len + 1 + r->args.len;
|
|
876 p = ngx_palloc(r->pool, len);
|
|
877
|
|
878 if (p == NULL) {
|
|
879 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
880 return NGX_OK;
|
|
881 }
|
|
882
|
|
883 r->headers_out.location->value.len = len;
|
|
884 r->headers_out.location->value.data = p;
|
|
885
|
|
886 p = ngx_cpymem(p, clcf->name.data, clcf->name.len);
|
|
887 *p++ = '?';
|
|
888 ngx_memcpy(p, r->args.data, r->args.len);
|
|
889 }
|
0
|
890
|
230
|
891 ngx_http_finalize_request(r, NGX_HTTP_MOVED_PERMANENTLY);
|
|
892 return NGX_OK;
|
|
893 }
|
|
894
|
|
895 r->phase_handler++;
|
|
896 return NGX_AGAIN;
|
|
897 }
|
|
898
|
|
899
|
|
900 ngx_int_t
|
|
901 ngx_http_core_post_rewrite_phase(ngx_http_request_t *r,
|
|
902 ngx_http_phase_handler_t *ph)
|
|
903 {
|
|
904 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
905 "post rewrite phase: %ui", r->phase_handler);
|
|
906
|
|
907 if (!r->uri_changed) {
|
|
908 r->phase_handler++;
|
|
909 return NGX_AGAIN;
|
|
910 }
|
|
911
|
|
912 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
913 "uri changes: %d", r->uri_changes);
|
|
914
|
|
915 /*
|
|
916 * gcc before 3.3 compiles the broken code for
|
|
917 * if (r->uri_changes-- == 0)
|
|
918 * if the r->uri_changes is defined as
|
|
919 * unsigned uri_changes:4
|
|
920 */
|
|
921
|
|
922 r->uri_changes--;
|
|
923
|
|
924 if (r->uri_changes == 0) {
|
|
925 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
926 "rewrite or internal redirection cycle "
|
|
927 "while processing \"%V\"", &r->uri);
|
|
928
|
|
929 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
930 return NGX_OK;
|
|
931 }
|
|
932
|
|
933 r->phase_handler = ph->next;
|
|
934
|
|
935 return NGX_AGAIN;
|
|
936 }
|
|
937
|
|
938
|
|
939 ngx_int_t
|
|
940 ngx_http_core_access_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
|
|
941 {
|
|
942 ngx_int_t rc;
|
|
943 ngx_http_core_loc_conf_t *clcf;
|
|
944
|
|
945 if (r != r->main) {
|
|
946 r->phase_handler = ph->next;
|
|
947 return NGX_AGAIN;
|
|
948 }
|
|
949
|
|
950 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
951 "access phase: %ui", r->phase_handler);
|
|
952
|
|
953 rc = ph->handler(r);
|
|
954
|
|
955 if (rc == NGX_DECLINED) {
|
|
956 r->phase_handler++;
|
|
957 return NGX_AGAIN;
|
|
958 }
|
|
959
|
|
960 if (rc == NGX_AGAIN || rc == NGX_DONE) {
|
|
961 return NGX_OK;
|
0
|
962 }
|
|
963
|
230
|
964 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
965
|
362
|
966 if (clcf->satisfy == NGX_HTTP_SATISFY_ALL) {
|
230
|
967
|
|
968 if (rc == NGX_OK) {
|
|
969 r->phase_handler++;
|
|
970 return NGX_AGAIN;
|
|
971 }
|
|
972
|
|
973 } else {
|
|
974 if (rc == NGX_OK) {
|
|
975 r->access_code = 0;
|
|
976
|
|
977 if (r->headers_out.www_authenticate) {
|
|
978 r->headers_out.www_authenticate->hash = 0;
|
|
979 }
|
|
980
|
|
981 r->phase_handler = ph->next;
|
|
982 return NGX_AGAIN;
|
|
983 }
|
|
984
|
|
985 if (rc == NGX_HTTP_FORBIDDEN || rc == NGX_HTTP_UNAUTHORIZED) {
|
|
986 r->access_code = rc;
|
|
987
|
|
988 r->phase_handler++;
|
|
989 return NGX_AGAIN;
|
|
990 }
|
|
991 }
|
|
992
|
|
993 /* rc == NGX_ERROR || rc == NGX_HTTP_... */
|
|
994
|
|
995 ngx_http_finalize_request(r, rc);
|
|
996 return NGX_OK;
|
|
997 }
|
|
998
|
|
999
|
|
1000 ngx_int_t
|
|
1001 ngx_http_core_post_access_phase(ngx_http_request_t *r,
|
|
1002 ngx_http_phase_handler_t *ph)
|
|
1003 {
|
|
1004 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1005 "post access phase: %ui", r->phase_handler);
|
|
1006
|
|
1007 if (r->access_code) {
|
|
1008
|
|
1009 if (r->access_code == NGX_HTTP_FORBIDDEN) {
|
|
1010 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1011 "access forbidden by rule");
|
|
1012 }
|
|
1013
|
|
1014 ngx_http_finalize_request(r, r->access_code);
|
|
1015 return NGX_OK;
|
|
1016 }
|
|
1017
|
|
1018 r->phase_handler++;
|
|
1019 return NGX_AGAIN;
|
|
1020 }
|
|
1021
|
|
1022
|
|
1023 ngx_int_t
|
384
|
1024 ngx_http_core_try_files_phase(ngx_http_request_t *r,
|
|
1025 ngx_http_phase_handler_t *ph)
|
|
1026 {
|
|
1027 size_t len, root, alias, reserve, allocated;
|
|
1028 u_char *p, *name;
|
|
1029 ngx_str_t path, args;
|
|
1030 ngx_uint_t test_dir;
|
|
1031 ngx_http_try_file_t *tf;
|
|
1032 ngx_open_file_info_t of;
|
|
1033 ngx_http_script_code_pt code;
|
|
1034 ngx_http_script_engine_t e;
|
|
1035 ngx_http_core_loc_conf_t *clcf;
|
|
1036 ngx_http_script_len_code_pt lcode;
|
|
1037
|
|
1038 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1039 "try files phase: %ui", r->phase_handler);
|
|
1040
|
|
1041 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1042
|
|
1043 if (clcf->try_files == NULL) {
|
|
1044 r->phase_handler++;
|
|
1045 return NGX_AGAIN;
|
|
1046 }
|
|
1047
|
|
1048 allocated = 0;
|
|
1049 root = 0;
|
|
1050 name = NULL;
|
|
1051 /* suppress MSVC warning */
|
|
1052 path.data = NULL;
|
|
1053
|
|
1054 tf = clcf->try_files;
|
|
1055
|
|
1056 alias = clcf->alias ? clcf->name.len : 0;
|
|
1057
|
|
1058 for ( ;; ) {
|
|
1059
|
|
1060 if (tf->lengths) {
|
|
1061 ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
|
|
1062
|
|
1063 e.ip = tf->lengths->elts;
|
|
1064 e.request = r;
|
|
1065
|
|
1066 /* 1 is for terminating '\0' as in static names */
|
|
1067 len = 1;
|
|
1068
|
|
1069 while (*(uintptr_t *) e.ip) {
|
|
1070 lcode = *(ngx_http_script_len_code_pt *) e.ip;
|
|
1071 len += lcode(&e);
|
|
1072 }
|
|
1073
|
|
1074 } else {
|
|
1075 len = tf->name.len;
|
|
1076 }
|
|
1077
|
|
1078 /* 16 bytes are preallocation */
|
|
1079 reserve = ngx_abs((ssize_t) (len - r->uri.len)) + alias + 16;
|
|
1080
|
|
1081 if (reserve > allocated) {
|
|
1082
|
|
1083 /* we just need to allocate path and to copy a root */
|
|
1084
|
|
1085 if (ngx_http_map_uri_to_path(r, &path, &root, reserve) == NULL) {
|
|
1086 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
1087 return NGX_OK;
|
|
1088 }
|
|
1089
|
|
1090 name = path.data + root;
|
|
1091 allocated = path.len - root - (r->uri.len - alias);
|
|
1092 }
|
|
1093
|
|
1094 if (tf->values == NULL) {
|
|
1095
|
|
1096 /* tf->name.len includes the terminating '\0' */
|
|
1097
|
|
1098 ngx_memcpy(name, tf->name.data, tf->name.len);
|
|
1099
|
|
1100 path.len = (name + tf->name.len - 1) - path.data;
|
|
1101
|
|
1102 } else {
|
|
1103 e.ip = tf->values->elts;
|
|
1104 e.pos = name;
|
|
1105 e.flushed = 1;
|
|
1106
|
|
1107 while (*(uintptr_t *) e.ip) {
|
|
1108 code = *(ngx_http_script_code_pt *) e.ip;
|
|
1109 code((ngx_http_script_engine_t *) &e);
|
|
1110 }
|
|
1111
|
|
1112 path.len = e.pos - path.data;
|
|
1113
|
|
1114 *e.pos = '\0';
|
|
1115
|
|
1116 if (alias && ngx_strncmp(name, clcf->name.data, alias) == 0) {
|
|
1117 ngx_memcpy(name, name + alias, len - alias);
|
|
1118 path.len -= alias;
|
|
1119 }
|
|
1120 }
|
|
1121
|
|
1122 test_dir = tf->test_dir;
|
|
1123
|
|
1124 tf++;
|
|
1125
|
|
1126 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1127 "try to use file: \"%s\" \"%s\"", name, path.data);
|
|
1128
|
|
1129 if (tf->lengths == NULL && tf->name.len == 0) {
|
|
1130
|
|
1131 path.len -= root;
|
|
1132 path.data += root;
|
|
1133
|
|
1134 if (path.data[0] == '@') {
|
|
1135 (void) ngx_http_named_location(r, &path);
|
|
1136
|
|
1137 } else {
|
|
1138 ngx_http_split_args(r, &path, &args);
|
|
1139
|
|
1140 (void) ngx_http_internal_redirect(r, &path, &args);
|
|
1141 }
|
|
1142
|
|
1143 return NGX_OK;
|
|
1144 }
|
|
1145
|
|
1146 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
|
|
1147
|
|
1148 of.valid = clcf->open_file_cache_valid;
|
|
1149 of.min_uses = clcf->open_file_cache_min_uses;
|
|
1150 of.errors = clcf->open_file_cache_errors;
|
|
1151 of.events = clcf->open_file_cache_events;
|
|
1152
|
|
1153 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
|
|
1154 != NGX_OK)
|
|
1155 {
|
|
1156 if (of.err != NGX_ENOENT && of.err != NGX_ENOTDIR) {
|
|
1157 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
|
|
1158 ngx_open_file_n " \"%s\" failed", path.data);
|
|
1159 }
|
|
1160
|
|
1161 continue;
|
|
1162 }
|
|
1163
|
|
1164 if (of.is_dir && !test_dir) {
|
|
1165 continue;
|
|
1166 }
|
|
1167
|
|
1168 path.len -= root;
|
|
1169 path.data += root;
|
|
1170
|
|
1171 if (!alias) {
|
|
1172 r->uri = path;
|
|
1173
|
|
1174 } else {
|
|
1175 r->uri.len = alias + path.len;
|
|
1176 r->uri.data = ngx_palloc(r->pool, r->uri.len);
|
|
1177 if (r->uri.data == NULL) {
|
|
1178 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
1179 return NGX_OK;
|
|
1180 }
|
|
1181
|
|
1182 p = ngx_copy(r->uri.data, clcf->name.data, alias);
|
|
1183 ngx_memcpy(p, name, path.len);
|
|
1184 }
|
|
1185
|
|
1186 if (ngx_http_set_exten(r) != NGX_OK) {
|
|
1187 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
1188 return NGX_OK;
|
|
1189 }
|
|
1190
|
|
1191 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1192 "try file uri: \"%V\"", &r->uri);
|
|
1193
|
|
1194 r->phase_handler++;
|
|
1195 return NGX_AGAIN;
|
|
1196 }
|
|
1197
|
|
1198 /* not reached */
|
|
1199 }
|
|
1200
|
|
1201
|
|
1202 ngx_int_t
|
230
|
1203 ngx_http_core_content_phase(ngx_http_request_t *r,
|
|
1204 ngx_http_phase_handler_t *ph)
|
|
1205 {
|
248
|
1206 size_t root;
|
230
|
1207 ngx_int_t rc;
|
|
1208 ngx_str_t path;
|
|
1209
|
|
1210 if (r->content_handler) {
|
|
1211 r->write_event_handler = ngx_http_request_empty_handler;
|
|
1212 ngx_http_finalize_request(r, r->content_handler(r));
|
|
1213 return NGX_OK;
|
|
1214 }
|
|
1215
|
|
1216 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1217 "content phase: %ui", r->phase_handler);
|
|
1218
|
|
1219 rc = ph->handler(r);
|
|
1220
|
|
1221 if (rc == NGX_DONE) {
|
|
1222 return NGX_OK;
|
|
1223 }
|
|
1224
|
|
1225 if (rc != NGX_DECLINED) {
|
|
1226 ngx_http_finalize_request(r, rc);
|
|
1227 return NGX_OK;
|
|
1228 }
|
|
1229
|
|
1230 /* rc == NGX_DECLINED */
|
|
1231
|
|
1232 ph++;
|
|
1233
|
|
1234 if (ph->checker) {
|
|
1235 r->phase_handler++;
|
|
1236 return NGX_AGAIN;
|
|
1237 }
|
|
1238
|
|
1239 /* no content handler was found */
|
|
1240
|
|
1241 if (r->uri.data[r->uri.len - 1] == '/' && !r->zero_in_uri) {
|
|
1242
|
248
|
1243 if (ngx_http_map_uri_to_path(r, &path, &root, 0) != NULL) {
|
230
|
1244 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
340
|
1245 "directory index of \"%s\" is forbidden", path.data);
|
230
|
1246 }
|
|
1247
|
|
1248 ngx_http_finalize_request(r, NGX_HTTP_FORBIDDEN);
|
|
1249 return NGX_OK;
|
|
1250 }
|
|
1251
|
|
1252 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no handler found");
|
|
1253
|
|
1254 ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
|
84
|
1255 return NGX_OK;
|
|
1256 }
|
|
1257
|
|
1258
|
|
1259 void
|
|
1260 ngx_http_update_location_config(ngx_http_request_t *r)
|
|
1261 {
|
|
1262 ngx_http_core_loc_conf_t *clcf;
|
|
1263
|
|
1264 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1265
|
180
|
1266 if (r->method & clcf->limit_except) {
|
|
1267 r->loc_conf = clcf->limit_except_loc_conf;
|
|
1268 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1269 }
|
|
1270
|
192
|
1271 if (r == r->main) {
|
294
|
1272 r->connection->log->file = clcf->err_log->file;
|
|
1273
|
192
|
1274 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
|
|
1275 r->connection->log->log_level = clcf->err_log->log_level;
|
|
1276 }
|
84
|
1277 }
|
|
1278
|
|
1279 if ((ngx_io.flags & NGX_IO_SENDFILE) && clcf->sendfile) {
|
|
1280 r->connection->sendfile = 1;
|
|
1281
|
|
1282 } else {
|
|
1283 r->connection->sendfile = 0;
|
|
1284 }
|
|
1285
|
182
|
1286 if (clcf->client_body_in_file_only) {
|
|
1287 r->request_body_in_file_only = 1;
|
|
1288 r->request_body_in_persistent_file = 1;
|
278
|
1289 r->request_body_in_clean_file =
|
|
1290 clcf->client_body_in_file_only == NGX_HTTP_REQUEST_BODY_FILE_CLEAN;
|
186
|
1291 r->request_body_file_log_level = NGX_LOG_NOTICE;
|
|
1292
|
|
1293 } else {
|
|
1294 r->request_body_file_log_level = NGX_LOG_WARN;
|
182
|
1295 }
|
|
1296
|
84
|
1297 if (r->keepalive && clcf->keepalive_timeout == 0) {
|
|
1298 r->keepalive = 0;
|
|
1299 }
|
|
1300
|
|
1301 if (!clcf->tcp_nopush) {
|
|
1302 /* disable TCP_NOPUSH/TCP_CORK use */
|
|
1303 r->connection->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;
|
|
1304 }
|
|
1305
|
162
|
1306 if (r->limit_rate == 0) {
|
|
1307 r->limit_rate = clcf->limit_rate;
|
|
1308 }
|
76
|
1309
|
0
|
1310 if (clcf->handler) {
|
|
1311 r->content_handler = clcf->handler;
|
|
1312 }
|
|
1313 }
|
|
1314
|
|
1315
|
36
|
1316 static ngx_int_t
|
|
1317 ngx_http_core_find_location(ngx_http_request_t *r,
|
308
|
1318 ngx_array_t *locations, ngx_uint_t regex_start, size_t len)
|
0
|
1319 {
|
|
1320 ngx_int_t n, rc;
|
326
|
1321 ngx_uint_t i, found;
|
0
|
1322 ngx_http_core_loc_conf_t *clcf, **clcfp;
|
326
|
1323 #if (NGX_PCRE)
|
|
1324 ngx_uint_t noregex;
|
|
1325 #endif
|
0
|
1326
|
104
|
1327 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1328 "find location for \"%V\"", &r->uri);
|
0
|
1329
|
|
1330 found = 0;
|
326
|
1331 #if (NGX_PCRE)
|
16
|
1332 noregex = 0;
|
326
|
1333 #endif
|
0
|
1334
|
|
1335 clcfp = locations->elts;
|
|
1336 for (i = 0; i < locations->nelts; i++) {
|
|
1337
|
324
|
1338 if (clcfp[i]->noname
|
4
|
1339 #if (NGX_PCRE)
|
324
|
1340 || clcfp[i]->regex
|
0
|
1341 #endif
|
324
|
1342 || clcfp[i]->named)
|
|
1343 {
|
34
|
1344 break;
|
|
1345 }
|
|
1346
|
0
|
1347 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
10
|
1348 "find location: %s\"%V\"",
|
|
1349 clcfp[i]->exact_match ? "= " : "", &clcfp[i]->name);
|
0
|
1350
|
|
1351 if (clcfp[i]->auto_redirect
|
|
1352 && r->uri.len == clcfp[i]->name.len - 1
|
|
1353 && ngx_strncmp(r->uri.data, clcfp[i]->name.data,
|
274
|
1354 clcfp[i]->name.len - 1)
|
|
1355 == 0)
|
0
|
1356 {
|
|
1357 /* the locations are lexicographically sorted */
|
|
1358
|
|
1359 r->loc_conf = clcfp[i]->loc_conf;
|
|
1360
|
|
1361 return NGX_HTTP_LOCATION_AUTO_REDIRECT;
|
|
1362 }
|
|
1363
|
|
1364 if (r->uri.len < clcfp[i]->name.len) {
|
|
1365 continue;
|
|
1366 }
|
|
1367
|
|
1368 n = ngx_strncmp(r->uri.data, clcfp[i]->name.data, clcfp[i]->name.len);
|
|
1369
|
|
1370 if (n < 0) {
|
|
1371 /* the locations are lexicographically sorted */
|
|
1372 break;
|
|
1373 }
|
|
1374
|
|
1375 if (n == 0) {
|
34
|
1376 if (clcfp[i]->exact_match) {
|
|
1377
|
|
1378 if (r->uri.len == clcfp[i]->name.len) {
|
|
1379 r->loc_conf = clcfp[i]->loc_conf;
|
|
1380 return NGX_HTTP_LOCATION_EXACT;
|
|
1381 }
|
|
1382
|
|
1383 continue;
|
0
|
1384 }
|
|
1385
|
|
1386 if (len > clcfp[i]->name.len) {
|
|
1387 /* the previous match is longer */
|
|
1388 break;
|
|
1389 }
|
|
1390
|
326
|
1391 found = 1;
|
|
1392
|
0
|
1393 r->loc_conf = clcfp[i]->loc_conf;
|
326
|
1394 #if (NGX_PCRE)
|
16
|
1395 noregex = clcfp[i]->noregex;
|
326
|
1396 #endif
|
0
|
1397 }
|
|
1398 }
|
|
1399
|
|
1400 if (found) {
|
|
1401 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1402
|
308
|
1403 if (clcf->locations) {
|
|
1404 rc = ngx_http_core_find_location(r, clcf->locations,
|
|
1405 clcf->regex_start, len);
|
0
|
1406
|
|
1407 if (rc != NGX_OK) {
|
|
1408 return rc;
|
|
1409 }
|
|
1410 }
|
|
1411 }
|
|
1412
|
4
|
1413 #if (NGX_PCRE)
|
0
|
1414
|
16
|
1415 if (noregex) {
|
|
1416 return NGX_HTTP_LOCATION_NOREGEX;
|
|
1417 }
|
|
1418
|
0
|
1419 /* regex matches */
|
|
1420
|
308
|
1421 for (i = regex_start; i < locations->nelts; i++) {
|
0
|
1422
|
324
|
1423 if (!clcfp[i]->regex) {
|
34
|
1424 break;
|
|
1425 }
|
|
1426
|
0
|
1427 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
10
|
1428 "find location: ~ \"%V\"", &clcfp[i]->name);
|
0
|
1429
|
|
1430 n = ngx_regex_exec(clcfp[i]->regex, &r->uri, NULL, 0);
|
|
1431
|
30
|
1432 if (n == NGX_REGEX_NO_MATCHED) {
|
0
|
1433 continue;
|
|
1434 }
|
|
1435
|
|
1436 if (n < 0) {
|
|
1437 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
|
1438 ngx_regex_exec_n
|
10
|
1439 " failed: %d on \"%V\" using \"%V\"",
|
|
1440 n, &r->uri, &clcfp[i]->name);
|
0
|
1441 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
1442 }
|
|
1443
|
|
1444 /* match */
|
|
1445
|
|
1446 r->loc_conf = clcfp[i]->loc_conf;
|
|
1447
|
|
1448 return NGX_HTTP_LOCATION_REGEX;
|
|
1449 }
|
|
1450
|
4
|
1451 #endif /* NGX_PCRE */
|
0
|
1452
|
|
1453 return NGX_OK;
|
|
1454 }
|
|
1455
|
|
1456
|
36
|
1457 ngx_int_t
|
|
1458 ngx_http_set_content_type(ngx_http_request_t *r)
|
0
|
1459 {
|
34
|
1460 u_char c, *p, *exten;
|
138
|
1461 ngx_str_t *type;
|
198
|
1462 ngx_uint_t i, hash;
|
0
|
1463 ngx_http_core_loc_conf_t *clcf;
|
|
1464
|
222
|
1465 if (r->headers_out.content_type.len) {
|
|
1466 return NGX_OK;
|
|
1467 }
|
|
1468
|
0
|
1469 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1470
|
|
1471 if (r->exten.len) {
|
34
|
1472
|
198
|
1473 hash = 0;
|
|
1474
|
|
1475 for (i = 0; i < r->exten.len; i++) {
|
|
1476 c = r->exten.data[i];
|
|
1477
|
|
1478 if (c >= 'A' && c <= 'Z') {
|
|
1479
|
50
|
1480 p = ngx_palloc(r->pool, r->exten.len);
|
|
1481 if (p == NULL) {
|
34
|
1482 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
1483 }
|
|
1484
|
198
|
1485 hash = 0;
|
34
|
1486 exten = p;
|
|
1487
|
|
1488 for (i = 0; i < r->exten.len; i++) {
|
198
|
1489 c = ngx_tolower(r->exten.data[i]);
|
|
1490 hash = ngx_hash(hash, c);
|
|
1491 *p++ = c;
|
34
|
1492 }
|
|
1493
|
|
1494 r->exten.data = exten;
|
198
|
1495
|
|
1496 break;
|
34
|
1497 }
|
|
1498
|
198
|
1499 hash = ngx_hash(hash, c);
|
34
|
1500 }
|
|
1501
|
198
|
1502 type = ngx_hash_find(&clcf->types_hash, hash,
|
138
|
1503 r->exten.data, r->exten.len);
|
|
1504
|
|
1505 if (type) {
|
206
|
1506 r->headers_out.content_type_len = type->len;
|
138
|
1507 r->headers_out.content_type = *type;
|
206
|
1508
|
138
|
1509 return NGX_OK;
|
0
|
1510 }
|
|
1511 }
|
|
1512
|
206
|
1513 r->headers_out.content_type_len = clcf->default_type.len;
|
138
|
1514 r->headers_out.content_type = clcf->default_type;
|
0
|
1515
|
|
1516 return NGX_OK;
|
|
1517 }
|
|
1518
|
|
1519
|
36
|
1520 ngx_int_t
|
|
1521 ngx_http_set_exten(ngx_http_request_t *r)
|
0
|
1522 {
|
|
1523 ngx_int_t i;
|
|
1524
|
|
1525 r->exten.len = 0;
|
|
1526 r->exten.data = NULL;
|
|
1527
|
|
1528 for (i = r->uri.len - 1; i > 1; i--) {
|
|
1529 if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {
|
198
|
1530
|
0
|
1531 r->exten.len = r->uri.len - i - 1;
|
198
|
1532 r->exten.data = &r->uri.data[i + 1];
|
0
|
1533
|
|
1534 break;
|
|
1535
|
|
1536 } else if (r->uri.data[i] == '/') {
|
|
1537 break;
|
|
1538 }
|
|
1539 }
|
|
1540
|
|
1541 return NGX_OK;
|
|
1542 }
|
|
1543
|
|
1544
|
36
|
1545 ngx_int_t
|
106
|
1546 ngx_http_send_header(ngx_http_request_t *r)
|
|
1547 {
|
|
1548 if (r->err_status) {
|
|
1549 r->headers_out.status = r->err_status;
|
|
1550 r->headers_out.status_line.len = 0;
|
|
1551 }
|
|
1552
|
|
1553 return ngx_http_top_header_filter(r);
|
|
1554 }
|
|
1555
|
|
1556
|
|
1557 ngx_int_t
|
|
1558 ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
|
1559 {
|
386
|
1560 ngx_int_t rc;
|
|
1561 ngx_connection_t *c;
|
|
1562
|
|
1563 c = r->connection;
|
|
1564
|
|
1565 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
132
|
1566 "http output filter \"%V?%V\"", &r->uri, &r->args);
|
106
|
1567
|
|
1568 rc = ngx_http_top_body_filter(r, in);
|
|
1569
|
|
1570 if (rc == NGX_ERROR) {
|
386
|
1571
|
|
1572 if (c->destroyed) {
|
|
1573 return NGX_DONE;
|
|
1574 }
|
|
1575
|
106
|
1576 /* NGX_ERROR may be returned by any filter */
|
386
|
1577 c->error = 1;
|
106
|
1578 }
|
|
1579
|
|
1580 return rc;
|
|
1581 }
|
|
1582
|
|
1583
|
|
1584 u_char *
|
|
1585 ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,
|
248
|
1586 size_t *root_length, size_t reserved)
|
106
|
1587 {
|
172
|
1588 u_char *last;
|
|
1589 size_t alias;
|
|
1590 ngx_http_core_loc_conf_t *clcf;
|
106
|
1591
|
|
1592 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1593
|
|
1594 alias = clcf->alias ? clcf->name.len : 0;
|
|
1595
|
152
|
1596 if (alias && !r->valid_location) {
|
|
1597 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
|
1598 "\"alias\" could not be used in location \"%V\" "
|
|
1599 "where URI was rewritten", &clcf->name);
|
|
1600 return NULL;
|
|
1601 }
|
|
1602
|
172
|
1603 reserved += r->uri.len - alias + 1;
|
|
1604
|
144
|
1605 if (clcf->root_lengths == NULL) {
|
|
1606
|
248
|
1607 *root_length = clcf->root.len;
|
144
|
1608
|
172
|
1609 path->len = clcf->root.len + reserved;
|
144
|
1610
|
|
1611 path->data = ngx_palloc(r->pool, path->len);
|
|
1612 if (path->data == NULL) {
|
|
1613 return NULL;
|
|
1614 }
|
|
1615
|
|
1616 last = ngx_copy(path->data, clcf->root.data, clcf->root.len);
|
172
|
1617
|
|
1618 } else {
|
216
|
1619 if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved,
|
220
|
1620 clcf->root_values->elts)
|
216
|
1621 == NULL)
|
|
1622 {
|
|
1623 return NULL;
|
|
1624 }
|
|
1625
|
324
|
1626 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, path, 0)== NGX_ERROR)
|
|
1627 {
|
172
|
1628 return NULL;
|
|
1629 }
|
|
1630
|
248
|
1631 *root_length = path->len - reserved;
|
|
1632 last = path->data + *root_length;
|
144
|
1633 }
|
|
1634
|
172
|
1635 last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1);
|
106
|
1636
|
|
1637 return last;
|
|
1638 }
|
|
1639
|
|
1640
|
|
1641 ngx_int_t
|
88
|
1642 ngx_http_auth_basic_user(ngx_http_request_t *r)
|
|
1643 {
|
|
1644 ngx_str_t auth, encoded;
|
|
1645 ngx_uint_t len;
|
|
1646
|
|
1647 if (r->headers_in.user.len == 0 && r->headers_in.user.data != NULL) {
|
|
1648 return NGX_DECLINED;
|
|
1649 }
|
|
1650
|
|
1651 if (r->headers_in.authorization == NULL) {
|
|
1652 r->headers_in.user.data = (u_char *) "";
|
|
1653 return NGX_DECLINED;
|
|
1654 }
|
|
1655
|
|
1656 encoded = r->headers_in.authorization->value;
|
|
1657
|
|
1658 if (encoded.len < sizeof("Basic ") - 1
|
286
|
1659 || ngx_strncasecmp(encoded.data, (u_char *) "Basic ",
|
|
1660 sizeof("Basic ") - 1)
|
|
1661 != 0)
|
88
|
1662 {
|
|
1663 r->headers_in.user.data = (u_char *) "";
|
|
1664 return NGX_DECLINED;
|
|
1665 }
|
|
1666
|
|
1667 encoded.len -= sizeof("Basic ") - 1;
|
|
1668 encoded.data += sizeof("Basic ") - 1;
|
|
1669
|
|
1670 while (encoded.len && encoded.data[0] == ' ') {
|
|
1671 encoded.len--;
|
|
1672 encoded.data++;
|
|
1673 }
|
|
1674
|
|
1675 if (encoded.len == 0) {
|
|
1676 r->headers_in.user.data = (u_char *) "";
|
|
1677 return NGX_DECLINED;
|
|
1678 }
|
126
|
1679
|
88
|
1680 auth.len = ngx_base64_decoded_length(encoded.len);
|
126
|
1681 auth.data = ngx_palloc(r->pool, auth.len + 1);
|
88
|
1682 if (auth.data == NULL) {
|
|
1683 return NGX_ERROR;
|
|
1684 }
|
|
1685
|
|
1686 if (ngx_decode_base64(&auth, &encoded) != NGX_OK) {
|
|
1687 r->headers_in.user.data = (u_char *) "";
|
|
1688 return NGX_DECLINED;
|
|
1689 }
|
126
|
1690
|
88
|
1691 auth.data[auth.len] = '\0';
|
126
|
1692
|
|
1693 for (len = 0; len < auth.len; len++) {
|
88
|
1694 if (auth.data[len] == ':') {
|
|
1695 break;
|
|
1696 }
|
|
1697 }
|
126
|
1698
|
122
|
1699 if (len == 0 || len == auth.len) {
|
88
|
1700 r->headers_in.user.data = (u_char *) "";
|
|
1701 return NGX_DECLINED;
|
|
1702 }
|
|
1703
|
|
1704 r->headers_in.user.len = len;
|
|
1705 r->headers_in.user.data = auth.data;
|
|
1706 r->headers_in.passwd.len = auth.len - len - 1;
|
|
1707 r->headers_in.passwd.data = &auth.data[len + 1];
|
|
1708
|
|
1709 return NGX_OK;
|
|
1710 }
|
|
1711
|
|
1712
|
362
|
1713 ngx_int_t
|
|
1714 ngx_http_server_addr(ngx_http_request_t *r, ngx_str_t *s)
|
|
1715 {
|
|
1716 socklen_t len;
|
|
1717 ngx_connection_t *c;
|
|
1718 struct sockaddr_in sin;
|
|
1719
|
|
1720 /* AF_INET only */
|
|
1721
|
|
1722 c = r->connection;
|
|
1723
|
|
1724 if (r->in_addr == 0) {
|
|
1725 len = sizeof(struct sockaddr_in);
|
|
1726 if (getsockname(c->fd, (struct sockaddr *) &sin, &len) == -1) {
|
|
1727 ngx_connection_error(c, ngx_socket_errno, "getsockname() failed");
|
|
1728 return NGX_ERROR;
|
|
1729 }
|
|
1730
|
|
1731 r->in_addr = sin.sin_addr.s_addr;
|
|
1732 }
|
|
1733
|
|
1734 if (s == NULL) {
|
|
1735 return NGX_OK;
|
|
1736 }
|
|
1737
|
|
1738 s->len = ngx_inet_ntop(c->listening->family, &r->in_addr,
|
|
1739 s->data, INET_ADDRSTRLEN);
|
|
1740
|
|
1741 return NGX_OK;
|
|
1742 }
|
|
1743
|
|
1744
|
358
|
1745 #if (NGX_HTTP_GZIP)
|
|
1746
|
|
1747 ngx_int_t
|
|
1748 ngx_http_gzip_ok(ngx_http_request_t *r)
|
|
1749 {
|
|
1750 time_t date, expires;
|
|
1751 ngx_uint_t p;
|
|
1752 ngx_array_t *cc;
|
|
1753 ngx_table_elt_t *e, *d;
|
|
1754 ngx_http_core_loc_conf_t *clcf;
|
|
1755
|
|
1756 if (r->gzip == 1) {
|
|
1757 return NGX_OK;
|
|
1758 }
|
|
1759
|
|
1760 if (r->gzip == 2) {
|
|
1761 return NGX_DECLINED;
|
|
1762 }
|
|
1763
|
|
1764 r->gzip = 2;
|
|
1765
|
|
1766 if (r != r->main
|
|
1767 || r->headers_in.accept_encoding == NULL
|
|
1768 || ngx_strcasestrn(r->headers_in.accept_encoding->value.data,
|
|
1769 "gzip", 4 - 1)
|
|
1770 == NULL
|
|
1771
|
|
1772 /*
|
|
1773 * if the URL (without the "http://" prefix) is longer than 253 bytes,
|
|
1774 * then MSIE 4.x can not handle the compressed stream - it waits
|
|
1775 * too long, hangs up or crashes
|
|
1776 */
|
|
1777
|
|
1778 || (r->headers_in.msie4 && r->unparsed_uri.len > 200))
|
|
1779 {
|
|
1780 return NGX_DECLINED;
|
|
1781 }
|
|
1782
|
|
1783 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1784
|
|
1785 if (r->http_version < clcf->gzip_http_version) {
|
|
1786 return NGX_DECLINED;
|
|
1787 }
|
|
1788
|
|
1789 if (r->headers_in.via == NULL) {
|
|
1790 goto ok;
|
|
1791 }
|
|
1792
|
|
1793 p = clcf->gzip_proxied;
|
|
1794
|
|
1795 if (p & NGX_HTTP_GZIP_PROXIED_OFF) {
|
|
1796 return NGX_DECLINED;
|
|
1797 }
|
|
1798
|
|
1799 if (p & NGX_HTTP_GZIP_PROXIED_ANY) {
|
|
1800 goto ok;
|
|
1801 }
|
|
1802
|
|
1803 if (r->headers_in.authorization && (p & NGX_HTTP_GZIP_PROXIED_AUTH)) {
|
|
1804 goto ok;
|
|
1805 }
|
|
1806
|
|
1807 e = r->headers_out.expires;
|
|
1808
|
|
1809 if (e) {
|
|
1810
|
|
1811 if (!(p & NGX_HTTP_GZIP_PROXIED_EXPIRED)) {
|
|
1812 return NGX_DECLINED;
|
|
1813 }
|
|
1814
|
|
1815 expires = ngx_http_parse_time(e->value.data, e->value.len);
|
|
1816 if (expires == NGX_ERROR) {
|
|
1817 return NGX_DECLINED;
|
|
1818 }
|
|
1819
|
|
1820 d = r->headers_out.date;
|
|
1821
|
|
1822 if (d) {
|
|
1823 date = ngx_http_parse_time(d->value.data, d->value.len);
|
|
1824 if (date == NGX_ERROR) {
|
|
1825 return NGX_DECLINED;
|
|
1826 }
|
|
1827
|
|
1828 } else {
|
|
1829 date = ngx_time();
|
|
1830 }
|
|
1831
|
|
1832 if (expires < date) {
|
|
1833 goto ok;
|
|
1834 }
|
|
1835
|
|
1836 return NGX_DECLINED;
|
|
1837 }
|
|
1838
|
|
1839 cc = &r->headers_out.cache_control;
|
|
1840
|
|
1841 if (cc->elts) {
|
|
1842
|
|
1843 if ((p & NGX_HTTP_GZIP_PROXIED_NO_CACHE)
|
|
1844 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_cache,
|
|
1845 NULL)
|
|
1846 >= 0)
|
|
1847 {
|
|
1848 goto ok;
|
|
1849 }
|
|
1850
|
|
1851 if ((p & NGX_HTTP_GZIP_PROXIED_NO_STORE)
|
|
1852 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_store,
|
|
1853 NULL)
|
|
1854 >= 0)
|
|
1855 {
|
|
1856 goto ok;
|
|
1857 }
|
|
1858
|
|
1859 if ((p & NGX_HTTP_GZIP_PROXIED_PRIVATE)
|
|
1860 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_private,
|
|
1861 NULL)
|
|
1862 >= 0)
|
|
1863 {
|
|
1864 goto ok;
|
|
1865 }
|
|
1866
|
|
1867 return NGX_DECLINED;
|
|
1868 }
|
|
1869
|
|
1870 if ((p & NGX_HTTP_GZIP_PROXIED_NO_LM) && r->headers_out.last_modified) {
|
|
1871 return NGX_DECLINED;
|
|
1872 }
|
|
1873
|
|
1874 if ((p & NGX_HTTP_GZIP_PROXIED_NO_ETAG) && r->headers_out.etag) {
|
|
1875 return NGX_DECLINED;
|
|
1876 }
|
|
1877
|
|
1878 ok:
|
|
1879
|
|
1880 #if (NGX_PCRE)
|
|
1881
|
|
1882 if (clcf->gzip_disable && r->headers_in.user_agent) {
|
|
1883
|
362
|
1884 if (ngx_regex_exec_array(clcf->gzip_disable,
|
358
|
1885 &r->headers_in.user_agent->value,
|
|
1886 r->connection->log)
|
|
1887 != NGX_DECLINED)
|
|
1888 {
|
|
1889 return NGX_DECLINED;
|
|
1890 }
|
|
1891 }
|
|
1892
|
|
1893 #endif
|
|
1894
|
|
1895 r->gzip = 1;
|
|
1896
|
|
1897 return NGX_OK;
|
|
1898 }
|
|
1899
|
|
1900 #endif
|
|
1901
|
|
1902
|
88
|
1903 ngx_int_t
|
58
|
1904 ngx_http_subrequest(ngx_http_request_t *r,
|
244
|
1905 ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **psr,
|
248
|
1906 ngx_http_post_subrequest_t *ps, ngx_uint_t flags)
|
58
|
1907 {
|
132
|
1908 ngx_connection_t *c;
|
58
|
1909 ngx_http_request_t *sr;
|
214
|
1910 ngx_http_log_ctx_t *ctx;
|
58
|
1911 ngx_http_core_srv_conf_t *cscf;
|
|
1912 ngx_http_postponed_request_t *pr, *p;
|
|
1913
|
206
|
1914 r->main->subrequests--;
|
|
1915
|
|
1916 if (r->main->subrequests == 0) {
|
|
1917 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
228
|
1918 "subrequests cycle while processing \"%V\"", uri);
|
256
|
1919 r->main->subrequests = 1;
|
206
|
1920 return NGX_ERROR;
|
|
1921 }
|
|
1922
|
58
|
1923 sr = ngx_pcalloc(r->pool, sizeof(ngx_http_request_t));
|
|
1924 if (sr == NULL) {
|
194
|
1925 return NGX_ERROR;
|
58
|
1926 }
|
|
1927
|
|
1928 sr->signature = NGX_HTTP_MODULE;
|
132
|
1929
|
|
1930 c = r->connection;
|
|
1931 sr->connection = c;
|
58
|
1932
|
|
1933 sr->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
|
|
1934 if (sr->ctx == NULL) {
|
194
|
1935 return NGX_ERROR;
|
58
|
1936 }
|
|
1937
|
|
1938 if (ngx_list_init(&sr->headers_out.headers, r->pool, 20,
|
130
|
1939 sizeof(ngx_table_elt_t))
|
|
1940 == NGX_ERROR)
|
58
|
1941 {
|
194
|
1942 return NGX_ERROR;
|
58
|
1943 }
|
|
1944
|
|
1945 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
|
1946 sr->main_conf = cscf->ctx->main_conf;
|
|
1947 sr->srv_conf = cscf->ctx->srv_conf;
|
|
1948 sr->loc_conf = cscf->ctx->loc_conf;
|
|
1949
|
|
1950 sr->pool = r->pool;
|
|
1951
|
|
1952 sr->headers_in = r->headers_in;
|
|
1953
|
126
|
1954 ngx_http_clear_content_length(sr);
|
|
1955 ngx_http_clear_accept_ranges(sr);
|
|
1956 ngx_http_clear_last_modified(sr);
|
58
|
1957
|
|
1958 sr->request_body = r->request_body;
|
|
1959
|
|
1960 sr->method = NGX_HTTP_GET;
|
|
1961 sr->http_version = r->http_version;
|
|
1962
|
|
1963 sr->request_line = r->request_line;
|
|
1964 sr->uri = *uri;
|
122
|
1965
|
58
|
1966 if (args) {
|
|
1967 sr->args = *args;
|
|
1968 }
|
122
|
1969
|
132
|
1970 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
|
1971 "http subrequest \"%V?%V\"", uri, &sr->args);
|
|
1972
|
248
|
1973 sr->zero_in_uri = (flags & NGX_HTTP_ZERO_IN_URI) != 0;
|
|
1974 sr->subrequest_in_memory = (flags & NGX_HTTP_SUBREQUEST_IN_MEMORY) != 0;
|
122
|
1975
|
58
|
1976 sr->unparsed_uri = r->unparsed_uri;
|
364
|
1977 sr->method_name = ngx_http_core_get_method;
|
58
|
1978 sr->http_protocol = r->http_protocol;
|
|
1979
|
|
1980 if (ngx_http_set_exten(sr) != NGX_OK) {
|
194
|
1981 return NGX_ERROR;
|
58
|
1982 }
|
|
1983
|
102
|
1984 sr->main = r->main;
|
58
|
1985 sr->parent = r;
|
248
|
1986 sr->post_subrequest = ps;
|
58
|
1987 sr->read_event_handler = ngx_http_request_empty_handler;
|
|
1988 sr->write_event_handler = ngx_http_request_empty_handler;
|
|
1989
|
132
|
1990 if (c->data == r) {
|
|
1991 c->data = sr;
|
58
|
1992 }
|
|
1993
|
|
1994 sr->in_addr = r->in_addr;
|
|
1995 sr->port = r->port;
|
|
1996 sr->port_text = r->port_text;
|
|
1997
|
|
1998 sr->variables = r->variables;
|
|
1999
|
|
2000 sr->log_handler = r->log_handler;
|
|
2001
|
|
2002 pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t));
|
|
2003 if (pr == NULL) {
|
194
|
2004 return NGX_ERROR;
|
58
|
2005 }
|
|
2006
|
|
2007 pr->request = sr;
|
|
2008 pr->out = NULL;
|
|
2009 pr->next = NULL;
|
|
2010
|
|
2011 if (r->postponed) {
|
|
2012 for (p = r->postponed; p->next; p = p->next) { /* void */ }
|
|
2013 p->next = pr;
|
|
2014
|
|
2015 } else {
|
|
2016 r->postponed = pr;
|
|
2017 }
|
|
2018
|
214
|
2019 ctx = c->log->data;
|
|
2020 ctx->current_request = sr;
|
|
2021
|
58
|
2022 sr->internal = 1;
|
146
|
2023 sr->fast_subrequest = 1;
|
58
|
2024
|
92
|
2025 sr->discard_body = r->discard_body;
|
382
|
2026 sr->expect_tested = 1;
|
62
|
2027 sr->main_filter_need_in_memory = r->main_filter_need_in_memory;
|
|
2028
|
200
|
2029 sr->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1;
|
|
2030
|
58
|
2031 ngx_http_handler(sr);
|
|
2032
|
132
|
2033 if (!c->destroyed) {
|
|
2034 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
|
2035 "http subrequest done \"%V?%V\"", uri, &sr->args);
|
194
|
2036
|
256
|
2037 r->main->subrequests++;
|
|
2038
|
244
|
2039 *psr = sr;
|
|
2040
|
194
|
2041 if (sr->fast_subrequest) {
|
|
2042 sr->fast_subrequest = 0;
|
|
2043
|
|
2044 if (sr->done) {
|
|
2045 return NGX_OK;
|
|
2046 }
|
|
2047 }
|
|
2048
|
|
2049 return NGX_AGAIN;
|
132
|
2050 }
|
58
|
2051
|
248
|
2052 return NGX_DONE;
|
58
|
2053 }
|
|
2054
|
|
2055
|
|
2056 ngx_int_t
|
36
|
2057 ngx_http_internal_redirect(ngx_http_request_t *r,
|
|
2058 ngx_str_t *uri, ngx_str_t *args)
|
0
|
2059 {
|
36
|
2060 ngx_http_core_srv_conf_t *cscf;
|
|
2061
|
226
|
2062 r->uri_changes--;
|
|
2063
|
|
2064 if (r->uri_changes == 0) {
|
|
2065 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
228
|
2066 "rewrite or internal redirection cycle "
|
|
2067 "while internal redirect to \"%V\"", uri);
|
|
2068
|
226
|
2069 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
2070 return NGX_DONE;
|
|
2071 }
|
|
2072
|
10
|
2073 r->uri = *uri;
|
0
|
2074
|
|
2075 if (args) {
|
10
|
2076 r->args = *args;
|
58
|
2077
|
|
2078 } else {
|
|
2079 r->args.len = 0;
|
|
2080 r->args.data = NULL;
|
0
|
2081 }
|
|
2082
|
132
|
2083 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2084 "internal redirect: \"%V?%V\"", uri, &r->args);
|
|
2085
|
0
|
2086 if (ngx_http_set_exten(r) != NGX_OK) {
|
226
|
2087 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
2088 return NGX_DONE;
|
0
|
2089 }
|
|
2090
|
224
|
2091 /* clear the modules contexts */
|
|
2092 ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
|
0
|
2093
|
36
|
2094 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
|
2095 r->loc_conf = cscf->ctx->loc_conf;
|
|
2096
|
84
|
2097 ngx_http_update_location_config(r);
|
|
2098
|
58
|
2099 r->internal = 1;
|
|
2100
|
0
|
2101 ngx_http_handler(r);
|
|
2102
|
|
2103 return NGX_DONE;
|
|
2104 }
|
|
2105
|
|
2106
|
324
|
2107 ngx_int_t
|
|
2108 ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name)
|
|
2109 {
|
|
2110 ngx_uint_t i;
|
|
2111 ngx_http_core_srv_conf_t *cscf;
|
|
2112 ngx_http_core_loc_conf_t **clcfp;
|
|
2113 ngx_http_core_main_conf_t *cmcf;
|
|
2114
|
|
2115 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
|
|
2116
|
|
2117 clcfp = cscf->locations.elts;
|
|
2118
|
|
2119 for (i = cscf->named_start; i < cscf->locations.nelts; i++) {
|
|
2120
|
|
2121 if (name->len != clcfp[i]->name.len
|
|
2122 || ngx_strncmp(name->data, clcfp[i]->name.data, name->len) != 0)
|
|
2123 {
|
|
2124 continue;
|
|
2125 }
|
|
2126
|
|
2127 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2128 "named location: %V \"%V?%V\"", name, &r->uri, &r->args);
|
|
2129
|
|
2130 r->internal = 1;
|
366
|
2131 r->content_handler = NULL;
|
324
|
2132 r->loc_conf = clcfp[i]->loc_conf;
|
|
2133
|
|
2134 ngx_http_update_location_config(r);
|
|
2135
|
|
2136 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
|
|
2137
|
|
2138 r->phase_handler = cmcf->phase_engine.location_rewrite_index;
|
366
|
2139
|
324
|
2140 ngx_http_core_run_phases(r);
|
|
2141
|
|
2142 return NGX_DONE;
|
|
2143 }
|
|
2144
|
|
2145 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
342
|
2146 "could not find named location \"%V\"", name);
|
324
|
2147
|
|
2148 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
2149 return NGX_DONE;
|
|
2150 }
|
|
2151
|
|
2152
|
118
|
2153 ngx_http_cleanup_t *
|
|
2154 ngx_http_cleanup_add(ngx_http_request_t *r, size_t size)
|
0
|
2155 {
|
118
|
2156 ngx_http_cleanup_t *cln;
|
|
2157
|
|
2158 r = r->main;
|
|
2159
|
|
2160 cln = ngx_palloc(r->pool, sizeof(ngx_http_cleanup_t));
|
|
2161 if (cln == NULL) {
|
|
2162 return NULL;
|
0
|
2163 }
|
|
2164
|
118
|
2165 if (size) {
|
|
2166 cln->data = ngx_palloc(r->pool, size);
|
|
2167 if (cln->data == NULL) {
|
|
2168 return NULL;
|
|
2169 }
|
|
2170
|
|
2171 } else {
|
|
2172 cln->data = NULL;
|
|
2173 }
|
|
2174
|
|
2175 cln->handler = NULL;
|
|
2176 cln->next = r->cleanup;
|
|
2177
|
|
2178 r->cleanup = cln;
|
|
2179
|
|
2180 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2181 "http cleanup add: %p", cln);
|
|
2182
|
|
2183 return cln;
|
0
|
2184 }
|
|
2185
|
|
2186
|
36
|
2187 static char *
|
|
2188 ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
0
|
2189 {
|
308
|
2190 char *rv;
|
|
2191 void *mconf;
|
310
|
2192 ngx_uint_t i;
|
308
|
2193 ngx_conf_t pcf;
|
|
2194 ngx_http_module_t *module;
|
|
2195 ngx_http_conf_ctx_t *ctx, *http_ctx;
|
|
2196 ngx_http_core_srv_conf_t *cscf, **cscfp;
|
324
|
2197 ngx_http_core_loc_conf_t **clcfp;
|
310
|
2198 ngx_http_core_main_conf_t *cmcf;
|
36
|
2199
|
50
|
2200 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
|
|
2201 if (ctx == NULL) {
|
36
|
2202 return NGX_CONF_ERROR;
|
|
2203 }
|
0
|
2204
|
|
2205 http_ctx = cf->ctx;
|
|
2206 ctx->main_conf = http_ctx->main_conf;
|
|
2207
|
|
2208 /* the server{}'s srv_conf */
|
|
2209
|
36
|
2210 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
2211 if (ctx->srv_conf == NULL) {
|
|
2212 return NGX_CONF_ERROR;
|
|
2213 }
|
0
|
2214
|
|
2215 /* the server{}'s loc_conf */
|
|
2216
|
36
|
2217 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
2218 if (ctx->loc_conf == NULL) {
|
|
2219 return NGX_CONF_ERROR;
|
|
2220 }
|
0
|
2221
|
310
|
2222 for (i = 0; ngx_modules[i]; i++) {
|
|
2223 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
|
0
|
2224 continue;
|
|
2225 }
|
|
2226
|
310
|
2227 module = ngx_modules[i]->ctx;
|
0
|
2228
|
|
2229 if (module->create_srv_conf) {
|
50
|
2230 mconf = module->create_srv_conf(cf);
|
|
2231 if (mconf == NULL) {
|
36
|
2232 return NGX_CONF_ERROR;
|
|
2233 }
|
|
2234
|
310
|
2235 ctx->srv_conf[ngx_modules[i]->ctx_index] = mconf;
|
0
|
2236 }
|
|
2237
|
|
2238 if (module->create_loc_conf) {
|
50
|
2239 mconf = module->create_loc_conf(cf);
|
|
2240 if (mconf == NULL) {
|
36
|
2241 return NGX_CONF_ERROR;
|
|
2242 }
|
|
2243
|
310
|
2244 ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
|
0
|
2245 }
|
|
2246 }
|
|
2247
|
36
|
2248
|
|
2249 /* the server configuration context */
|
0
|
2250
|
|
2251 cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
|
|
2252 cscf->ctx = ctx;
|
|
2253
|
36
|
2254
|
0
|
2255 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
|
36
|
2256
|
50
|
2257 cscfp = ngx_array_push(&cmcf->servers);
|
|
2258 if (cscfp == NULL) {
|
36
|
2259 return NGX_CONF_ERROR;
|
|
2260 }
|
|
2261
|
0
|
2262 *cscfp = cscf;
|
|
2263
|
36
|
2264
|
0
|
2265 /* parse inside server{} */
|
|
2266
|
70
|
2267 pcf = *cf;
|
0
|
2268 cf->ctx = ctx;
|
|
2269 cf->cmd_type = NGX_HTTP_SRV_CONF;
|
34
|
2270
|
0
|
2271 rv = ngx_conf_parse(cf, NULL);
|
34
|
2272
|
70
|
2273 *cf = pcf;
|
0
|
2274
|
|
2275 if (rv != NGX_CONF_OK) {
|
|
2276 return rv;
|
|
2277 }
|
|
2278
|
302
|
2279 ngx_sort(cscf->locations.elts, (size_t) cscf->locations.nelts,
|
|
2280 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations);
|
0
|
2281
|
324
|
2282 clcfp = cscf->locations.elts;
|
|
2283
|
310
|
2284 #if (NGX_PCRE)
|
|
2285
|
308
|
2286 cscf->regex_start = cscf->locations.nelts;
|
|
2287
|
|
2288 for (i = 0; i < cscf->locations.nelts; i++) {
|
|
2289 if (clcfp[i]->regex) {
|
|
2290 cscf->regex_start = i;
|
|
2291 break;
|
|
2292 }
|
|
2293 }
|
|
2294
|
310
|
2295 #endif
|
|
2296
|
324
|
2297 cscf->named_start = cscf->locations.nelts;
|
|
2298
|
|
2299 for (i = 0; i < cscf->locations.nelts; i++) {
|
|
2300 if (clcfp[i]->named) {
|
|
2301 cscf->named_start = i;
|
|
2302 break;
|
|
2303 }
|
|
2304 }
|
|
2305
|
0
|
2306 return rv;
|
|
2307 }
|
|
2308
|
|
2309
|
36
|
2310 static char *
|
|
2311 ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
0
|
2312 {
|
|
2313 char *rv;
|
310
|
2314 ngx_uint_t i;
|
0
|
2315 ngx_str_t *value;
|
34
|
2316 ngx_conf_t save;
|
0
|
2317 ngx_http_module_t *module;
|
|
2318 ngx_http_conf_ctx_t *ctx, *pctx;
|
|
2319 ngx_http_core_srv_conf_t *cscf;
|
|
2320 ngx_http_core_loc_conf_t *clcf, *pclcf, **clcfp;
|
|
2321
|
50
|
2322 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
|
|
2323 if (ctx == NULL) {
|
0
|
2324 return NGX_CONF_ERROR;
|
|
2325 }
|
|
2326
|
|
2327 pctx = cf->ctx;
|
|
2328 ctx->main_conf = pctx->main_conf;
|
|
2329 ctx->srv_conf = pctx->srv_conf;
|
|
2330
|
|
2331 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
2332 if (ctx->loc_conf == NULL) {
|
|
2333 return NGX_CONF_ERROR;
|
|
2334 }
|
|
2335
|
310
|
2336 for (i = 0; ngx_modules[i]; i++) {
|
|
2337 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
|
0
|
2338 continue;
|
|
2339 }
|
|
2340
|
310
|
2341 module = ngx_modules[i]->ctx;
|
0
|
2342
|
|
2343 if (module->create_loc_conf) {
|
310
|
2344 ctx->loc_conf[ngx_modules[i]->ctx_index] =
|
0
|
2345 module->create_loc_conf(cf);
|
310
|
2346 if (ctx->loc_conf[ngx_modules[i]->ctx_index] == NULL) {
|
0
|
2347 return NGX_CONF_ERROR;
|
|
2348 }
|
|
2349 }
|
|
2350 }
|
|
2351
|
|
2352 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
|
|
2353 clcf->loc_conf = ctx->loc_conf;
|
|
2354
|
|
2355 value = cf->args->elts;
|
|
2356
|
|
2357 if (cf->args->nelts == 3) {
|
|
2358 if (value[1].len == 1 && value[1].data[0] == '=') {
|
12
|
2359 clcf->name = value[2];
|
0
|
2360 clcf->exact_match = 1;
|
|
2361
|
16
|
2362 } else if (value[1].len == 2
|
|
2363 && value[1].data[0] == '^'
|
|
2364 && value[1].data[1] == '~')
|
|
2365 {
|
|
2366 clcf->name = value[2];
|
|
2367 clcf->noregex = 1;
|
|
2368
|
0
|
2369 } else if ((value[1].len == 1 && value[1].data[0] == '~')
|
|
2370 || (value[1].len == 2
|
|
2371 && value[1].data[0] == '~'
|
|
2372 && value[1].data[1] == '*'))
|
|
2373 {
|
4
|
2374 #if (NGX_PCRE)
|
356
|
2375 ngx_str_t err;
|
|
2376 u_char errstr[NGX_MAX_CONF_ERRSTR];
|
|
2377
|
0
|
2378 err.len = NGX_MAX_CONF_ERRSTR;
|
|
2379 err.data = errstr;
|
|
2380
|
|
2381 clcf->regex = ngx_regex_compile(&value[2],
|
|
2382 value[1].len == 2 ? NGX_REGEX_CASELESS: 0,
|
|
2383 cf->pool, &err);
|
|
2384
|
|
2385 if (clcf->regex == NULL) {
|
|
2386 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
|
|
2387 return NGX_CONF_ERROR;
|
|
2388 }
|
|
2389
|
|
2390 clcf->name = value[2];
|
|
2391 #else
|
|
2392 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
2393 "the using of the regex \"%V\" "
|
|
2394 "requires PCRE library", &value[2]);
|
0
|
2395 return NGX_CONF_ERROR;
|
|
2396 #endif
|
|
2397
|
|
2398 } else {
|
|
2399 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
2400 "invalid location modifier \"%V\"", &value[1]);
|
0
|
2401 return NGX_CONF_ERROR;
|
|
2402 }
|
|
2403
|
|
2404 } else {
|
324
|
2405
|
12
|
2406 clcf->name = value[1];
|
324
|
2407
|
|
2408 if (value[1].data[0] == '@') {
|
|
2409 clcf->named = 1;
|
|
2410 }
|
0
|
2411 }
|
|
2412
|
|
2413 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
|
|
2414
|
|
2415 if (pclcf->name.len == 0) {
|
|
2416 cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
|
50
|
2417
|
|
2418 clcfp = ngx_array_push(&cscf->locations);
|
|
2419 if (clcfp == NULL) {
|
0
|
2420 return NGX_CONF_ERROR;
|
|
2421 }
|
|
2422
|
|
2423 } else {
|
34
|
2424 #if 0
|
0
|
2425 clcf->prev_location = pclcf;
|
34
|
2426 #endif
|
0
|
2427
|
|
2428 if (pclcf->exact_match) {
|
|
2429 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
2430 "location \"%V\" could not be inside "
|
|
2431 "the exact location \"%V\"",
|
|
2432 &clcf->name, &pclcf->name);
|
0
|
2433 return NGX_CONF_ERROR;
|
|
2434 }
|
|
2435
|
324
|
2436 if (pclcf->named) {
|
|
2437 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2438 "location \"%V\" could not be inside "
|
|
2439 "the named location \"%V\"",
|
|
2440 &clcf->name, &pclcf->name);
|
|
2441 return NGX_CONF_ERROR;
|
|
2442 }
|
|
2443
|
4
|
2444 #if (NGX_PCRE)
|
0
|
2445 if (clcf->regex == NULL
|
|
2446 && ngx_strncmp(clcf->name.data, pclcf->name.data, pclcf->name.len)
|
302
|
2447 != 0)
|
0
|
2448 #else
|
|
2449 if (ngx_strncmp(clcf->name.data, pclcf->name.data, pclcf->name.len)
|
302
|
2450 != 0)
|
0
|
2451 #endif
|
|
2452 {
|
|
2453 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
2454 "location \"%V\" is outside location \"%V\"",
|
|
2455 &clcf->name, &pclcf->name);
|
0
|
2456 return NGX_CONF_ERROR;
|
|
2457 }
|
|
2458
|
308
|
2459 if (pclcf->locations == NULL) {
|
|
2460 pclcf->locations = ngx_array_create(cf->pool, 2, sizeof(void *));
|
|
2461
|
|
2462 if (pclcf->locations == NULL) {
|
50
|
2463 return NGX_CONF_ERROR;
|
|
2464 }
|
0
|
2465 }
|
|
2466
|
308
|
2467 clcfp = ngx_array_push(pclcf->locations);
|
50
|
2468 if (clcfp == NULL) {
|
0
|
2469 return NGX_CONF_ERROR;
|
|
2470 }
|
|
2471 }
|
|
2472
|
|
2473 *clcfp = clcf;
|
|
2474
|
34
|
2475 save = *cf;
|
0
|
2476 cf->ctx = ctx;
|
|
2477 cf->cmd_type = NGX_HTTP_LOC_CONF;
|
34
|
2478
|
0
|
2479 rv = ngx_conf_parse(cf, NULL);
|
34
|
2480
|
|
2481 *cf = save;
|
|
2482
|
|
2483 if (rv != NGX_CONF_OK) {
|
|
2484 return rv;
|
|
2485 }
|
|
2486
|
308
|
2487 if (clcf->locations == NULL) {
|
|
2488 return rv;
|
|
2489 }
|
|
2490
|
|
2491 ngx_sort(clcf->locations->elts, (size_t) clcf->locations->nelts,
|
302
|
2492 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations);
|
0
|
2493
|
310
|
2494 #if (NGX_PCRE)
|
|
2495
|
308
|
2496 clcf->regex_start = clcf->locations->nelts;
|
|
2497 clcfp = clcf->locations->elts;
|
|
2498
|
|
2499 for (i = 0; i < clcf->locations->nelts; i++) {
|
|
2500 if (clcfp[i]->regex) {
|
|
2501 clcf->regex_start = i;
|
|
2502 break;
|
|
2503 }
|
|
2504 }
|
|
2505
|
310
|
2506 #endif
|
|
2507
|
0
|
2508 return rv;
|
|
2509 }
|
|
2510
|
|
2511
|
372
|
2512 static ngx_int_t
|
36
|
2513 ngx_http_core_cmp_locations(const void *one, const void *two)
|
34
|
2514 {
|
|
2515 ngx_int_t rc;
|
|
2516 ngx_http_core_loc_conf_t *first, *second;
|
|
2517
|
|
2518 first = *(ngx_http_core_loc_conf_t **) one;
|
|
2519 second = *(ngx_http_core_loc_conf_t **) two;
|
|
2520
|
324
|
2521 if (first->named && !second->named) {
|
|
2522 /* shift named locations to the end */
|
|
2523 return 1;
|
|
2524 }
|
|
2525
|
|
2526 if (!first->named && second->named) {
|
|
2527 /* shift named locations to the end */
|
|
2528 return -1;
|
|
2529 }
|
|
2530
|
|
2531 if (first->named && second->named) {
|
|
2532 return ngx_strcmp(first->name.data, second->name.data);
|
|
2533 }
|
|
2534
|
34
|
2535 if (first->noname && !second->noname) {
|
|
2536 /* shift no named locations to the end */
|
|
2537 return 1;
|
|
2538 }
|
|
2539
|
|
2540 if (!first->noname && second->noname) {
|
|
2541 /* shift no named locations to the end */
|
|
2542 return -1;
|
|
2543 }
|
|
2544
|
|
2545 if (first->noname || second->noname) {
|
|
2546 /* do not sort no named locations */
|
|
2547 return 0;
|
|
2548 }
|
|
2549
|
|
2550 #if (NGX_PCRE)
|
|
2551
|
|
2552 if (first->regex && !second->regex) {
|
|
2553 /* shift the regex matches to the end */
|
|
2554 return 1;
|
|
2555 }
|
|
2556
|
|
2557 if (!first->regex && second->regex) {
|
|
2558 /* shift the regex matches to the end */
|
|
2559 return -1;
|
|
2560 }
|
|
2561
|
|
2562 if (first->regex || second->regex) {
|
|
2563 /* do not sort the regex matches */
|
|
2564 return 0;
|
|
2565 }
|
|
2566
|
|
2567 #endif
|
|
2568
|
|
2569 rc = ngx_strcmp(first->name.data, second->name.data);
|
|
2570
|
|
2571 if (rc == 0 && second->exact_match) {
|
|
2572 /* an exact match must be before the same inclusive one */
|
|
2573 return 1;
|
|
2574 }
|
|
2575
|
372
|
2576 return rc;
|
34
|
2577 }
|
|
2578
|
|
2579
|
36
|
2580 static char *
|
|
2581 ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
2582 {
|
186
|
2583 ngx_http_core_loc_conf_t *lcf = conf;
|
|
2584
|
0
|
2585 char *rv;
|
34
|
2586 ngx_conf_t save;
|
0
|
2587
|
186
|
2588 if (lcf->types == NULL) {
|
|
2589 lcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t));
|
|
2590 if (lcf->types == NULL) {
|
|
2591 return NGX_CONF_ERROR;
|
|
2592 }
|
|
2593 }
|
|
2594
|
34
|
2595 save = *cf;
|
|
2596 cf->handler = ngx_http_core_type;
|
0
|
2597 cf->handler_conf = conf;
|
34
|
2598
|
0
|
2599 rv = ngx_conf_parse(cf, NULL);
|
34
|
2600
|
|
2601 *cf = save;
|
0
|
2602
|
|
2603 return rv;
|
|
2604 }
|
|
2605
|
|
2606
|
36
|
2607 static char *
|
|
2608 ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
|
0
|
2609 {
|
|
2610 ngx_http_core_loc_conf_t *lcf = conf;
|
|
2611
|
294
|
2612 ngx_str_t *value, *content_type, *old, file;
|
138
|
2613 ngx_uint_t i, n;
|
|
2614 ngx_hash_key_t *type;
|
0
|
2615
|
294
|
2616 value = cf->args->elts;
|
|
2617
|
|
2618 if (ngx_strcmp(value[0].data, "include") == 0) {
|
|
2619 file = value[1];
|
|
2620
|
324
|
2621 if (ngx_conf_full_name(cf->cycle, &file, 1) == NGX_ERROR){
|
294
|
2622 return NGX_CONF_ERROR;
|
|
2623 }
|
|
2624
|
|
2625 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
|
|
2626
|
|
2627 return ngx_conf_parse(cf, &file);
|
|
2628 }
|
|
2629
|
138
|
2630 content_type = ngx_palloc(cf->pool, sizeof(ngx_str_t));
|
|
2631 if (content_type == NULL) {
|
|
2632 return NGX_CONF_ERROR;
|
0
|
2633 }
|
|
2634
|
138
|
2635 *content_type = value[0];
|
0
|
2636
|
|
2637 for (i = 1; i < cf->args->nelts; i++) {
|
138
|
2638
|
|
2639 for (n = 0; n < value[i].len; n++) {
|
|
2640 value[i].data[n] = ngx_tolower(value[i].data[n]);
|
|
2641 }
|
|
2642
|
|
2643 type = lcf->types->elts;
|
|
2644 for (n = 0; n < lcf->types->nelts; n++) {
|
|
2645 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) {
|
|
2646 old = type[n].value;
|
|
2647 type[n].value = content_type;
|
|
2648
|
|
2649 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
2650 "duplicate extention \"%V\", "
|
|
2651 "content type: \"%V\", "
|
|
2652 "old content type: \"%V\"",
|
|
2653 &value[i], content_type, old);
|
|
2654 continue;
|
|
2655 }
|
|
2656 }
|
|
2657
|
|
2658
|
|
2659 type = ngx_array_push(lcf->types);
|
50
|
2660 if (type == NULL) {
|
0
|
2661 return NGX_CONF_ERROR;
|
|
2662 }
|
|
2663
|
138
|
2664 type->key = value[i];
|
|
2665 type->key_hash = ngx_hash_key(value[i].data, value[i].len);
|
|
2666 type->value = content_type;
|
0
|
2667 }
|
|
2668
|
|
2669 return NGX_CONF_OK;
|
|
2670 }
|
|
2671
|
|
2672
|
58
|
2673 static ngx_int_t
|
|
2674 ngx_http_core_preconfiguration(ngx_conf_t *cf)
|
|
2675 {
|
|
2676 return ngx_http_variables_add_core_vars(cf);
|
|
2677 }
|
|
2678
|
|
2679
|
36
|
2680 static void *
|
|
2681 ngx_http_core_create_main_conf(ngx_conf_t *cf)
|
0
|
2682 {
|
34
|
2683 ngx_http_core_main_conf_t *cmcf;
|
|
2684
|
50
|
2685 cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t));
|
|
2686 if (cmcf == NULL) {
|
34
|
2687 return NGX_CONF_ERROR;
|
|
2688 }
|
0
|
2689
|
48
|
2690 if (ngx_array_init(&cmcf->servers, cf->pool, 4,
|
118
|
2691 sizeof(ngx_http_core_srv_conf_t *))
|
200
|
2692 != NGX_OK)
|
34
|
2693 {
|
|
2694 return NGX_CONF_ERROR;
|
|
2695 }
|
0
|
2696
|
142
|
2697 cmcf->server_names_hash_max_size = NGX_CONF_UNSET_UINT;
|
|
2698 cmcf->server_names_hash_bucket_size = NGX_CONF_UNSET_UINT;
|
26
|
2699
|
160
|
2700 cmcf->variables_hash_max_size = NGX_CONF_UNSET_UINT;
|
|
2701 cmcf->variables_hash_bucket_size = NGX_CONF_UNSET_UINT;
|
|
2702
|
0
|
2703 return cmcf;
|
|
2704 }
|
|
2705
|
|
2706
|
36
|
2707 static char *
|
|
2708 ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf)
|
0
|
2709 {
|
|
2710 ngx_http_core_main_conf_t *cmcf = conf;
|
|
2711
|
142
|
2712 if (cmcf->server_names_hash_max_size == NGX_CONF_UNSET_UINT) {
|
|
2713 cmcf->server_names_hash_max_size = 512;
|
26
|
2714 }
|
|
2715
|
142
|
2716 if (cmcf->server_names_hash_bucket_size == NGX_CONF_UNSET_UINT) {
|
|
2717 cmcf->server_names_hash_bucket_size = ngx_cacheline_size;
|
26
|
2718 }
|
0
|
2719
|
142
|
2720 cmcf->server_names_hash_bucket_size =
|
|
2721 ngx_align(cmcf->server_names_hash_bucket_size, ngx_cacheline_size);
|
|
2722
|
160
|
2723
|
|
2724 if (cmcf->variables_hash_max_size == NGX_CONF_UNSET_UINT) {
|
|
2725 cmcf->variables_hash_max_size = 512;
|
|
2726 }
|
|
2727
|
|
2728 if (cmcf->variables_hash_bucket_size == NGX_CONF_UNSET_UINT) {
|
|
2729 cmcf->variables_hash_bucket_size = 64;
|
|
2730 }
|
|
2731
|
|
2732 cmcf->variables_hash_bucket_size =
|
|
2733 ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size);
|
|
2734
|
0
|
2735 return NGX_CONF_OK;
|
|
2736 }
|
|
2737
|
|
2738
|
36
|
2739 static void *
|
|
2740 ngx_http_core_create_srv_conf(ngx_conf_t *cf)
|
0
|
2741 {
|
|
2742 ngx_http_core_srv_conf_t *cscf;
|
|
2743
|
50
|
2744 cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t));
|
|
2745 if (cscf == NULL) {
|
36
|
2746 return NGX_CONF_ERROR;
|
|
2747 }
|
|
2748
|
0
|
2749 /*
|
36
|
2750 * set by ngx_pcalloc():
|
28
|
2751 *
|
|
2752 * conf->client_large_buffers.num = 0;
|
|
2753 */
|
0
|
2754
|
48
|
2755 if (ngx_array_init(&cscf->locations, cf->pool, 4, sizeof(void *))
|
142
|
2756 == NGX_ERROR)
|
36
|
2757 {
|
|
2758 return NGX_CONF_ERROR;
|
|
2759 }
|
|
2760
|
48
|
2761 if (ngx_array_init(&cscf->listen, cf->pool, 4, sizeof(ngx_http_listen_t))
|
142
|
2762 == NGX_ERROR)
|
36
|
2763 {
|
|
2764 return NGX_CONF_ERROR;
|
|
2765 }
|
|
2766
|
230
|
2767 if (ngx_array_init(&cscf->server_names, cf->temp_pool, 4,
|
142
|
2768 sizeof(ngx_http_server_name_t))
|
|
2769 == NGX_ERROR)
|
36
|
2770 {
|
|
2771 return NGX_CONF_ERROR;
|
|
2772 }
|
0
|
2773
|
|
2774 cscf->connection_pool_size = NGX_CONF_UNSET_SIZE;
|
|
2775 cscf->request_pool_size = NGX_CONF_UNSET_SIZE;
|
|
2776 cscf->client_header_timeout = NGX_CONF_UNSET_MSEC;
|
|
2777 cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE;
|
158
|
2778 cscf->optimize_server_names = NGX_CONF_UNSET;
|
60
|
2779 cscf->ignore_invalid_headers = NGX_CONF_UNSET;
|
342
|
2780 cscf->merge_slashes = NGX_CONF_UNSET;
|
0
|
2781
|
|
2782 return cscf;
|
|
2783 }
|
|
2784
|
|
2785
|
36
|
2786 static char *
|
|
2787 ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
0
|
2788 {
|
|
2789 ngx_http_core_srv_conf_t *prev = parent;
|
|
2790 ngx_http_core_srv_conf_t *conf = child;
|
|
2791
|
142
|
2792 ngx_http_listen_t *ls;
|
|
2793 ngx_http_server_name_t *sn;
|
0
|
2794
|
|
2795 /* TODO: it does not merge, it inits only */
|
|
2796
|
|
2797 if (conf->listen.nelts == 0) {
|
50
|
2798 ls = ngx_array_push(&conf->listen);
|
|
2799 if (ls == NULL) {
|
36
|
2800 return NGX_CONF_ERROR;
|
|
2801 }
|
|
2802
|
72
|
2803 ngx_memzero(ls, sizeof(ngx_http_listen_t));
|
|
2804
|
36
|
2805 ls->addr = INADDR_ANY;
|
10
|
2806 #if (NGX_WIN32)
|
36
|
2807 ls->port = 80;
|
0
|
2808 #else
|
|
2809 /* STUB: getuid() should be cached */
|
36
|
2810 ls->port = (getuid() == 0) ? 80 : 8000;
|
0
|
2811 #endif
|
36
|
2812 ls->family = AF_INET;
|
118
|
2813
|
326
|
2814 ls->conf.backlog = NGX_LISTEN_BACKLOG;
|
118
|
2815 ls->conf.rcvbuf = -1;
|
|
2816 ls->conf.sndbuf = -1;
|
0
|
2817 }
|
|
2818
|
154
|
2819 if (conf->server_name.data == NULL) {
|
376
|
2820 conf->server_name = cf->cycle->hostname;
|
154
|
2821
|
50
|
2822 sn = ngx_array_push(&conf->server_names);
|
|
2823 if (sn == NULL) {
|
36
|
2824 return NGX_CONF_ERROR;
|
|
2825 }
|
|
2826
|
342
|
2827 #if (NGX_PCRE)
|
|
2828 sn->regex = NULL;
|
|
2829 #endif
|
|
2830 sn->core_srv_conf = conf;
|
154
|
2831 sn->name.len = conf->server_name.len;
|
|
2832 sn->name.data = conf->server_name.data;
|
0
|
2833 }
|
|
2834
|
|
2835 ngx_conf_merge_size_value(conf->connection_pool_size,
|
|
2836 prev->connection_pool_size, 256);
|
|
2837 ngx_conf_merge_size_value(conf->request_pool_size,
|
|
2838 prev->request_pool_size, 4096);
|
|
2839 ngx_conf_merge_msec_value(conf->client_header_timeout,
|
|
2840 prev->client_header_timeout, 60000);
|
|
2841 ngx_conf_merge_size_value(conf->client_header_buffer_size,
|
|
2842 prev->client_header_buffer_size, 1024);
|
|
2843 ngx_conf_merge_bufs_value(conf->large_client_header_buffers,
|
|
2844 prev->large_client_header_buffers,
|
|
2845 4, ngx_pagesize);
|
|
2846
|
|
2847 if (conf->large_client_header_buffers.size < conf->connection_pool_size) {
|
|
2848 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2849 "the \"large_client_header_buffers\" size must be "
|
|
2850 "equal to or bigger than \"connection_pool_size\"");
|
|
2851 return NGX_CONF_ERROR;
|
|
2852 }
|
|
2853
|
158
|
2854 ngx_conf_merge_value(conf->optimize_server_names,
|
|
2855 prev->optimize_server_names, 1);
|
152
|
2856
|
60
|
2857 ngx_conf_merge_value(conf->ignore_invalid_headers,
|
|
2858 prev->ignore_invalid_headers, 1);
|
|
2859
|
342
|
2860 ngx_conf_merge_value(conf->merge_slashes, prev->merge_slashes, 1);
|
|
2861
|
0
|
2862 return NGX_CONF_OK;
|
|
2863 }
|
|
2864
|
|
2865
|
36
|
2866 static void *
|
|
2867 ngx_http_core_create_loc_conf(ngx_conf_t *cf)
|
0
|
2868 {
|
34
|
2869 ngx_http_core_loc_conf_t *lcf;
|
0
|
2870
|
50
|
2871 lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t));
|
|
2872 if (lcf == NULL) {
|
36
|
2873 return NGX_CONF_ERROR;
|
|
2874 }
|
0
|
2875
|
28
|
2876 /*
|
|
2877 * set by ngx_pcalloc():
|
|
2878 *
|
126
|
2879 * lcf->root = { 0, NULL };
|
180
|
2880 * lcf->limit_except = 0;
|
126
|
2881 * lcf->post_action = { 0, NULL };
|
28
|
2882 * lcf->types = NULL;
|
126
|
2883 * lcf->default_type = { 0, NULL };
|
28
|
2884 * lcf->err_log = NULL;
|
|
2885 * lcf->error_pages = NULL;
|
384
|
2886 * lcf->try_files = NULL;
|
28
|
2887 * lcf->client_body_path = NULL;
|
|
2888 * lcf->regex = NULL;
|
|
2889 * lcf->exact_match = 0;
|
|
2890 * lcf->auto_redirect = 0;
|
|
2891 * lcf->alias = 0;
|
358
|
2892 * lcf->gzip_proxied = 0;
|
28
|
2893 */
|
0
|
2894
|
212
|
2895 lcf->client_max_body_size = NGX_CONF_UNSET;
|
0
|
2896 lcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE;
|
|
2897 lcf->client_body_timeout = NGX_CONF_UNSET_MSEC;
|
362
|
2898 lcf->satisfy = NGX_CONF_UNSET_UINT;
|
384
|
2899 lcf->if_modified_since = NGX_CONF_UNSET_UINT;
|
58
|
2900 lcf->internal = NGX_CONF_UNSET;
|
182
|
2901 lcf->client_body_in_file_only = NGX_CONF_UNSET;
|
0
|
2902 lcf->sendfile = NGX_CONF_UNSET;
|
300
|
2903 lcf->sendfile_max_chunk = NGX_CONF_UNSET_SIZE;
|
0
|
2904 lcf->tcp_nopush = NGX_CONF_UNSET;
|
2
|
2905 lcf->tcp_nodelay = NGX_CONF_UNSET;
|
0
|
2906 lcf->send_timeout = NGX_CONF_UNSET_MSEC;
|
|
2907 lcf->send_lowat = NGX_CONF_UNSET_SIZE;
|
|
2908 lcf->postpone_output = NGX_CONF_UNSET_SIZE;
|
|
2909 lcf->limit_rate = NGX_CONF_UNSET_SIZE;
|
|
2910 lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
|
|
2911 lcf->keepalive_header = NGX_CONF_UNSET;
|
|
2912 lcf->lingering_time = NGX_CONF_UNSET_MSEC;
|
|
2913 lcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
|
348
|
2914 lcf->resolver_timeout = NGX_CONF_UNSET_MSEC;
|
0
|
2915 lcf->reset_timedout_connection = NGX_CONF_UNSET;
|
362
|
2916 lcf->server_name_in_redirect = NGX_CONF_UNSET;
|
70
|
2917 lcf->port_in_redirect = NGX_CONF_UNSET;
|
0
|
2918 lcf->msie_padding = NGX_CONF_UNSET;
|
228
|
2919 lcf->msie_refresh = NGX_CONF_UNSET;
|
76
|
2920 lcf->log_not_found = NGX_CONF_UNSET;
|
228
|
2921 lcf->recursive_error_pages = NGX_CONF_UNSET;
|
342
|
2922 lcf->server_tokens = NGX_CONF_UNSET;
|
138
|
2923 lcf->types_hash_max_size = NGX_CONF_UNSET_UINT;
|
|
2924 lcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT;
|
358
|
2925
|
332
|
2926 lcf->open_file_cache = NGX_CONF_UNSET_PTR;
|
358
|
2927 lcf->open_file_cache_valid = NGX_CONF_UNSET;
|
|
2928 lcf->open_file_cache_min_uses = NGX_CONF_UNSET_UINT;
|
332
|
2929 lcf->open_file_cache_errors = NGX_CONF_UNSET;
|
|
2930 lcf->open_file_cache_events = NGX_CONF_UNSET;
|
0
|
2931
|
358
|
2932 #if (NGX_HTTP_GZIP)
|
|
2933 lcf->gzip_vary = NGX_CONF_UNSET;
|
|
2934 lcf->gzip_http_version = NGX_CONF_UNSET_UINT;
|
362
|
2935 #if (NGX_PCRE)
|
358
|
2936 lcf->gzip_disable = NGX_CONF_UNSET_PTR;
|
|
2937 #endif
|
362
|
2938 #endif
|
358
|
2939
|
0
|
2940 return lcf;
|
|
2941 }
|
|
2942
|
|
2943
|
138
|
2944 static ngx_str_t ngx_http_core_text_html_type = ngx_string("text/html");
|
|
2945 static ngx_str_t ngx_http_core_image_gif_type = ngx_string("image/gif");
|
|
2946 static ngx_str_t ngx_http_core_image_jpeg_type = ngx_string("image/jpeg");
|
|
2947
|
|
2948 static ngx_hash_key_t ngx_http_core_default_types[] = {
|
|
2949 { ngx_string("html"), 0, &ngx_http_core_text_html_type },
|
|
2950 { ngx_string("gif"), 0, &ngx_http_core_image_gif_type },
|
|
2951 { ngx_string("jpg"), 0, &ngx_http_core_image_jpeg_type },
|
|
2952 { ngx_null_string, 0, NULL }
|
0
|
2953 };
|
|
2954
|
|
2955
|
36
|
2956 static char *
|
138
|
2957 ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
0
|
2958 {
|
|
2959 ngx_http_core_loc_conf_t *prev = parent;
|
|
2960 ngx_http_core_loc_conf_t *conf = child;
|
|
2961
|
36
|
2962 ngx_uint_t i;
|
138
|
2963 ngx_hash_key_t *type;
|
|
2964 ngx_hash_init_t types_hash;
|
0
|
2965
|
152
|
2966 if (conf->root.data == NULL) {
|
|
2967
|
174
|
2968 conf->alias = prev->alias;
|
152
|
2969 conf->root = prev->root;
|
|
2970 conf->root_lengths = prev->root_lengths;
|
|
2971 conf->root_values = prev->root_values;
|
|
2972
|
|
2973 if (prev->root.data == NULL) {
|
|
2974 conf->root.len = sizeof("html") - 1;
|
|
2975 conf->root.data = (u_char *) "html";
|
|
2976
|
324
|
2977 if (ngx_conf_full_name(cf->cycle, &conf->root, 0) == NGX_ERROR) {
|
152
|
2978 return NGX_CONF_ERROR;
|
|
2979 }
|
|
2980 }
|
0
|
2981 }
|
|
2982
|
126
|
2983 if (conf->post_action.data == NULL) {
|
|
2984 conf->post_action = prev->post_action;
|
|
2985 }
|
|
2986
|
212
|
2987 ngx_conf_merge_uint_value(conf->types_hash_max_size,
|
|
2988 prev->types_hash_max_size, 1024);
|
|
2989
|
|
2990 ngx_conf_merge_uint_value(conf->types_hash_bucket_size,
|
|
2991 prev->types_hash_bucket_size,
|
|
2992 ngx_cacheline_size);
|
138
|
2993
|
|
2994 conf->types_hash_bucket_size = ngx_align(conf->types_hash_bucket_size,
|
|
2995 ngx_cacheline_size);
|
|
2996
|
|
2997 /*
|
|
2998 * the special handling the "types" directive in the "http" section
|
|
2999 * to inherit the http's conf->types_hash to all servers
|
|
3000 */
|
|
3001
|
|
3002 if (prev->types && prev->types_hash.buckets == NULL) {
|
|
3003
|
|
3004 types_hash.hash = &prev->types_hash;
|
|
3005 types_hash.key = ngx_hash_key_lc;
|
|
3006 types_hash.max_size = conf->types_hash_max_size;
|
|
3007 types_hash.bucket_size = conf->types_hash_bucket_size;
|
144
|
3008 types_hash.name = "types_hash";
|
138
|
3009 types_hash.pool = cf->pool;
|
|
3010 types_hash.temp_pool = NULL;
|
|
3011
|
|
3012 if (ngx_hash_init(&types_hash, prev->types->elts, prev->types->nelts)
|
|
3013 != NGX_OK)
|
|
3014 {
|
|
3015 return NGX_CONF_ERROR;
|
|
3016 }
|
|
3017 }
|
|
3018
|
0
|
3019 if (conf->types == NULL) {
|
138
|
3020 conf->types = prev->types;
|
|
3021 conf->types_hash = prev->types_hash;
|
|
3022 }
|
|
3023
|
|
3024 if (conf->types == NULL) {
|
|
3025 conf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_hash_key_t));
|
|
3026 if (conf->types == NULL) {
|
|
3027 return NGX_CONF_ERROR;
|
|
3028 }
|
|
3029
|
|
3030 for (i = 0; ngx_http_core_default_types[i].key.len; i++) {
|
|
3031 type = ngx_array_push(conf->types);
|
|
3032 if (type == NULL) {
|
36
|
3033 return NGX_CONF_ERROR;
|
|
3034 }
|
0
|
3035
|
138
|
3036 type->key = ngx_http_core_default_types[i].key;
|
|
3037 type->key_hash =
|
|
3038 ngx_hash_key_lc(ngx_http_core_default_types[i].key.data,
|
|
3039 ngx_http_core_default_types[i].key.len);
|
|
3040 type->value = ngx_http_core_default_types[i].value;
|
|
3041 }
|
|
3042 }
|
|
3043
|
|
3044 if (conf->types_hash.buckets == NULL) {
|
|
3045
|
|
3046 types_hash.hash = &conf->types_hash;
|
|
3047 types_hash.key = ngx_hash_key_lc;
|
|
3048 types_hash.max_size = conf->types_hash_max_size;
|
|
3049 types_hash.bucket_size = conf->types_hash_bucket_size;
|
144
|
3050 types_hash.name = "mime_types_hash";
|
138
|
3051 types_hash.pool = cf->pool;
|
|
3052 types_hash.temp_pool = NULL;
|
|
3053
|
|
3054 if (ngx_hash_init(&types_hash, conf->types->elts, conf->types->nelts)
|
|
3055 != NGX_OK)
|
|
3056 {
|
|
3057 return NGX_CONF_ERROR;
|
0
|
3058 }
|
|
3059 }
|
|
3060
|
|
3061 if (conf->err_log == NULL) {
|
|
3062 if (prev->err_log) {
|
|
3063 conf->err_log = prev->err_log;
|
|
3064 } else {
|
|
3065 conf->err_log = cf->cycle->new_log;
|
|
3066 }
|
|
3067 }
|
|
3068
|
|
3069 if (conf->error_pages == NULL && prev->error_pages) {
|
|
3070 conf->error_pages = prev->error_pages;
|
|
3071 }
|
|
3072
|
|
3073 ngx_conf_merge_str_value(conf->default_type,
|
36
|
3074 prev->default_type, "text/plain");
|
0
|
3075
|
212
|
3076 ngx_conf_merge_off_value(conf->client_max_body_size,
|
0
|
3077 prev->client_max_body_size, 1 * 1024 * 1024);
|
|
3078 ngx_conf_merge_size_value(conf->client_body_buffer_size,
|
|
3079 prev->client_body_buffer_size,
|
|
3080 (size_t) 2 * ngx_pagesize);
|
|
3081 ngx_conf_merge_msec_value(conf->client_body_timeout,
|
|
3082 prev->client_body_timeout, 60000);
|
58
|
3083
|
362
|
3084 ngx_conf_merge_uint_value(conf->satisfy, prev->satisfy,
|
|
3085 NGX_HTTP_SATISFY_ALL);
|
384
|
3086 ngx_conf_merge_uint_value(conf->if_modified_since, prev->if_modified_since,
|
|
3087 NGX_HTTP_IMS_EXACT);
|
58
|
3088 ngx_conf_merge_value(conf->internal, prev->internal, 0);
|
182
|
3089 ngx_conf_merge_value(conf->client_body_in_file_only,
|
|
3090 prev->client_body_in_file_only, 0);
|
0
|
3091 ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
|
300
|
3092 ngx_conf_merge_size_value(conf->sendfile_max_chunk,
|
|
3093 prev->sendfile_max_chunk, 0);
|
0
|
3094 ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0);
|
228
|
3095 ngx_conf_merge_value(conf->tcp_nodelay, prev->tcp_nodelay, 1);
|
58
|
3096
|
0
|
3097 ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000);
|
|
3098 ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0);
|
|
3099 ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output,
|
|
3100 1460);
|
|
3101 ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0);
|
|
3102 ngx_conf_merge_msec_value(conf->keepalive_timeout,
|
|
3103 prev->keepalive_timeout, 75000);
|
|
3104 ngx_conf_merge_sec_value(conf->keepalive_header,
|
|
3105 prev->keepalive_header, 0);
|
|
3106 ngx_conf_merge_msec_value(conf->lingering_time,
|
|
3107 prev->lingering_time, 30000);
|
|
3108 ngx_conf_merge_msec_value(conf->lingering_timeout,
|
|
3109 prev->lingering_timeout, 5000);
|
348
|
3110 ngx_conf_merge_msec_value(conf->resolver_timeout,
|
|
3111 prev->resolver_timeout, 30000);
|
|
3112
|
|
3113 if (conf->resolver == NULL) {
|
366
|
3114
|
|
3115 if (prev->resolver == NULL) {
|
|
3116
|
|
3117 /*
|
|
3118 * create dummy resolver in http {} context
|
|
3119 * to inherit it in all servers
|
|
3120 */
|
|
3121
|
|
3122 prev->resolver = ngx_resolver_create(cf, NULL);
|
|
3123 if (prev->resolver == NULL) {
|
364
|
3124 return NGX_CONF_ERROR;
|
354
|
3125 }
|
|
3126 }
|
376
|
3127
|
366
|
3128 conf->resolver = prev->resolver;
|
348
|
3129 }
|
0
|
3130
|
28
|
3131 ngx_conf_merge_path_value(conf->client_body_temp_path,
|
|
3132 prev->client_body_temp_path,
|
|
3133 NGX_HTTP_CLIENT_TEMP_PATH, 0, 0, 0,
|
|
3134 ngx_garbage_collector_temp_handler, cf);
|
|
3135
|
0
|
3136 ngx_conf_merge_value(conf->reset_timedout_connection,
|
36
|
3137 prev->reset_timedout_connection, 0);
|
362
|
3138 ngx_conf_merge_value(conf->server_name_in_redirect,
|
|
3139 prev->server_name_in_redirect, 1);
|
70
|
3140 ngx_conf_merge_value(conf->port_in_redirect, prev->port_in_redirect, 1);
|
0
|
3141 ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1);
|
228
|
3142 ngx_conf_merge_value(conf->msie_refresh, prev->msie_refresh, 0);
|
76
|
3143 ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1);
|
228
|
3144 ngx_conf_merge_value(conf->recursive_error_pages,
|
|
3145 prev->recursive_error_pages, 0);
|
342
|
3146 ngx_conf_merge_value(conf->server_tokens, prev->server_tokens, 1);
|
0
|
3147
|
332
|
3148 ngx_conf_merge_ptr_value(conf->open_file_cache,
|
358
|
3149 prev->open_file_cache, NULL);
|
|
3150
|
|
3151 ngx_conf_merge_sec_value(conf->open_file_cache_valid,
|
|
3152 prev->open_file_cache_valid, 60);
|
|
3153
|
|
3154 ngx_conf_merge_uint_value(conf->open_file_cache_min_uses,
|
|
3155 prev->open_file_cache_min_uses, 1);
|
332
|
3156
|
|
3157 ngx_conf_merge_sec_value(conf->open_file_cache_errors,
|
358
|
3158 prev->open_file_cache_errors, 0);
|
332
|
3159
|
|
3160 ngx_conf_merge_sec_value(conf->open_file_cache_events,
|
358
|
3161 prev->open_file_cache_events, 0);
|
|
3162 #if (NGX_HTTP_GZIP)
|
|
3163
|
|
3164 ngx_conf_merge_value(conf->gzip_vary, prev->gzip_vary, 0);
|
|
3165 ngx_conf_merge_uint_value(conf->gzip_http_version, prev->gzip_http_version,
|
|
3166 NGX_HTTP_VERSION_11);
|
|
3167 ngx_conf_merge_bitmask_value(conf->gzip_proxied, prev->gzip_proxied,
|
|
3168 (NGX_CONF_BITMASK_SET|NGX_HTTP_GZIP_PROXIED_OFF));
|
|
3169
|
362
|
3170 #if (NGX_PCRE)
|
358
|
3171 ngx_conf_merge_ptr_value(conf->gzip_disable, prev->gzip_disable, NULL);
|
362
|
3172 #endif
|
358
|
3173
|
|
3174 #endif
|
0
|
3175
|
|
3176 return NGX_CONF_OK;
|
|
3177 }
|
|
3178
|
|
3179
|
72
|
3180 /* AF_INET only */
|
|
3181
|
36
|
3182 static char *
|
|
3183 ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
3184 {
|
|
3185 ngx_http_core_srv_conf_t *scf = conf;
|
|
3186
|
252
|
3187 ngx_str_t *value, size;
|
|
3188 ngx_url_t u;
|
|
3189 ngx_uint_t n;
|
|
3190 ngx_http_listen_t *ls;
|
0
|
3191
|
|
3192 /*
|
|
3193 * TODO: check duplicate 'listen' directives,
|
|
3194 * add resolved name to server names ???
|
|
3195 */
|
|
3196
|
72
|
3197 value = cf->args->elts;
|
126
|
3198
|
252
|
3199 ngx_memzero(&u, sizeof(ngx_url_t));
|
|
3200
|
|
3201 u.url = value[1];
|
|
3202 u.listen = 1;
|
266
|
3203 u.default_port = 80;
|
252
|
3204
|
340
|
3205 if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
|
252
|
3206 if (u.err) {
|
|
3207 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3208 "%s in \"%V\" of the \"listen\" directive",
|
|
3209 u.err, &u.url);
|
|
3210 }
|
|
3211
|
126
|
3212 return NGX_CONF_ERROR;
|
72
|
3213 }
|
|
3214
|
50
|
3215 ls = ngx_array_push(&scf->listen);
|
|
3216 if (ls == NULL) {
|
0
|
3217 return NGX_CONF_ERROR;
|
|
3218 }
|
|
3219
|
72
|
3220 ngx_memzero(ls, sizeof(ngx_http_listen_t));
|
0
|
3221
|
|
3222 ls->family = AF_INET;
|
252
|
3223 ls->addr = u.addr.in_addr;
|
266
|
3224 ls->port = u.port;
|
336
|
3225 ls->file_name = cf->conf_file->file.name.data;
|
0
|
3226 ls->line = cf->conf_file->line;
|
326
|
3227 ls->conf.backlog = NGX_LISTEN_BACKLOG;
|
112
|
3228 ls->conf.rcvbuf = -1;
|
|
3229 ls->conf.sndbuf = -1;
|
72
|
3230
|
180
|
3231 n = ngx_inet_ntop(AF_INET, &ls->addr, ls->conf.addr, INET_ADDRSTRLEN + 6);
|
|
3232 ngx_sprintf(&ls->conf.addr[n], ":%ui", ls->port);
|
|
3233
|
72
|
3234 if (cf->args->nelts == 2) {
|
|
3235 return NGX_CONF_OK;
|
|
3236 }
|
|
3237
|
|
3238 if (ngx_strcmp(value[2].data, "default") == 0) {
|
|
3239 ls->conf.default_server = 1;
|
|
3240 n = 3;
|
138
|
3241
|
72
|
3242 } else {
|
|
3243 n = 2;
|
0
|
3244 }
|
|
3245
|
72
|
3246 for ( /* void */ ; n < cf->args->nelts; n++) {
|
|
3247
|
|
3248 if (ls->conf.default_server == 0) {
|
|
3249 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3250 "\"%V\" parameter can be specified for "
|
|
3251 "the default \"listen\" directive only",
|
|
3252 &value[n]);
|
|
3253 return NGX_CONF_ERROR;
|
|
3254 }
|
|
3255
|
|
3256 if (ngx_strcmp(value[n].data, "bind") == 0) {
|
|
3257 ls->conf.bind = 1;
|
|
3258 continue;
|
|
3259 }
|
|
3260
|
112
|
3261 if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) {
|
|
3262 ls->conf.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8);
|
72
|
3263 ls->conf.bind = 1;
|
|
3264
|
|
3265 if (ls->conf.backlog == NGX_ERROR || ls->conf.backlog == 0) {
|
|
3266 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3267 "invalid backlog \"%V\"", &value[n]);
|
|
3268 return NGX_CONF_ERROR;
|
|
3269 }
|
|
3270
|
|
3271 continue;
|
|
3272 }
|
|
3273
|
112
|
3274 if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) {
|
|
3275 size.len = value[n].len - 7;
|
|
3276 size.data = value[n].data + 7;
|
|
3277
|
|
3278 ls->conf.rcvbuf = ngx_parse_size(&size);
|
|
3279 ls->conf.bind = 1;
|
|
3280
|
|
3281 if (ls->conf.rcvbuf == NGX_ERROR) {
|
|
3282 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3283 "invalid rcvbuf \"%V\"", &value[n]);
|
|
3284 return NGX_CONF_ERROR;
|
|
3285 }
|
|
3286
|
|
3287 continue;
|
|
3288 }
|
|
3289
|
|
3290 if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) {
|
|
3291 size.len = value[n].len - 7;
|
|
3292 size.data = value[n].data + 7;
|
|
3293
|
|
3294 ls->conf.sndbuf = ngx_parse_size(&size);
|
|
3295 ls->conf.bind = 1;
|
|
3296
|
|
3297 if (ls->conf.sndbuf == NGX_ERROR) {
|
|
3298 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3299 "invalid sndbuf \"%V\"", &value[n]);
|
|
3300 return NGX_CONF_ERROR;
|
|
3301 }
|
|
3302
|
|
3303 continue;
|
|
3304 }
|
|
3305
|
|
3306 if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) {
|
72
|
3307 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
|
112
|
3308 ls->conf.accept_filter = (char *) &value[n].data[14];
|
72
|
3309 ls->conf.bind = 1;
|
|
3310 #else
|
|
3311 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3312 "accept filters \"%V\" are not supported "
|
|
3313 "on this platform, ignored",
|
|
3314 &value[n]);
|
|
3315 #endif
|
|
3316 continue;
|
|
3317 }
|
|
3318
|
|
3319 if (ngx_strcmp(value[n].data, "deferred") == 0) {
|
|
3320 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
|
|
3321 ls->conf.deferred_accept = 1;
|
|
3322 ls->conf.bind = 1;
|
|
3323 #else
|
|
3324 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3325 "the deferred accept is not supported "
|
|
3326 "on this platform, ignored");
|
|
3327 #endif
|
|
3328 continue;
|
|
3329 }
|
0
|
3330
|
|
3331 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
72
|
3332 "the invalid \"%V\" parameter", &value[n]);
|
0
|
3333 return NGX_CONF_ERROR;
|
|
3334 }
|
|
3335
|
|
3336 return NGX_CONF_OK;
|
|
3337 }
|
|
3338
|
|
3339
|
36
|
3340 static char *
|
|
3341 ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
3342 {
|
142
|
3343 ngx_http_core_srv_conf_t *cscf = conf;
|
|
3344
|
|
3345 u_char ch;
|
|
3346 ngx_str_t *value, name;
|
|
3347 ngx_uint_t i;
|
|
3348 ngx_http_server_name_t *sn;
|
0
|
3349
|
|
3350 value = cf->args->elts;
|
|
3351
|
142
|
3352 ch = value[1].data[0];
|
|
3353
|
|
3354 if (cscf->server_name.data == NULL && value[1].len) {
|
|
3355 name = value[1];
|
|
3356
|
|
3357 if (ch == '.') {
|
|
3358 name.len--;
|
|
3359 name.data++;
|
|
3360 }
|
|
3361
|
|
3362 cscf->server_name.len = name.len;
|
|
3363 cscf->server_name.data = ngx_pstrdup(cf->pool, &name);
|
|
3364 if (cscf->server_name.data == NULL) {
|
|
3365 return NGX_CONF_ERROR;
|
|
3366 }
|
|
3367 }
|
|
3368
|
|
3369 for (i = 1; i < cf->args->nelts; i++) {
|
|
3370
|
|
3371 ch = value[i].data[0];
|
|
3372
|
|
3373 if (value[i].len == 0
|
|
3374 || (ch == '*' && (value[i].len < 3 || value[i].data[1] != '.'))
|
|
3375 || (ch == '.' && value[i].len < 2))
|
|
3376 {
|
|
3377 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3378 "server name \"%V\" is invalid", &value[i]);
|
|
3379 return NGX_CONF_ERROR;
|
|
3380 }
|
|
3381
|
294
|
3382 if (ngx_strchr(value[i].data, '/')) {
|
|
3383 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
3384 "server name \"%V\" has strange symbols",
|
|
3385 &value[i]);
|
|
3386 }
|
|
3387
|
362
|
3388 if (value[i].len == 1 && ch == '*') {
|
|
3389 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3390 "\"server_name *\" is unsupported, use "
|
|
3391 "\"server_name_in_redirect off\" instead");
|
|
3392 return NGX_CONF_ERROR;
|
|
3393 }
|
|
3394
|
142
|
3395 sn = ngx_array_push(&cscf->server_names);
|
50
|
3396 if (sn == NULL) {
|
4
|
3397 return NGX_CONF_ERROR;
|
|
3398 }
|
0
|
3399
|
326
|
3400 #if (NGX_PCRE)
|
|
3401 sn->regex = NULL;
|
|
3402 #endif
|
|
3403 sn->core_srv_conf = cscf;
|
358
|
3404 sn->name = value[i];
|
326
|
3405
|
|
3406 if (value[i].data[0] != '~') {
|
|
3407 continue;
|
|
3408 }
|
|
3409
|
|
3410 #if (NGX_PCRE)
|
356
|
3411 {
|
|
3412 ngx_str_t err;
|
|
3413 u_char errstr[NGX_MAX_CONF_ERRSTR];
|
|
3414
|
326
|
3415 err.len = NGX_MAX_CONF_ERRSTR;
|
|
3416 err.data = errstr;
|
|
3417
|
|
3418 value[i].len--;
|
|
3419 value[i].data++;
|
|
3420
|
376
|
3421 sn->regex = ngx_regex_compile(&value[i], 0, cf->pool, &err);
|
326
|
3422
|
|
3423 if (sn->regex == NULL) {
|
|
3424 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
|
|
3425 return NGX_CONF_ERROR;
|
|
3426 }
|
|
3427
|
358
|
3428 sn->name = value[i];
|
356
|
3429 }
|
326
|
3430 #else
|
|
3431 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3432 "the using of the regex \"%V\" "
|
|
3433 "requires PCRE library", &value[i]);
|
|
3434
|
|
3435 return NGX_CONF_ERROR;
|
|
3436 #endif
|
0
|
3437 }
|
|
3438
|
|
3439 return NGX_CONF_OK;
|
|
3440 }
|
|
3441
|
|
3442
|
36
|
3443 static char *
|
|
3444 ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
3445 {
|
|
3446 ngx_http_core_loc_conf_t *lcf = conf;
|
|
3447
|
144
|
3448 ngx_str_t *value;
|
|
3449 ngx_uint_t alias, n;
|
|
3450 ngx_http_script_compile_t sc;
|
0
|
3451
|
|
3452 alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0;
|
|
3453
|
|
3454 if (lcf->root.data) {
|
|
3455
|
|
3456 /* the (ngx_uint_t) cast is required by gcc 2.7.2.3 */
|
|
3457
|
|
3458 if ((ngx_uint_t) lcf->alias == alias) {
|
|
3459 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
3460 "\"%V\" directive is duplicate",
|
|
3461 &cmd->name);
|
0
|
3462 } else {
|
|
3463 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
3464 "\"%V\" directive is duplicate, "
|
0
|
3465 "\"%s\" directive is specified before",
|
10
|
3466 &cmd->name, lcf->alias ? "alias" : "root");
|
0
|
3467 }
|
|
3468
|
|
3469 return NGX_CONF_ERROR;
|
|
3470 }
|
|
3471
|
324
|
3472 if (lcf->named && alias) {
|
|
3473 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3474 "the \"alias\" directive may not be used "
|
|
3475 "inside named location");
|
|
3476
|
|
3477 return NGX_CONF_ERROR;
|
|
3478 }
|
|
3479
|
308
|
3480 #if (NGX_PCRE)
|
|
3481
|
|
3482 if (lcf->regex && alias) {
|
|
3483 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3484 "the \"alias\" directive may not be used "
|
|
3485 "inside location given by regular expression");
|
|
3486
|
|
3487 return NGX_CONF_ERROR;
|
|
3488 }
|
|
3489
|
|
3490 #endif
|
|
3491
|
0
|
3492 value = cf->args->elts;
|
|
3493
|
294
|
3494 if (ngx_strstr(value[1].data, "$document_root")
|
|
3495 || ngx_strstr(value[1].data, "${document_root}"))
|
|
3496 {
|
|
3497 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3498 "the $document_root variable may not be used "
|
|
3499 "in the \"%V\" directive",
|
|
3500 &cmd->name);
|
|
3501
|
|
3502 return NGX_CONF_ERROR;
|
|
3503 }
|
|
3504
|
0
|
3505 lcf->alias = alias;
|
|
3506 lcf->root = value[1];
|
|
3507
|
|
3508 if (!alias && lcf->root.data[lcf->root.len - 1] == '/') {
|
|
3509 lcf->root.len--;
|
|
3510 }
|
|
3511
|
216
|
3512 if (lcf->root.data[0] != '$') {
|
324
|
3513 if (ngx_conf_full_name(cf->cycle, &lcf->root, 0) == NGX_ERROR) {
|
216
|
3514 return NGX_CONF_ERROR;
|
|
3515 }
|
152
|
3516 }
|
|
3517
|
|
3518 n = ngx_http_script_variables_count(&lcf->root);
|
144
|
3519
|
|
3520 if (n == 0) {
|
|
3521 return NGX_CONF_OK;
|
|
3522 }
|
|
3523
|
|
3524 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
3525
|
|
3526 sc.cf = cf;
|
152
|
3527 sc.source = &lcf->root;
|
144
|
3528 sc.lengths = &lcf->root_lengths;
|
|
3529 sc.values = &lcf->root_values;
|
|
3530 sc.variables = n;
|
|
3531 sc.complete_lengths = 1;
|
|
3532 sc.complete_values = 1;
|
|
3533
|
|
3534 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
3535 return NGX_CONF_ERROR;
|
|
3536 }
|
|
3537
|
0
|
3538 return NGX_CONF_OK;
|
|
3539 }
|
|
3540
|
|
3541
|
180
|
3542 static ngx_http_method_name_t ngx_methods_names[] = {
|
286
|
3543 { (u_char *) "GET", (uint32_t) ~NGX_HTTP_GET },
|
|
3544 { (u_char *) "HEAD", (uint32_t) ~NGX_HTTP_HEAD },
|
|
3545 { (u_char *) "POST", (uint32_t) ~NGX_HTTP_POST },
|
|
3546 { (u_char *) "PUT", (uint32_t) ~NGX_HTTP_PUT },
|
|
3547 { (u_char *) "DELETE", (uint32_t) ~NGX_HTTP_DELETE },
|
|
3548 { (u_char *) "MKCOL", (uint32_t) ~NGX_HTTP_MKCOL },
|
|
3549 { (u_char *) "COPY", (uint32_t) ~NGX_HTTP_COPY },
|
|
3550 { (u_char *) "MOVE", (uint32_t) ~NGX_HTTP_MOVE },
|
|
3551 { (u_char *) "OPTIONS", (uint32_t) ~NGX_HTTP_OPTIONS },
|
|
3552 { (u_char *) "PROPFIND" , (uint32_t) ~NGX_HTTP_PROPFIND },
|
|
3553 { (u_char *) "PROPPATCH", (uint32_t) ~NGX_HTTP_PROPPATCH },
|
|
3554 { (u_char *) "LOCK", (uint32_t) ~NGX_HTTP_LOCK },
|
|
3555 { (u_char *) "UNLOCK", (uint32_t) ~NGX_HTTP_UNLOCK },
|
180
|
3556 { NULL, 0 }
|
|
3557 };
|
|
3558
|
|
3559
|
|
3560 static char *
|
|
3561 ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
3562 {
|
|
3563 ngx_http_core_loc_conf_t *clcf = conf;
|
|
3564
|
|
3565 char *rv;
|
|
3566 void *mconf;
|
|
3567 ngx_str_t *value;
|
|
3568 ngx_uint_t i;
|
|
3569 ngx_conf_t save;
|
|
3570 ngx_http_module_t *module;
|
|
3571 ngx_http_conf_ctx_t *ctx, *pctx;
|
|
3572 ngx_http_method_name_t *name;
|
|
3573 ngx_http_core_loc_conf_t *lcf, **clcfp;
|
|
3574
|
|
3575 if (clcf->limit_except) {
|
|
3576 return "duplicate";
|
|
3577 }
|
|
3578
|
|
3579 clcf->limit_except = 0xffffffff;
|
|
3580
|
|
3581 value = cf->args->elts;
|
|
3582
|
|
3583 for (i = 1; i < cf->args->nelts; i++) {
|
|
3584 for (name = ngx_methods_names; name->name; name++) {
|
|
3585
|
|
3586 if (ngx_strcasecmp(value[i].data, name->name) == 0) {
|
|
3587 clcf->limit_except &= name->method;
|
|
3588 goto next;
|
|
3589 }
|
|
3590 }
|
|
3591
|
|
3592 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3593 "invalid method \"%V\"", &value[i]);
|
|
3594 return NGX_CONF_ERROR;
|
|
3595
|
|
3596 next:
|
|
3597 continue;
|
|
3598 }
|
|
3599
|
|
3600 if (!(clcf->limit_except & NGX_HTTP_GET)) {
|
|
3601 clcf->limit_except &= (uint32_t) ~NGX_HTTP_HEAD;
|
|
3602 }
|
|
3603
|
|
3604 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
|
|
3605 if (ctx == NULL) {
|
|
3606 return NGX_CONF_ERROR;
|
|
3607 }
|
|
3608
|
|
3609 pctx = cf->ctx;
|
|
3610 ctx->main_conf = pctx->main_conf;
|
|
3611 ctx->srv_conf = pctx->srv_conf;
|
|
3612
|
|
3613 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
|
|
3614 if (ctx->loc_conf == NULL) {
|
|
3615 return NGX_CONF_ERROR;
|
|
3616 }
|
|
3617
|
|
3618 for (i = 0; ngx_modules[i]; i++) {
|
|
3619 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
|
|
3620 continue;
|
|
3621 }
|
|
3622
|
|
3623 module = ngx_modules[i]->ctx;
|
|
3624
|
|
3625 if (module->create_loc_conf) {
|
|
3626
|
|
3627 mconf = module->create_loc_conf(cf);
|
|
3628 if (mconf == NULL) {
|
|
3629 return NGX_CONF_ERROR;
|
|
3630 }
|
|
3631
|
|
3632 ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
|
|
3633 }
|
|
3634 }
|
|
3635
|
|
3636
|
|
3637 lcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
|
|
3638 clcf->limit_except_loc_conf = ctx->loc_conf;
|
|
3639 lcf->loc_conf = ctx->loc_conf;
|
|
3640 lcf->name = clcf->name;
|
|
3641 lcf->noname = 1;
|
|
3642
|
308
|
3643 if (clcf->locations == NULL) {
|
|
3644 clcf->locations = ngx_array_create(cf->pool, 2, sizeof(void *));
|
|
3645 if (clcf->locations == NULL) {
|
180
|
3646 return NGX_CONF_ERROR;
|
|
3647 }
|
|
3648 }
|
|
3649
|
308
|
3650 clcfp = ngx_array_push(clcf->locations);
|
180
|
3651 if (clcfp == NULL) {
|
|
3652 return NGX_CONF_ERROR;
|
|
3653 }
|
|
3654
|
|
3655 *clcfp = lcf;
|
|
3656
|
|
3657
|
|
3658 save = *cf;
|
|
3659 cf->ctx = ctx;
|
|
3660 cf->cmd_type = NGX_HTTP_LMT_CONF;
|
|
3661
|
|
3662 rv = ngx_conf_parse(cf, NULL);
|
|
3663
|
|
3664 *cf = save;
|
|
3665
|
|
3666 return rv;
|
|
3667 }
|
|
3668
|
|
3669
|
36
|
3670 static char *
|
|
3671 ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
3672 {
|
|
3673 ngx_http_core_loc_conf_t *lcf = conf;
|
|
3674
|
372
|
3675 u_char *args;
|
222
|
3676 ngx_int_t overwrite;
|
|
3677 ngx_str_t *value, uri;
|
|
3678 ngx_uint_t i, n, nvar;
|
|
3679 ngx_array_t *uri_lengths, *uri_values;
|
|
3680 ngx_http_err_page_t *err;
|
|
3681 ngx_http_script_compile_t sc;
|
0
|
3682
|
|
3683 if (lcf->error_pages == NULL) {
|
36
|
3684 lcf->error_pages = ngx_array_create(cf->pool, 4,
|
0
|
3685 sizeof(ngx_http_err_page_t));
|
|
3686 if (lcf->error_pages == NULL) {
|
|
3687 return NGX_CONF_ERROR;
|
|
3688 }
|
|
3689 }
|
|
3690
|
|
3691 value = cf->args->elts;
|
|
3692
|
|
3693 i = cf->args->nelts - 2;
|
|
3694
|
|
3695 if (value[i].data[0] == '=') {
|
|
3696 if (i == 1) {
|
|
3697 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
3698 "invalid value \"%V\"", &value[i]);
|
0
|
3699 return NGX_CONF_ERROR;
|
|
3700 }
|
|
3701
|
104
|
3702 if (value[i].len > 1) {
|
|
3703 overwrite = ngx_atoi(&value[i].data[1], value[i].len - 1);
|
|
3704
|
|
3705 if (overwrite == NGX_ERROR) {
|
|
3706 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3707 "invalid value \"%V\"", &value[i]);
|
|
3708 return NGX_CONF_ERROR;
|
|
3709 }
|
|
3710
|
|
3711 } else {
|
|
3712 overwrite = 0;
|
0
|
3713 }
|
|
3714
|
|
3715 n = 2;
|
|
3716
|
|
3717 } else {
|
104
|
3718 overwrite = -1;
|
0
|
3719 n = 1;
|
|
3720 }
|
|
3721
|
222
|
3722 uri = value[cf->args->nelts - 1];
|
|
3723 uri_lengths = NULL;
|
|
3724 uri_values = NULL;
|
|
3725
|
|
3726 nvar = ngx_http_script_variables_count(&uri);
|
|
3727
|
|
3728 if (nvar) {
|
|
3729 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
3730
|
|
3731 sc.cf = cf;
|
|
3732 sc.source = &uri;
|
|
3733 sc.lengths = &uri_lengths;
|
|
3734 sc.values = &uri_values;
|
|
3735 sc.variables = nvar;
|
|
3736 sc.complete_lengths = 1;
|
|
3737 sc.complete_values = 1;
|
|
3738
|
|
3739 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
3740 return NGX_CONF_ERROR;
|
|
3741 }
|
|
3742 }
|
|
3743
|
372
|
3744 args = (u_char *) ngx_strchr(uri.data, '?');
|
|
3745
|
0
|
3746 for (i = 1; i < cf->args->nelts - n; i++) {
|
50
|
3747 err = ngx_array_push(lcf->error_pages);
|
|
3748 if (err == NULL) {
|
0
|
3749 return NGX_CONF_ERROR;
|
|
3750 }
|
|
3751
|
|
3752 err->status = ngx_atoi(value[i].data, value[i].len);
|
36
|
3753
|
236
|
3754 if (err->status == NGX_ERROR || err->status == 499) {
|
0
|
3755 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
3756 "invalid value \"%V\"", &value[i]);
|
0
|
3757 return NGX_CONF_ERROR;
|
|
3758 }
|
|
3759
|
|
3760 if (err->status < 400 || err->status > 599) {
|
|
3761 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
10
|
3762 "value \"%V\" must be between 400 and 599",
|
|
3763 &value[i]);
|
0
|
3764 return NGX_CONF_ERROR;
|
|
3765 }
|
|
3766
|
366
|
3767 if (overwrite >= 0) {
|
|
3768 err->overwrite = overwrite;
|
|
3769
|
|
3770 } else {
|
|
3771 switch (err->status) {
|
|
3772 case NGX_HTTP_TO_HTTPS:
|
|
3773 case NGX_HTTPS_CERT_ERROR:
|
|
3774 case NGX_HTTPS_NO_CERT:
|
|
3775 err->overwrite = NGX_HTTP_BAD_REQUEST;
|
|
3776 break;
|
|
3777
|
|
3778 default:
|
|
3779 err->overwrite = err->status;
|
|
3780 break;
|
|
3781 }
|
|
3782 }
|
104
|
3783
|
372
|
3784 if (args) {
|
|
3785 err->uri.len = args - uri.data;
|
|
3786 err->uri.data = uri.data;
|
|
3787 args++;
|
|
3788 err->args.len = (uri.data + uri.len) - args;
|
|
3789 err->args.data = args;
|
|
3790
|
|
3791 } else {
|
|
3792 err->uri = uri;
|
|
3793 err->args.len = 0;
|
|
3794 err->args.data = NULL;
|
|
3795 }
|
|
3796
|
222
|
3797 err->uri_lengths = uri_lengths;
|
|
3798 err->uri_values = uri_values;
|
0
|
3799 }
|
|
3800
|
|
3801 return NGX_CONF_OK;
|
|
3802 }
|
|
3803
|
|
3804
|
36
|
3805 static char *
|
384
|
3806 ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
3807 {
|
|
3808 ngx_http_core_loc_conf_t *clcf = conf;
|
|
3809
|
|
3810 ngx_str_t *value;
|
|
3811 ngx_uint_t i, n;
|
|
3812 ngx_http_try_file_t *tf;
|
|
3813 ngx_http_script_compile_t sc;
|
|
3814 ngx_http_core_main_conf_t *cmcf;
|
|
3815
|
|
3816 if (clcf->try_files) {
|
|
3817 return "is duplicate";
|
|
3818 }
|
|
3819
|
|
3820 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
|
|
3821
|
|
3822 cmcf->try_files = 1;
|
|
3823
|
|
3824 tf = ngx_pcalloc(cf->pool, cf->args->nelts * sizeof(ngx_http_try_file_t));
|
|
3825 if (tf == NULL) {
|
|
3826 return NGX_CONF_ERROR;
|
|
3827 }
|
|
3828
|
|
3829 clcf->try_files = tf;
|
|
3830
|
|
3831 value = cf->args->elts;
|
|
3832
|
|
3833 for (i = 0; i < cf->args->nelts - 1; i++) {
|
|
3834
|
|
3835 tf[i].name = value[i + 1];
|
|
3836
|
|
3837 if (tf[i].name.data[tf[i].name.len - 1] == '/') {
|
|
3838 tf[i].test_dir = 1;
|
|
3839 tf[i].name.len--;
|
|
3840 tf[i].name.data[tf[i].name.len] = '\0';
|
|
3841 }
|
|
3842
|
|
3843 n = ngx_http_script_variables_count(&tf[i].name);
|
|
3844
|
|
3845 if (n) {
|
|
3846 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
3847
|
|
3848 sc.cf = cf;
|
|
3849 sc.source = &tf[i].name;
|
|
3850 sc.lengths = &tf[i].lengths;
|
|
3851 sc.values = &tf[i].values;
|
|
3852 sc.variables = n;
|
|
3853 sc.complete_lengths = 1;
|
|
3854 sc.complete_values = 1;
|
|
3855
|
|
3856 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
3857 return NGX_CONF_ERROR;
|
|
3858 }
|
|
3859
|
|
3860 } else {
|
|
3861 /* add trailing '\0' to length */
|
|
3862 tf[i].name.len++;
|
|
3863 }
|
|
3864 }
|
|
3865
|
|
3866 return NGX_CONF_OK;
|
|
3867 }
|
|
3868
|
|
3869
|
|
3870 static char *
|
332
|
3871 ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
3872 {
|
|
3873 ngx_http_core_loc_conf_t *lcf = conf;
|
|
3874
|
|
3875 time_t inactive;
|
|
3876 ngx_str_t *value, s;
|
|
3877 ngx_int_t max;
|
|
3878 ngx_uint_t i;
|
|
3879
|
|
3880 if (lcf->open_file_cache != NGX_CONF_UNSET_PTR) {
|
|
3881 return "is duplicate";
|
|
3882 }
|
|
3883
|
|
3884 value = cf->args->elts;
|
|
3885
|
|
3886 max = 0;
|
|
3887 inactive = 60;
|
|
3888
|
|
3889 for (i = 1; i < cf->args->nelts; i++) {
|
|
3890
|
|
3891 if (ngx_strncmp(value[i].data, "max=", 4) == 0) {
|
|
3892
|
|
3893 max = ngx_atoi(value[i].data + 4, value[i].len - 4);
|
|
3894 if (max == NGX_ERROR) {
|
|
3895 return NGX_CONF_ERROR;
|
|
3896 }
|
|
3897
|
|
3898 continue;
|
|
3899 }
|
|
3900
|
|
3901 if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) {
|
|
3902
|
|
3903 s.len = value[i].len - 9;
|
|
3904 s.data = value[i].data + 9;
|
|
3905
|
|
3906 inactive = ngx_parse_time(&s, 1);
|
|
3907 if (inactive < 0) {
|
|
3908 return NGX_CONF_ERROR;
|
|
3909 }
|
|
3910
|
|
3911 continue;
|
|
3912 }
|
|
3913
|
|
3914 if (ngx_strcmp(value[i].data, "off") == 0) {
|
|
3915
|
|
3916 lcf->open_file_cache = NULL;
|
|
3917
|
|
3918 continue;
|
|
3919 }
|
|
3920
|
|
3921 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3922 "invalid \"open_file_cache\" parameter \"%V\"",
|
|
3923 &value[i]);
|
|
3924 return NGX_CONF_ERROR;
|
|
3925 }
|
|
3926
|
|
3927 if (lcf->open_file_cache == NULL) {
|
|
3928 return NGX_CONF_OK;
|
|
3929 }
|
|
3930
|
|
3931 if (max == 0) {
|
|
3932 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
3933 "\"open_file_cache\" must have \"max\" parameter");
|
|
3934 return NGX_CONF_ERROR;
|
|
3935 }
|
|
3936
|
|
3937 lcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive);
|
|
3938 if (lcf->open_file_cache) {
|
|
3939 return NGX_CONF_OK;
|
|
3940 }
|
|
3941
|
|
3942 return NGX_CONF_ERROR;
|
|
3943 }
|
|
3944
|
|
3945
|
|
3946 static char *
|
58
|
3947 ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
3948 {
|
|
3949 ngx_http_core_loc_conf_t *lcf = conf;
|
|
3950
|
|
3951 lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args);
|
|
3952 if (lcf->err_log == NULL) {
|
|
3953 return NGX_CONF_ERROR;
|
|
3954 }
|
|
3955
|
|
3956 return ngx_set_error_log_levels(cf, lcf->err_log);
|
|
3957 }
|
|
3958
|
|
3959
|
|
3960 static char *
|
36
|
3961 ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
3962 {
|
|
3963 ngx_http_core_loc_conf_t *lcf = conf;
|
|
3964
|
|
3965 ngx_str_t *value;
|
|
3966
|
|
3967 if (lcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) {
|
|
3968 return "is duplicate";
|
|
3969 }
|
|
3970
|
|
3971 value = cf->args->elts;
|
|
3972
|
|
3973 lcf->keepalive_timeout = ngx_parse_time(&value[1], 0);
|
36
|
3974
|
0
|
3975 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) {
|
|
3976 return "invalid value";
|
|
3977 }
|
|
3978
|
|
3979 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) {
|
|
3980 return "value must be less than 597 hours";
|
|
3981 }
|
|
3982
|
|
3983 if (cf->args->nelts == 2) {
|
|
3984 return NGX_CONF_OK;
|
|
3985 }
|
|
3986
|
|
3987 lcf->keepalive_header = ngx_parse_time(&value[2], 1);
|
36
|
3988
|
0
|
3989 if (lcf->keepalive_header == NGX_ERROR) {
|
|
3990 return "invalid value";
|
|
3991 }
|
|
3992
|
|
3993 if (lcf->keepalive_header == NGX_PARSE_LARGE_TIME) {
|
|
3994 return "value must be less than 68 years";
|
|
3995 }
|
|
3996
|
|
3997 return NGX_CONF_OK;
|
|
3998 }
|
|
3999
|
|
4000
|
36
|
4001 static char *
|
58
|
4002 ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
4003 {
|
|
4004 ngx_http_core_loc_conf_t *lcf = conf;
|
|
4005
|
58
|
4006 if (lcf->internal != NGX_CONF_UNSET) {
|
|
4007 return "is duplicate";
|
0
|
4008 }
|
|
4009
|
58
|
4010 lcf->internal = 1;
|
|
4011
|
|
4012 return NGX_CONF_OK;
|
0
|
4013 }
|
|
4014
|
|
4015
|
36
|
4016 static char *
|
348
|
4017 ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
4018 {
|
|
4019 ngx_http_core_loc_conf_t *clcf = conf;
|
|
4020
|
|
4021 ngx_url_t u;
|
|
4022 ngx_str_t *value;
|
|
4023
|
366
|
4024 if (clcf->resolver) {
|
|
4025 return "is duplicate";
|
|
4026 }
|
|
4027
|
348
|
4028 value = cf->args->elts;
|
|
4029
|
354
|
4030 ngx_memzero(&u, sizeof(ngx_url_t));
|
|
4031
|
348
|
4032 u.host = value[1];
|
|
4033 u.port = 53;
|
|
4034
|
|
4035 if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
|
|
4036 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V: %s", &u.host, u.err);
|
|
4037 return NGX_CONF_ERROR;
|
|
4038 }
|
|
4039
|
366
|
4040 clcf->resolver = ngx_resolver_create(cf, &u.addrs[0]);
|
348
|
4041 if (clcf->resolver == NULL) {
|
|
4042 return NGX_OK;
|
|
4043 }
|
|
4044
|
|
4045 return NGX_CONF_OK;
|
|
4046 }
|
|
4047
|
|
4048
|
358
|
4049 #if (NGX_HTTP_GZIP)
|
|
4050
|
|
4051 static char *
|
|
4052 ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
4053 {
|
|
4054 #if (NGX_PCRE)
|
|
4055 ngx_http_core_loc_conf_t *clcf = conf;
|
|
4056
|
|
4057 ngx_str_t err, *value;
|
|
4058 ngx_uint_t i;
|
|
4059 ngx_regex_elt_t *re;
|
|
4060 u_char errstr[NGX_MAX_CONF_ERRSTR];
|
|
4061
|
|
4062 if (clcf->gzip_disable == NGX_CONF_UNSET_PTR) {
|
|
4063 clcf->gzip_disable = ngx_array_create(cf->pool, 2,
|
|
4064 sizeof(ngx_regex_elt_t));
|
|
4065 if (clcf->gzip_disable == NULL) {
|
|
4066 return NGX_CONF_ERROR;
|
|
4067 }
|
|
4068 }
|
|
4069
|
|
4070 value = cf->args->elts;
|
|
4071
|
|
4072 err.len = NGX_MAX_CONF_ERRSTR;
|
|
4073 err.data = errstr;
|
|
4074
|
|
4075 for (i = 1; i < cf->args->nelts; i++) {
|
|
4076
|
|
4077 re = ngx_array_push(clcf->gzip_disable);
|
|
4078 if (re == NULL) {
|
|
4079 return NGX_CONF_ERROR;
|
|
4080 }
|
|
4081
|
|
4082 re->regex = ngx_regex_compile(&value[i], NGX_REGEX_CASELESS, cf->pool,
|
|
4083 &err);
|
|
4084
|
|
4085 if (re->regex == NULL) {
|
|
4086 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
|
|
4087 return NGX_CONF_ERROR;
|
|
4088 }
|
|
4089
|
|
4090 re->name = value[i].data;
|
|
4091 }
|
|
4092
|
|
4093 return NGX_CONF_OK;
|
|
4094
|
|
4095 #else
|
|
4096 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4097 "\"gzip_disable\" requires PCRE library");
|
|
4098
|
|
4099 return NGX_CONF_ERROR;
|
|
4100 #endif
|
|
4101 }
|
|
4102
|
|
4103 #endif
|
|
4104
|
|
4105
|
348
|
4106 static char *
|
36
|
4107 ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data)
|
0
|
4108 {
|
22
|
4109 #if (NGX_FREEBSD)
|
2
|
4110 ssize_t *np = data;
|
0
|
4111
|
222
|
4112 if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) {
|
0
|
4113 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4114 "\"send_lowat\" must be less than %d "
|
|
4115 "(sysctl net.inet.tcp.sendspace)",
|
|
4116 ngx_freebsd_net_inet_tcp_sendspace);
|
|
4117
|
|
4118 return NGX_CONF_ERROR;
|
|
4119 }
|
|
4120
|
18
|
4121 #elif !(NGX_HAVE_SO_SNDLOWAT)
|
22
|
4122 ssize_t *np = data;
|
0
|
4123
|
|
4124 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
4125 "\"send_lowat\" is not supported, ignored");
|
|
4126
|
2
|
4127 *np = 0;
|
|
4128
|
0
|
4129 #endif
|
|
4130
|
|
4131 return NGX_CONF_OK;
|
|
4132 }
|
300
|
4133
|
|
4134
|
|
4135 static char *
|
|
4136 ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data)
|
|
4137 {
|
|
4138 size_t *sp = data;
|
|
4139
|
|
4140 if (*sp < NGX_MIN_POOL_SIZE) {
|
|
4141 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
4142 "pool must be no less than %uz", NGX_MIN_POOL_SIZE);
|
|
4143
|
|
4144 return NGX_CONF_ERROR;
|
|
4145 }
|
|
4146
|
|
4147 return NGX_CONF_OK;
|
|
4148 }
|