50
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #include <ngx_config.h>
|
|
8 #include <ngx_core.h>
|
|
9 #include <ngx_http.h>
|
|
10
|
|
11
|
|
12 typedef struct {
|
200
|
13 ngx_http_upstream_conf_t upstream;
|
|
14
|
|
15 ngx_str_t index;
|
|
16
|
|
17 ngx_array_t *flushes;
|
|
18 ngx_array_t *params_len;
|
|
19 ngx_array_t *params;
|
|
20 ngx_array_t *params_source;
|
306
|
21 ngx_array_t *catch_stderr;
|
430
|
22
|
|
23 ngx_array_t *fastcgi_lengths;
|
|
24 ngx_array_t *fastcgi_values;
|
438
|
25
|
576
|
26 ngx_hash_t headers_hash;
|
|
27 ngx_uint_t header_params;
|
|
28
|
466
|
29 #if (NGX_HTTP_CACHE)
|
|
30 ngx_http_complex_value_t cache_key;
|
|
31 #endif
|
|
32
|
438
|
33 #if (NGX_PCRE)
|
|
34 ngx_regex_t *split_regex;
|
|
35 ngx_str_t split_name;
|
|
36 #endif
|
50
|
37 } ngx_http_fastcgi_loc_conf_t;
|
|
38
|
|
39
|
|
40 typedef enum {
|
|
41 ngx_http_fastcgi_st_version = 0,
|
|
42 ngx_http_fastcgi_st_type,
|
|
43 ngx_http_fastcgi_st_request_id_hi,
|
|
44 ngx_http_fastcgi_st_request_id_lo,
|
|
45 ngx_http_fastcgi_st_content_length_hi,
|
|
46 ngx_http_fastcgi_st_content_length_lo,
|
|
47 ngx_http_fastcgi_st_padding_length,
|
|
48 ngx_http_fastcgi_st_reserved,
|
|
49 ngx_http_fastcgi_st_data,
|
64
|
50 ngx_http_fastcgi_st_padding
|
50
|
51 } ngx_http_fastcgi_state_e;
|
|
52
|
|
53
|
|
54 typedef struct {
|
316
|
55 u_char *start;
|
|
56 u_char *end;
|
|
57 } ngx_http_fastcgi_split_part_t;
|
|
58
|
|
59
|
|
60 typedef struct {
|
200
|
61 ngx_http_fastcgi_state_e state;
|
|
62 u_char *pos;
|
|
63 u_char *last;
|
|
64 ngx_uint_t type;
|
|
65 size_t length;
|
|
66 size_t padding;
|
|
67
|
564
|
68 unsigned fastcgi_stdout:1;
|
|
69 unsigned large_stderr:1;
|
316
|
70
|
|
71 ngx_array_t *split_parts;
|
438
|
72
|
|
73 ngx_str_t script_name;
|
|
74 ngx_str_t path_info;
|
50
|
75 } ngx_http_fastcgi_ctx_t;
|
|
76
|
|
77
|
|
78 #define NGX_HTTP_FASTCGI_RESPONDER 1
|
|
79
|
|
80 #define NGX_HTTP_FASTCGI_BEGIN_REQUEST 1
|
|
81 #define NGX_HTTP_FASTCGI_ABORT_REQUEST 2
|
|
82 #define NGX_HTTP_FASTCGI_END_REQUEST 3
|
|
83 #define NGX_HTTP_FASTCGI_PARAMS 4
|
|
84 #define NGX_HTTP_FASTCGI_STDIN 5
|
|
85 #define NGX_HTTP_FASTCGI_STDOUT 6
|
|
86 #define NGX_HTTP_FASTCGI_STDERR 7
|
|
87 #define NGX_HTTP_FASTCGI_DATA 8
|
|
88
|
|
89
|
|
90 typedef struct {
|
|
91 u_char version;
|
|
92 u_char type;
|
|
93 u_char request_id_hi;
|
|
94 u_char request_id_lo;
|
|
95 u_char content_length_hi;
|
|
96 u_char content_length_lo;
|
|
97 u_char padding_length;
|
|
98 u_char reserved;
|
|
99 } ngx_http_fastcgi_header_t;
|
|
100
|
|
101
|
|
102 typedef struct {
|
|
103 u_char role_hi;
|
|
104 u_char role_lo;
|
|
105 u_char flags;
|
|
106 u_char reserved[5];
|
|
107 } ngx_http_fastcgi_begin_request_t;
|
|
108
|
|
109
|
58
|
110 typedef struct {
|
|
111 u_char version;
|
|
112 u_char type;
|
|
113 u_char request_id_hi;
|
|
114 u_char request_id_lo;
|
|
115 } ngx_http_fastcgi_header_small_t;
|
|
116
|
|
117
|
|
118 typedef struct {
|
|
119 ngx_http_fastcgi_header_t h0;
|
|
120 ngx_http_fastcgi_begin_request_t br;
|
|
121 ngx_http_fastcgi_header_small_t h1;
|
|
122 } ngx_http_fastcgi_request_start_t;
|
|
123
|
|
124
|
430
|
125 static ngx_int_t ngx_http_fastcgi_eval(ngx_http_request_t *r,
|
|
126 ngx_http_fastcgi_loc_conf_t *flcf);
|
466
|
127 #if (NGX_HTTP_CACHE)
|
|
128 static ngx_int_t ngx_http_fastcgi_create_key(ngx_http_request_t *r);
|
|
129 #endif
|
50
|
130 static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r);
|
|
131 static ngx_int_t ngx_http_fastcgi_reinit_request(ngx_http_request_t *r);
|
|
132 static ngx_int_t ngx_http_fastcgi_process_header(ngx_http_request_t *r);
|
|
133 static ngx_int_t ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p,
|
|
134 ngx_buf_t *buf);
|
|
135 static ngx_int_t ngx_http_fastcgi_process_record(ngx_http_request_t *r,
|
|
136 ngx_http_fastcgi_ctx_t *f);
|
|
137 static void ngx_http_fastcgi_abort_request(ngx_http_request_t *r);
|
|
138 static void ngx_http_fastcgi_finalize_request(ngx_http_request_t *r,
|
|
139 ngx_int_t rc);
|
|
140
|
58
|
141 static ngx_int_t ngx_http_fastcgi_add_variables(ngx_conf_t *cf);
|
|
142 static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf);
|
|
143 static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf,
|
|
144 void *parent, void *child);
|
122
|
145 static ngx_int_t ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r,
|
|
146 ngx_http_variable_value_t *v, uintptr_t data);
|
438
|
147 static ngx_int_t ngx_http_fastcgi_path_info_variable(ngx_http_request_t *r,
|
|
148 ngx_http_variable_value_t *v, uintptr_t data);
|
440
|
149 static ngx_http_fastcgi_ctx_t *ngx_http_fastcgi_split(ngx_http_request_t *r,
|
|
150 ngx_http_fastcgi_loc_conf_t *flcf);
|
58
|
151
|
50
|
152 static char *ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
153 void *conf);
|
438
|
154 static char *ngx_http_fastcgi_split_path_info(ngx_conf_t *cf,
|
|
155 ngx_command_t *cmd, void *conf);
|
320
|
156 static char *ngx_http_fastcgi_store(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
157 void *conf);
|
466
|
158 #if (NGX_HTTP_CACHE)
|
|
159 static char *ngx_http_fastcgi_cache(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
160 void *conf);
|
|
161 static char *ngx_http_fastcgi_cache_key(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
162 void *conf);
|
|
163 #endif
|
|
164
|
50
|
165 static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post,
|
|
166 void *data);
|
|
167
|
|
168
|
58
|
169 static ngx_conf_post_t ngx_http_fastcgi_lowat_post =
|
|
170 { ngx_http_fastcgi_lowat_check };
|
50
|
171
|
|
172
|
|
173 static ngx_conf_bitmask_t ngx_http_fastcgi_next_upstream_masks[] = {
|
|
174 { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR },
|
|
175 { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT },
|
|
176 { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER },
|
|
177 { ngx_string("http_500"), NGX_HTTP_UPSTREAM_FT_HTTP_500 },
|
172
|
178 { ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 },
|
50
|
179 { ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 },
|
498
|
180 { ngx_string("updating"), NGX_HTTP_UPSTREAM_FT_UPDATING },
|
214
|
181 { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF },
|
50
|
182 { ngx_null_string, 0 }
|
|
183 };
|
|
184
|
|
185
|
466
|
186 ngx_module_t ngx_http_fastcgi_module;
|
|
187
|
|
188
|
50
|
189 static ngx_command_t ngx_http_fastcgi_commands[] = {
|
|
190
|
|
191 { ngx_string("fastcgi_pass"),
|
178
|
192 NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
|
50
|
193 ngx_http_fastcgi_pass,
|
|
194 NGX_HTTP_LOC_CONF_OFFSET,
|
|
195 0,
|
|
196 NULL },
|
|
197
|
|
198 { ngx_string("fastcgi_index"),
|
|
199 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
200 ngx_conf_set_str_slot,
|
|
201 NGX_HTTP_LOC_CONF_OFFSET,
|
|
202 offsetof(ngx_http_fastcgi_loc_conf_t, index),
|
|
203 NULL },
|
|
204
|
438
|
205 { ngx_string("fastcgi_split_path_info"),
|
|
206 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
207 ngx_http_fastcgi_split_path_info,
|
|
208 NGX_HTTP_LOC_CONF_OFFSET,
|
|
209 0,
|
|
210 NULL },
|
|
211
|
318
|
212 { ngx_string("fastcgi_store"),
|
320
|
213 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
214 ngx_http_fastcgi_store,
|
|
215 NGX_HTTP_LOC_CONF_OFFSET,
|
|
216 0,
|
|
217 NULL },
|
|
218
|
|
219 { ngx_string("fastcgi_store_access"),
|
318
|
220 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123,
|
|
221 ngx_conf_set_access_slot,
|
|
222 NGX_HTTP_LOC_CONF_OFFSET,
|
320
|
223 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.store_access),
|
318
|
224 NULL },
|
|
225
|
178
|
226 { ngx_string("fastcgi_ignore_client_abort"),
|
|
227 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
228 ngx_conf_set_flag_slot,
|
|
229 NGX_HTTP_LOC_CONF_OFFSET,
|
|
230 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.ignore_client_abort),
|
|
231 NULL },
|
|
232
|
540
|
233 { ngx_string("fastcgi_bind"),
|
|
234 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
558
|
235 ngx_http_upstream_bind_set_slot,
|
540
|
236 NGX_HTTP_LOC_CONF_OFFSET,
|
|
237 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.local),
|
|
238 NULL },
|
|
239
|
50
|
240 { ngx_string("fastcgi_connect_timeout"),
|
|
241 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
242 ngx_conf_set_msec_slot,
|
|
243 NGX_HTTP_LOC_CONF_OFFSET,
|
|
244 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.connect_timeout),
|
|
245 NULL },
|
|
246
|
|
247 { ngx_string("fastcgi_send_timeout"),
|
|
248 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
249 ngx_conf_set_msec_slot,
|
|
250 NGX_HTTP_LOC_CONF_OFFSET,
|
|
251 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.send_timeout),
|
|
252 NULL },
|
|
253
|
|
254 { ngx_string("fastcgi_send_lowat"),
|
|
255 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
256 ngx_conf_set_size_slot,
|
|
257 NGX_HTTP_LOC_CONF_OFFSET,
|
|
258 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.send_lowat),
|
|
259 &ngx_http_fastcgi_lowat_post },
|
|
260
|
130
|
261 { ngx_string("fastcgi_buffer_size"),
|
|
262 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
263 ngx_conf_set_size_slot,
|
|
264 NGX_HTTP_LOC_CONF_OFFSET,
|
|
265 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.buffer_size),
|
|
266 NULL },
|
|
267
|
58
|
268 { ngx_string("fastcgi_pass_request_headers"),
|
|
269 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
270 ngx_conf_set_flag_slot,
|
|
271 NGX_HTTP_LOC_CONF_OFFSET,
|
|
272 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.pass_request_headers),
|
|
273 NULL },
|
|
274
|
|
275 { ngx_string("fastcgi_pass_request_body"),
|
|
276 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
277 ngx_conf_set_flag_slot,
|
|
278 NGX_HTTP_LOC_CONF_OFFSET,
|
|
279 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.pass_request_body),
|
|
280 NULL },
|
|
281
|
206
|
282 { ngx_string("fastcgi_intercept_errors"),
|
|
283 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
284 ngx_conf_set_flag_slot,
|
|
285 NGX_HTTP_LOC_CONF_OFFSET,
|
|
286 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.intercept_errors),
|
|
287 NULL },
|
|
288
|
50
|
289 { ngx_string("fastcgi_read_timeout"),
|
|
290 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
291 ngx_conf_set_msec_slot,
|
|
292 NGX_HTTP_LOC_CONF_OFFSET,
|
|
293 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.read_timeout),
|
|
294 NULL },
|
|
295
|
|
296 { ngx_string("fastcgi_buffers"),
|
|
297 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
|
|
298 ngx_conf_set_bufs_slot,
|
|
299 NGX_HTTP_LOC_CONF_OFFSET,
|
|
300 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.bufs),
|
|
301 NULL },
|
|
302
|
|
303 { ngx_string("fastcgi_busy_buffers_size"),
|
|
304 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
305 ngx_conf_set_size_slot,
|
|
306 NGX_HTTP_LOC_CONF_OFFSET,
|
78
|
307 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.busy_buffers_size_conf),
|
50
|
308 NULL },
|
|
309
|
466
|
310 #if (NGX_HTTP_CACHE)
|
|
311
|
|
312 { ngx_string("fastcgi_cache"),
|
592
|
313 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
466
|
314 ngx_http_fastcgi_cache,
|
|
315 NGX_HTTP_LOC_CONF_OFFSET,
|
|
316 0,
|
|
317 NULL },
|
|
318
|
|
319 { ngx_string("fastcgi_cache_key"),
|
592
|
320 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
466
|
321 ngx_http_fastcgi_cache_key,
|
|
322 NGX_HTTP_LOC_CONF_OFFSET,
|
|
323 0,
|
|
324 NULL },
|
|
325
|
|
326 { ngx_string("fastcgi_cache_path"),
|
|
327 NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE,
|
|
328 ngx_http_file_cache_set_slot,
|
|
329 0,
|
|
330 0,
|
|
331 &ngx_http_fastcgi_module },
|
|
332
|
588
|
333 { ngx_string("fastcgi_cache_bypass"),
|
|
334 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
335 ngx_http_set_predicate_slot,
|
|
336 NGX_HTTP_LOC_CONF_OFFSET,
|
|
337 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.cache_bypass),
|
|
338 NULL },
|
|
339
|
572
|
340 { ngx_string("fastcgi_no_cache"),
|
|
341 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
588
|
342 ngx_http_set_predicate_slot,
|
572
|
343 NGX_HTTP_LOC_CONF_OFFSET,
|
|
344 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.no_cache),
|
|
345 NULL },
|
|
346
|
466
|
347 { ngx_string("fastcgi_cache_valid"),
|
|
348 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
349 ngx_http_file_cache_valid_set_slot,
|
|
350 NGX_HTTP_LOC_CONF_OFFSET,
|
|
351 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.cache_valid),
|
|
352 NULL },
|
|
353
|
482
|
354 { ngx_string("fastcgi_cache_min_uses"),
|
466
|
355 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
356 ngx_conf_set_num_slot,
|
|
357 NGX_HTTP_LOC_CONF_OFFSET,
|
|
358 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.cache_min_uses),
|
|
359 NULL },
|
|
360
|
|
361 { ngx_string("fastcgi_cache_use_stale"),
|
|
362 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
363 ngx_conf_set_bitmask_slot,
|
|
364 NGX_HTTP_LOC_CONF_OFFSET,
|
|
365 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.cache_use_stale),
|
|
366 &ngx_http_fastcgi_next_upstream_masks },
|
|
367
|
494
|
368 { ngx_string("fastcgi_cache_methods"),
|
|
369 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
370 ngx_conf_set_bitmask_slot,
|
|
371 NGX_HTTP_LOC_CONF_OFFSET,
|
|
372 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.cache_methods),
|
|
373 &ngx_http_upstream_cache_method_mask },
|
|
374
|
466
|
375 #endif
|
|
376
|
50
|
377 { ngx_string("fastcgi_temp_path"),
|
|
378 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
|
|
379 ngx_conf_set_path_slot,
|
|
380 NGX_HTTP_LOC_CONF_OFFSET,
|
|
381 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.temp_path),
|
464
|
382 NULL },
|
50
|
383
|
|
384 { ngx_string("fastcgi_max_temp_file_size"),
|
|
385 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
386 ngx_conf_set_size_slot,
|
|
387 NGX_HTTP_LOC_CONF_OFFSET,
|
78
|
388 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.max_temp_file_size_conf),
|
50
|
389 NULL },
|
|
390
|
|
391 { ngx_string("fastcgi_temp_file_write_size"),
|
|
392 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
393 ngx_conf_set_size_slot,
|
|
394 NGX_HTTP_LOC_CONF_OFFSET,
|
78
|
395 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.temp_file_write_size_conf),
|
50
|
396 NULL },
|
|
397
|
|
398 { ngx_string("fastcgi_next_upstream"),
|
96
|
399 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
50
|
400 ngx_conf_set_bitmask_slot,
|
|
401 NGX_HTTP_LOC_CONF_OFFSET,
|
|
402 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.next_upstream),
|
|
403 &ngx_http_fastcgi_next_upstream_masks },
|
|
404
|
58
|
405 { ngx_string("fastcgi_param"),
|
|
406 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
|
198
|
407 ngx_conf_set_keyval_slot,
|
50
|
408 NGX_HTTP_LOC_CONF_OFFSET,
|
58
|
409 offsetof(ngx_http_fastcgi_loc_conf_t, params_source),
|
50
|
410 NULL },
|
|
411
|
198
|
412 { ngx_string("fastcgi_pass_header"),
|
592
|
413 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
198
|
414 ngx_conf_set_str_array_slot,
|
|
415 NGX_HTTP_LOC_CONF_OFFSET,
|
|
416 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.pass_headers),
|
|
417 NULL },
|
|
418
|
|
419 { ngx_string("fastcgi_hide_header"),
|
592
|
420 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
198
|
421 ngx_conf_set_str_array_slot,
|
|
422 NGX_HTTP_LOC_CONF_OFFSET,
|
|
423 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.hide_headers),
|
|
424 NULL },
|
|
425
|
484
|
426 { ngx_string("fastcgi_ignore_headers"),
|
|
427 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
428 ngx_conf_set_bitmask_slot,
|
|
429 NGX_HTTP_LOC_CONF_OFFSET,
|
|
430 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.ignore_headers),
|
584
|
431 &ngx_http_upstream_ignore_headers_masks },
|
484
|
432
|
306
|
433 { ngx_string("fastcgi_catch_stderr"),
|
|
434 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
435 ngx_conf_set_str_array_slot,
|
|
436 NGX_HTTP_LOC_CONF_OFFSET,
|
|
437 offsetof(ngx_http_fastcgi_loc_conf_t, catch_stderr),
|
|
438 NULL },
|
|
439
|
50
|
440 ngx_null_command
|
|
441 };
|
|
442
|
|
443
|
216
|
444 static ngx_http_module_t ngx_http_fastcgi_module_ctx = {
|
58
|
445 ngx_http_fastcgi_add_variables, /* preconfiguration */
|
|
446 NULL, /* postconfiguration */
|
50
|
447
|
|
448 NULL, /* create main configuration */
|
|
449 NULL, /* init main configuration */
|
|
450
|
|
451 NULL, /* create server configuration */
|
|
452 NULL, /* merge server configuration */
|
|
453
|
|
454 ngx_http_fastcgi_create_loc_conf, /* create location configuration */
|
|
455 ngx_http_fastcgi_merge_loc_conf /* merge location configuration */
|
|
456 };
|
|
457
|
|
458
|
|
459 ngx_module_t ngx_http_fastcgi_module = {
|
58
|
460 NGX_MODULE_V1,
|
50
|
461 &ngx_http_fastcgi_module_ctx, /* module context */
|
|
462 ngx_http_fastcgi_commands, /* module directives */
|
|
463 NGX_HTTP_MODULE, /* module type */
|
90
|
464 NULL, /* init master */
|
50
|
465 NULL, /* init module */
|
90
|
466 NULL, /* init process */
|
|
467 NULL, /* init thread */
|
|
468 NULL, /* exit thread */
|
|
469 NULL, /* exit process */
|
|
470 NULL, /* exit master */
|
|
471 NGX_MODULE_V1_PADDING
|
50
|
472 };
|
|
473
|
|
474
|
364
|
475 static ngx_http_fastcgi_request_start_t ngx_http_fastcgi_request_start = {
|
|
476 { 1, /* version */
|
|
477 NGX_HTTP_FASTCGI_BEGIN_REQUEST, /* type */
|
|
478 0, /* request_id_hi */
|
|
479 1, /* request_id_lo */
|
|
480 0, /* content_length_hi */
|
|
481 sizeof(ngx_http_fastcgi_begin_request_t), /* content_length_lo */
|
|
482 0, /* padding_length */
|
|
483 0 }, /* reserved */
|
|
484
|
|
485 { 0, /* role_hi */
|
|
486 NGX_HTTP_FASTCGI_RESPONDER, /* role_lo */
|
|
487 0, /* NGX_HTTP_FASTCGI_KEEP_CONN */ /* flags */
|
|
488 { 0, 0, 0, 0, 0 } }, /* reserved[5] */
|
|
489
|
|
490 { 1, /* version */
|
|
491 NGX_HTTP_FASTCGI_PARAMS, /* type */
|
|
492 0, /* request_id_hi */
|
|
493 1 }, /* request_id_lo */
|
|
494
|
|
495 };
|
|
496
|
|
497
|
438
|
498 static ngx_http_variable_t ngx_http_fastcgi_vars[] = {
|
|
499
|
|
500 { ngx_string("fastcgi_script_name"), NULL,
|
|
501 ngx_http_fastcgi_script_name_variable, 0,
|
|
502 NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
|
|
503
|
|
504 { ngx_string("fastcgi_path_info"), NULL,
|
|
505 ngx_http_fastcgi_path_info_variable, 0,
|
|
506 NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
|
|
507
|
|
508 { ngx_null_string, NULL, NULL, 0, 0, 0 }
|
|
509 };
|
364
|
510
|
|
511
|
198
|
512 static ngx_str_t ngx_http_fastcgi_hide_headers[] = {
|
|
513 ngx_string("Status"),
|
|
514 ngx_string("X-Accel-Expires"),
|
|
515 ngx_string("X-Accel-Redirect"),
|
|
516 ngx_string("X-Accel-Limit-Rate"),
|
364
|
517 ngx_string("X-Accel-Buffering"),
|
|
518 ngx_string("X-Accel-Charset"),
|
198
|
519 ngx_null_string
|
|
520 };
|
|
521
|
|
522
|
536
|
523 #if (NGX_HTTP_CACHE)
|
|
524
|
576
|
525 static ngx_keyval_t ngx_http_fastcgi_cache_headers[] = {
|
|
526 { ngx_string("HTTP_IF_MODIFIED_SINCE"), ngx_string("") },
|
|
527 { ngx_string("HTTP_IF_UNMODIFIED_SINCE"), ngx_string("") },
|
|
528 { ngx_string("HTTP_IF_NONE_MATCH"), ngx_string("") },
|
|
529 { ngx_string("HTTP_IF_MATCH"), ngx_string("") },
|
|
530 { ngx_string("HTTP_RANGE"), ngx_string("") },
|
|
531 { ngx_string("HTTP_IF_RANGE"), ngx_string("") },
|
|
532 { ngx_null_string, ngx_null_string }
|
|
533 };
|
|
534
|
536
|
535 #endif
|
|
536
|
|
537
|
464
|
538 static ngx_path_init_t ngx_http_fastcgi_temp_path = {
|
|
539 ngx_string(NGX_HTTP_FASTCGI_TEMP_PATH), { 1, 2, 0 }
|
|
540 };
|
|
541
|
|
542
|
50
|
543 static ngx_int_t
|
|
544 ngx_http_fastcgi_handler(ngx_http_request_t *r)
|
|
545 {
|
|
546 ngx_int_t rc;
|
|
547 ngx_http_upstream_t *u;
|
438
|
548 ngx_http_fastcgi_ctx_t *f;
|
50
|
549 ngx_http_fastcgi_loc_conf_t *flcf;
|
|
550
|
248
|
551 if (r->subrequest_in_memory) {
|
|
552 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
|
553 "ngx_http_fastcgi_module does not support "
|
346
|
554 "subrequest in memory");
|
248
|
555 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
556 }
|
|
557
|
510
|
558 if (ngx_http_upstream_create(r) != NGX_OK) {
|
|
559 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
560 }
|
|
561
|
438
|
562 f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t));
|
|
563 if (f == NULL) {
|
510
|
564 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
438
|
565 }
|
|
566
|
|
567 ngx_http_set_ctx(r, f, ngx_http_fastcgi_module);
|
50
|
568
|
430
|
569 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
|
|
570
|
|
571 if (flcf->fastcgi_lengths) {
|
|
572 if (ngx_http_fastcgi_eval(r, flcf) != NGX_OK) {
|
|
573 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
574 }
|
|
575 }
|
|
576
|
510
|
577 u = r->upstream;
|
|
578
|
570
|
579 ngx_str_set(&u->schema, "fastcgi://");
|
50
|
580 u->output.tag = (ngx_buf_tag_t) &ngx_http_fastcgi_module;
|
|
581
|
|
582 u->conf = &flcf->upstream;
|
|
583
|
466
|
584 #if (NGX_HTTP_CACHE)
|
|
585 u->create_key = ngx_http_fastcgi_create_key;
|
|
586 #endif
|
50
|
587 u->create_request = ngx_http_fastcgi_create_request;
|
|
588 u->reinit_request = ngx_http_fastcgi_reinit_request;
|
|
589 u->process_header = ngx_http_fastcgi_process_header;
|
|
590 u->abort_request = ngx_http_fastcgi_abort_request;
|
|
591 u->finalize_request = ngx_http_fastcgi_finalize_request;
|
|
592
|
198
|
593 u->buffering = 1;
|
|
594
|
130
|
595 u->pipe = ngx_pcalloc(r->pool, sizeof(ngx_event_pipe_t));
|
|
596 if (u->pipe == NULL) {
|
|
597 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
598 }
|
|
599
|
|
600 u->pipe->input_filter = ngx_http_fastcgi_input_filter;
|
|
601 u->pipe->input_ctx = r;
|
50
|
602
|
|
603 rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init);
|
|
604
|
|
605 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
|
|
606 return rc;
|
|
607 }
|
|
608
|
|
609 return NGX_DONE;
|
|
610 }
|
|
611
|
|
612
|
|
613 static ngx_int_t
|
430
|
614 ngx_http_fastcgi_eval(ngx_http_request_t *r, ngx_http_fastcgi_loc_conf_t *flcf)
|
|
615 {
|
578
|
616 ngx_url_t url;
|
|
617 ngx_http_upstream_t *u;
|
|
618
|
|
619 ngx_memzero(&url, sizeof(ngx_url_t));
|
|
620
|
|
621 if (ngx_http_script_run(r, &url.url, flcf->fastcgi_lengths->elts, 0,
|
430
|
622 flcf->fastcgi_values->elts)
|
|
623 == NULL)
|
|
624 {
|
|
625 return NGX_ERROR;
|
|
626 }
|
|
627
|
578
|
628 url.no_resolve = 1;
|
|
629
|
|
630 if (ngx_parse_url(r->pool, &url) != NGX_OK) {
|
|
631 if (url.err) {
|
430
|
632 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
578
|
633 "%s in upstream \"%V\"", url.err, &url.url);
|
430
|
634 }
|
|
635
|
|
636 return NGX_ERROR;
|
|
637 }
|
|
638
|
578
|
639 if (url.no_port) {
|
430
|
640 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
578
|
641 "no port in upstream \"%V\"", &url.url);
|
430
|
642 return NGX_ERROR;
|
|
643 }
|
|
644
|
578
|
645 u = r->upstream;
|
|
646
|
|
647 u->resolved = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_resolved_t));
|
|
648 if (u->resolved == NULL) {
|
|
649 return NGX_ERROR;
|
|
650 }
|
|
651
|
|
652 if (url.addrs && url.addrs[0].sockaddr) {
|
|
653 u->resolved->sockaddr = url.addrs[0].sockaddr;
|
|
654 u->resolved->socklen = url.addrs[0].socklen;
|
|
655 u->resolved->naddrs = 1;
|
|
656 u->resolved->host = url.addrs[0].name;
|
434
|
657
|
|
658 } else {
|
578
|
659 u->resolved->host = url.host;
|
|
660 u->resolved->port = url.port;
|
434
|
661 }
|
430
|
662
|
|
663 return NGX_OK;
|
|
664 }
|
|
665
|
|
666
|
466
|
667 #if (NGX_HTTP_CACHE)
|
|
668
|
|
669 static ngx_int_t
|
|
670 ngx_http_fastcgi_create_key(ngx_http_request_t *r)
|
|
671 {
|
|
672 ngx_str_t *key;
|
|
673 ngx_http_fastcgi_loc_conf_t *flcf;
|
|
674
|
|
675 key = ngx_array_push(&r->cache->keys);
|
|
676 if (key == NULL) {
|
|
677 return NGX_ERROR;
|
|
678 }
|
|
679
|
|
680 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
|
|
681
|
|
682 if (ngx_http_complex_value(r, &flcf->cache_key, key) != NGX_OK) {
|
|
683 return NGX_ERROR;
|
|
684 }
|
|
685
|
|
686 return NGX_OK;
|
|
687 }
|
|
688
|
|
689 #endif
|
|
690
|
|
691
|
430
|
692 static ngx_int_t
|
50
|
693 ngx_http_fastcgi_create_request(ngx_http_request_t *r)
|
|
694 {
|
58
|
695 off_t file_pos;
|
576
|
696 u_char ch, *pos, *lowcase_key;
|
|
697 size_t size, len, key_len, val_len, padding,
|
|
698 allocated;
|
|
699 ngx_uint_t i, n, next, hash, header_params;
|
58
|
700 ngx_buf_t *b;
|
|
701 ngx_chain_t *cl, *body;
|
|
702 ngx_list_part_t *part;
|
576
|
703 ngx_table_elt_t *header, **ignored;
|
58
|
704 ngx_http_script_code_pt code;
|
|
705 ngx_http_script_engine_t e, le;
|
|
706 ngx_http_fastcgi_header_t *h;
|
|
707 ngx_http_fastcgi_loc_conf_t *flcf;
|
|
708 ngx_http_script_len_code_pt lcode;
|
50
|
709
|
58
|
710 len = 0;
|
576
|
711 header_params = 0;
|
|
712 ignored = NULL;
|
50
|
713
|
|
714 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
|
|
715
|
58
|
716 if (flcf->params_len) {
|
|
717 ngx_memzero(&le, sizeof(ngx_http_script_engine_t));
|
50
|
718
|
340
|
719 ngx_http_script_flush_no_cacheable_variables(r, flcf->flushes);
|
122
|
720 le.flushed = 1;
|
|
721
|
58
|
722 le.ip = flcf->params_len->elts;
|
|
723 le.request = r;
|
50
|
724
|
58
|
725 while (*(uintptr_t *) le.ip) {
|
50
|
726
|
58
|
727 lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
|
728 key_len = lcode(&le);
|
50
|
729
|
58
|
730 for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode(&le)) {
|
|
731 lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
|
732 }
|
|
733 le.ip += sizeof(uintptr_t);
|
50
|
734
|
86
|
735 len += 1 + key_len + ((val_len > 127) ? 4 : 1) + val_len;
|
50
|
736 }
|
|
737 }
|
|
738
|
58
|
739 if (flcf->upstream.pass_request_headers) {
|
50
|
740
|
576
|
741 allocated = 0;
|
|
742 lowcase_key = NULL;
|
|
743
|
|
744 if (flcf->header_params) {
|
|
745 ignored = ngx_palloc(r->pool, flcf->header_params * sizeof(void *));
|
|
746 if (ignored == NULL) {
|
|
747 return NGX_ERROR;
|
|
748 }
|
|
749 }
|
|
750
|
58
|
751 part = &r->headers_in.headers.part;
|
|
752 header = part->elts;
|
|
753
|
|
754 for (i = 0; /* void */; i++) {
|
50
|
755
|
58
|
756 if (i >= part->nelts) {
|
|
757 if (part->next == NULL) {
|
|
758 break;
|
|
759 }
|
50
|
760
|
58
|
761 part = part->next;
|
|
762 header = part->elts;
|
|
763 i = 0;
|
50
|
764 }
|
|
765
|
576
|
766 if (flcf->header_params) {
|
|
767 if (allocated < header[i].key.len) {
|
|
768 allocated = header[i].key.len + 16;
|
|
769 lowcase_key = ngx_pnalloc(r->pool, allocated);
|
|
770 if (lowcase_key == NULL) {
|
|
771 return NGX_ERROR;
|
|
772 }
|
|
773 }
|
|
774
|
|
775 hash = 0;
|
|
776
|
|
777 for (n = 0; n < header[i].key.len; n++) {
|
|
778 ch = header[i].key.data[n];
|
|
779
|
|
780 if (ch >= 'A' && ch <= 'Z') {
|
|
781 ch |= 0x20;
|
|
782
|
|
783 } else if (ch == '-') {
|
|
784 ch = '_';
|
|
785 }
|
|
786
|
|
787 hash = ngx_hash(hash, ch);
|
|
788 lowcase_key[n] = ch;
|
|
789 }
|
|
790
|
|
791 if (ngx_hash_find(&flcf->headers_hash, hash, lowcase_key, n)) {
|
|
792 ignored[header_params++] = &header[i];
|
|
793 continue;
|
|
794 }
|
|
795
|
|
796 n += sizeof("HTTP_") - 1;
|
|
797
|
|
798 } else {
|
|
799 n = sizeof("HTTP_") - 1 + header[i].key.len;
|
|
800 }
|
|
801
|
|
802 len += ((n > 127) ? 4 : 1) + ((header[i].value.len > 127) ? 4 : 1)
|
|
803 + n + header[i].value.len;
|
50
|
804 }
|
|
805 }
|
|
806
|
|
807
|
|
808 if (len > 65535) {
|
|
809 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
354
|
810 "fastcgi request record is too big: %uz", len);
|
50
|
811 return NGX_ERROR;
|
|
812 }
|
|
813
|
|
814
|
|
815 padding = 8 - len % 8;
|
|
816 padding = (padding == 8) ? 0 : padding;
|
|
817
|
|
818
|
|
819 size = sizeof(ngx_http_fastcgi_header_t)
|
|
820 + sizeof(ngx_http_fastcgi_begin_request_t)
|
|
821
|
|
822 + sizeof(ngx_http_fastcgi_header_t) /* NGX_HTTP_FASTCGI_PARAMS */
|
|
823 + len + padding
|
|
824 + sizeof(ngx_http_fastcgi_header_t) /* NGX_HTTP_FASTCGI_PARAMS */
|
|
825
|
|
826 + sizeof(ngx_http_fastcgi_header_t); /* NGX_HTTP_FASTCGI_STDIN */
|
|
827
|
|
828
|
|
829 b = ngx_create_temp_buf(r->pool, size);
|
|
830 if (b == NULL) {
|
|
831 return NGX_ERROR;
|
|
832 }
|
|
833
|
|
834 cl = ngx_alloc_chain_link(r->pool);
|
|
835 if (cl == NULL) {
|
|
836 return NGX_ERROR;
|
|
837 }
|
|
838
|
|
839 cl->buf = b;
|
|
840
|
58
|
841 ngx_memcpy(b->pos, &ngx_http_fastcgi_request_start,
|
|
842 sizeof(ngx_http_fastcgi_request_start_t));
|
50
|
843
|
|
844 h = (ngx_http_fastcgi_header_t *)
|
|
845 (b->pos + sizeof(ngx_http_fastcgi_header_t)
|
|
846 + sizeof(ngx_http_fastcgi_begin_request_t));
|
|
847
|
|
848 h->content_length_hi = (u_char) ((len >> 8) & 0xff);
|
|
849 h->content_length_lo = (u_char) (len & 0xff);
|
|
850 h->padding_length = (u_char) padding;
|
|
851 h->reserved = 0;
|
|
852
|
|
853 b->last = b->pos + sizeof(ngx_http_fastcgi_header_t)
|
|
854 + sizeof(ngx_http_fastcgi_begin_request_t)
|
|
855 + sizeof(ngx_http_fastcgi_header_t);
|
|
856
|
|
857
|
58
|
858 if (flcf->params_len) {
|
|
859 ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
|
50
|
860
|
58
|
861 e.ip = flcf->params->elts;
|
|
862 e.pos = b->last;
|
|
863 e.request = r;
|
122
|
864 e.flushed = 1;
|
50
|
865
|
58
|
866 le.ip = flcf->params_len->elts;
|
50
|
867
|
58
|
868 while (*(uintptr_t *) le.ip) {
|
50
|
869
|
58
|
870 lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
|
871 key_len = (u_char) lcode(&le);
|
50
|
872
|
58
|
873 for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode(&le)) {
|
|
874 lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
|
875 }
|
|
876 le.ip += sizeof(uintptr_t);
|
50
|
877
|
86
|
878 *e.pos++ = (u_char) key_len;
|
50
|
879
|
86
|
880 if (val_len > 127) {
|
|
881 *e.pos++ = (u_char) (((val_len >> 24) & 0x7f) | 0x80);
|
|
882 *e.pos++ = (u_char) ((val_len >> 16) & 0xff);
|
|
883 *e.pos++ = (u_char) ((val_len >> 8) & 0xff);
|
|
884 *e.pos++ = (u_char) (val_len & 0xff);
|
50
|
885
|
86
|
886 } else {
|
|
887 *e.pos++ = (u_char) val_len;
|
58
|
888 }
|
50
|
889
|
58
|
890 while (*(uintptr_t *) e.ip) {
|
|
891 code = *(ngx_http_script_code_pt *) e.ip;
|
|
892 code((ngx_http_script_engine_t *) &e);
|
|
893 }
|
|
894 e.ip += sizeof(uintptr_t);
|
370
|
895
|
|
896 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
897 "fastcgi param: \"%*s: %*s\"",
|
|
898 key_len, e.pos - (key_len + val_len),
|
|
899 val_len, e.pos - val_len);
|
50
|
900 }
|
|
901
|
58
|
902 b->last = e.pos;
|
50
|
903 }
|
|
904
|
|
905
|
58
|
906 if (flcf->upstream.pass_request_headers) {
|
50
|
907
|
58
|
908 part = &r->headers_in.headers.part;
|
|
909 header = part->elts;
|
50
|
910
|
58
|
911 for (i = 0; /* void */; i++) {
|
50
|
912
|
58
|
913 if (i >= part->nelts) {
|
|
914 if (part->next == NULL) {
|
126
|
915 break;
|
58
|
916 }
|
126
|
917
|
58
|
918 part = part->next;
|
|
919 header = part->elts;
|
|
920 i = 0;
|
|
921 }
|
50
|
922
|
576
|
923 for (n = 0; n < header_params; n++) {
|
|
924 if (&header[i] == ignored[n]) {
|
|
925 goto next;
|
|
926 }
|
|
927 }
|
|
928
|
|
929 key_len = sizeof("HTTP_") - 1 + header[i].key.len;
|
|
930 if (key_len > 127) {
|
|
931 *b->last++ = (u_char) (((key_len >> 24) & 0x7f) | 0x80);
|
|
932 *b->last++ = (u_char) ((key_len >> 16) & 0xff);
|
|
933 *b->last++ = (u_char) ((key_len >> 8) & 0xff);
|
|
934 *b->last++ = (u_char) (key_len & 0xff);
|
126
|
935
|
58
|
936 } else {
|
576
|
937 *b->last++ = (u_char) key_len;
|
50
|
938 }
|
|
939
|
576
|
940 val_len = header[i].value.len;
|
|
941 if (val_len > 127) {
|
|
942 *b->last++ = (u_char) (((val_len >> 24) & 0x7f) | 0x80);
|
|
943 *b->last++ = (u_char) ((val_len >> 16) & 0xff);
|
|
944 *b->last++ = (u_char) ((val_len >> 8) & 0xff);
|
|
945 *b->last++ = (u_char) (val_len & 0xff);
|
50
|
946
|
58
|
947 } else {
|
576
|
948 *b->last++ = (u_char) val_len;
|
50
|
949 }
|
|
950
|
58
|
951 b->last = ngx_cpymem(b->last, "HTTP_", sizeof("HTTP_") - 1);
|
50
|
952
|
58
|
953 for (n = 0; n < header[i].key.len; n++) {
|
|
954 ch = header[i].key.data[n];
|
50
|
955
|
58
|
956 if (ch >= 'a' && ch <= 'z') {
|
|
957 ch &= ~0x20;
|
50
|
958
|
58
|
959 } else if (ch == '-') {
|
|
960 ch = '_';
|
|
961 }
|
50
|
962
|
58
|
963 *b->last++ = ch;
|
50
|
964 }
|
|
965
|
576
|
966 b->last = ngx_copy(b->last, header[i].value.data, val_len);
|
|
967
|
|
968 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
969 "fastcgi param: \"%*s: %*s\"",
|
|
970 key_len, b->last - (key_len + val_len),
|
|
971 val_len, b->last - val_len);
|
|
972 next:
|
|
973
|
|
974 continue;
|
50
|
975 }
|
|
976 }
|
|
977
|
|
978
|
|
979 if (padding) {
|
|
980 ngx_memzero(b->last, padding);
|
|
981 b->last += padding;
|
|
982 }
|
|
983
|
|
984
|
|
985 h = (ngx_http_fastcgi_header_t *) b->last;
|
|
986 b->last += sizeof(ngx_http_fastcgi_header_t);
|
|
987
|
|
988 h->version = 1;
|
|
989 h->type = NGX_HTTP_FASTCGI_PARAMS;
|
|
990 h->request_id_hi = 0;
|
|
991 h->request_id_lo = 1;
|
|
992 h->content_length_hi = 0;
|
|
993 h->content_length_lo = 0;
|
|
994 h->padding_length = 0;
|
|
995 h->reserved = 0;
|
|
996
|
|
997 h = (ngx_http_fastcgi_header_t *) b->last;
|
|
998 b->last += sizeof(ngx_http_fastcgi_header_t);
|
|
999
|
58
|
1000 if (flcf->upstream.pass_request_body) {
|
|
1001 body = r->upstream->request_bufs;
|
|
1002 r->upstream->request_bufs = cl;
|
50
|
1003
|
|
1004 #if (NGX_SUPPRESS_WARN)
|
58
|
1005 file_pos = 0;
|
|
1006 pos = NULL;
|
50
|
1007 #endif
|
|
1008
|
58
|
1009 while (body) {
|
50
|
1010
|
58
|
1011 if (body->buf->in_file) {
|
|
1012 file_pos = body->buf->file_pos;
|
50
|
1013
|
58
|
1014 } else {
|
|
1015 pos = body->buf->pos;
|
50
|
1016 }
|
|
1017
|
58
|
1018 next = 0;
|
50
|
1019
|
58
|
1020 do {
|
|
1021 b = ngx_alloc_buf(r->pool);
|
|
1022 if (b == NULL) {
|
|
1023 return NGX_ERROR;
|
50
|
1024 }
|
|
1025
|
58
|
1026 ngx_memcpy(b, body->buf, sizeof(ngx_buf_t));
|
|
1027
|
|
1028 if (body->buf->in_file) {
|
|
1029 b->file_pos = file_pos;
|
|
1030 file_pos += 32 * 1024;
|
50
|
1031
|
292
|
1032 if (file_pos >= body->buf->file_last) {
|
58
|
1033 file_pos = body->buf->file_last;
|
|
1034 next = 1;
|
|
1035 }
|
|
1036
|
|
1037 b->file_last = file_pos;
|
|
1038 len = (ngx_uint_t) (file_pos - b->file_pos);
|
|
1039
|
|
1040 } else {
|
|
1041 b->pos = pos;
|
|
1042 pos += 32 * 1024;
|
50
|
1043
|
292
|
1044 if (pos >= body->buf->last) {
|
58
|
1045 pos = body->buf->last;
|
|
1046 next = 1;
|
|
1047 }
|
|
1048
|
|
1049 b->last = pos;
|
|
1050 len = (ngx_uint_t) (pos - b->pos);
|
|
1051 }
|
50
|
1052
|
58
|
1053 padding = 8 - len % 8;
|
|
1054 padding = (padding == 8) ? 0 : padding;
|
50
|
1055
|
58
|
1056 h->version = 1;
|
|
1057 h->type = NGX_HTTP_FASTCGI_STDIN;
|
|
1058 h->request_id_hi = 0;
|
|
1059 h->request_id_lo = 1;
|
|
1060 h->content_length_hi = (u_char) ((len >> 8) & 0xff);
|
|
1061 h->content_length_lo = (u_char) (len & 0xff);
|
|
1062 h->padding_length = (u_char) padding;
|
|
1063 h->reserved = 0;
|
50
|
1064
|
58
|
1065 cl->next = ngx_alloc_chain_link(r->pool);
|
|
1066 if (cl->next == NULL) {
|
|
1067 return NGX_ERROR;
|
|
1068 }
|
50
|
1069
|
58
|
1070 cl = cl->next;
|
|
1071 cl->buf = b;
|
|
1072
|
|
1073 b = ngx_create_temp_buf(r->pool,
|
|
1074 sizeof(ngx_http_fastcgi_header_t)
|
|
1075 + padding);
|
|
1076 if (b == NULL) {
|
|
1077 return NGX_ERROR;
|
|
1078 }
|
50
|
1079
|
58
|
1080 if (padding) {
|
|
1081 ngx_memzero(b->last, padding);
|
|
1082 b->last += padding;
|
|
1083 }
|
|
1084
|
|
1085 h = (ngx_http_fastcgi_header_t *) b->last;
|
|
1086 b->last += sizeof(ngx_http_fastcgi_header_t);
|
50
|
1087
|
58
|
1088 cl->next = ngx_alloc_chain_link(r->pool);
|
|
1089 if (cl->next == NULL) {
|
|
1090 return NGX_ERROR;
|
|
1091 }
|
|
1092
|
|
1093 cl = cl->next;
|
|
1094 cl->buf = b;
|
50
|
1095
|
58
|
1096 } while (!next);
|
50
|
1097
|
58
|
1098 body = body->next;
|
|
1099 }
|
50
|
1100
|
58
|
1101 } else {
|
|
1102 r->upstream->request_bufs = cl;
|
50
|
1103 }
|
|
1104
|
|
1105 h->version = 1;
|
|
1106 h->type = NGX_HTTP_FASTCGI_STDIN;
|
|
1107 h->request_id_hi = 0;
|
|
1108 h->request_id_lo = 1;
|
|
1109 h->content_length_hi = 0;
|
|
1110 h->content_length_lo = 0;
|
|
1111 h->padding_length = 0;
|
|
1112 h->reserved = 0;
|
|
1113
|
|
1114 cl->next = NULL;
|
|
1115
|
|
1116 return NGX_OK;
|
|
1117 }
|
|
1118
|
|
1119
|
|
1120 static ngx_int_t
|
|
1121 ngx_http_fastcgi_reinit_request(ngx_http_request_t *r)
|
|
1122 {
|
|
1123 ngx_http_fastcgi_ctx_t *f;
|
|
1124
|
|
1125 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
|
|
1126
|
|
1127 if (f == NULL) {
|
|
1128 return NGX_OK;
|
|
1129 }
|
|
1130
|
|
1131 f->state = ngx_http_fastcgi_st_version;
|
164
|
1132 f->fastcgi_stdout = 0;
|
564
|
1133 f->large_stderr = 0;
|
50
|
1134
|
|
1135 return NGX_OK;
|
|
1136 }
|
|
1137
|
|
1138
|
56
|
1139 static ngx_int_t
|
|
1140 ngx_http_fastcgi_process_header(ngx_http_request_t *r)
|
50
|
1141 {
|
514
|
1142 u_char *p, *msg, *start, *last,
|
|
1143 *part_start, *part_end;
|
316
|
1144 size_t size;
|
514
|
1145 ngx_str_t *status_line, *pattern;
|
58
|
1146 ngx_int_t rc, status;
|
316
|
1147 ngx_buf_t buf;
|
198
|
1148 ngx_uint_t i;
|
58
|
1149 ngx_table_elt_t *h;
|
|
1150 ngx_http_upstream_t *u;
|
|
1151 ngx_http_fastcgi_ctx_t *f;
|
|
1152 ngx_http_upstream_header_t *hh;
|
306
|
1153 ngx_http_fastcgi_loc_conf_t *flcf;
|
316
|
1154 ngx_http_fastcgi_split_part_t *part;
|
58
|
1155 ngx_http_upstream_main_conf_t *umcf;
|
50
|
1156
|
|
1157 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
|
|
1158
|
58
|
1159 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);
|
|
1160
|
50
|
1161 u = r->upstream;
|
|
1162
|
|
1163 for ( ;; ) {
|
|
1164
|
|
1165 if (f->state < ngx_http_fastcgi_st_data) {
|
|
1166
|
130
|
1167 f->pos = u->buffer.pos;
|
|
1168 f->last = u->buffer.last;
|
50
|
1169
|
|
1170 rc = ngx_http_fastcgi_process_record(r, f);
|
|
1171
|
130
|
1172 u->buffer.pos = f->pos;
|
|
1173 u->buffer.last = f->last;
|
50
|
1174
|
|
1175 if (rc == NGX_AGAIN) {
|
|
1176 return NGX_AGAIN;
|
|
1177 }
|
|
1178
|
|
1179 if (rc == NGX_ERROR) {
|
|
1180 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
|
1181 }
|
|
1182
|
|
1183 if (f->type != NGX_HTTP_FASTCGI_STDOUT
|
|
1184 && f->type != NGX_HTTP_FASTCGI_STDERR)
|
|
1185 {
|
|
1186 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1187 "upstream sent unexpected FastCGI record: %d",
|
|
1188 f->type);
|
|
1189
|
|
1190 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
|
1191 }
|
|
1192
|
|
1193 if (f->type == NGX_HTTP_FASTCGI_STDOUT && f->length == 0) {
|
|
1194 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1195 "upstream closed prematurely FastCGI stdout");
|
|
1196
|
|
1197 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
|
1198 }
|
|
1199 }
|
|
1200
|
|
1201 if (f->state == ngx_http_fastcgi_st_padding) {
|
|
1202
|
130
|
1203 if (u->buffer.pos + f->padding < u->buffer.last) {
|
50
|
1204 f->state = ngx_http_fastcgi_st_version;
|
130
|
1205 u->buffer.pos += f->padding;
|
50
|
1206
|
|
1207 continue;
|
|
1208 }
|
|
1209
|
130
|
1210 if (u->buffer.pos + f->padding == u->buffer.last) {
|
50
|
1211 f->state = ngx_http_fastcgi_st_version;
|
130
|
1212 u->buffer.pos = u->buffer.last;
|
50
|
1213
|
|
1214 return NGX_AGAIN;
|
|
1215 }
|
|
1216
|
130
|
1217 f->padding -= u->buffer.last - u->buffer.pos;
|
|
1218 u->buffer.pos = u->buffer.last;
|
50
|
1219
|
|
1220 return NGX_AGAIN;
|
|
1221 }
|
|
1222
|
|
1223
|
|
1224 /* f->state == ngx_http_fastcgi_st_data */
|
|
1225
|
|
1226 if (f->type == NGX_HTTP_FASTCGI_STDERR) {
|
|
1227
|
|
1228 if (f->length) {
|
514
|
1229 msg = u->buffer.pos;
|
50
|
1230
|
130
|
1231 if (u->buffer.pos + f->length <= u->buffer.last) {
|
|
1232 u->buffer.pos += f->length;
|
50
|
1233 f->length = 0;
|
|
1234 f->state = ngx_http_fastcgi_st_padding;
|
|
1235
|
126
|
1236 } else {
|
130
|
1237 f->length -= u->buffer.last - u->buffer.pos;
|
|
1238 u->buffer.pos = u->buffer.last;
|
50
|
1239 }
|
|
1240
|
514
|
1241 for (p = u->buffer.pos - 1; msg < p; p--) {
|
|
1242 if (*p != LF && *p != CR && *p != '.' && *p != ' ') {
|
|
1243 break;
|
|
1244 }
|
50
|
1245 }
|
|
1246
|
514
|
1247 p++;
|
|
1248
|
50
|
1249 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
514
|
1250 "FastCGI sent in stderr: \"%*s\"", p - msg, msg);
|
50
|
1251
|
306
|
1252 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
|
|
1253
|
|
1254 if (flcf->catch_stderr) {
|
|
1255 pattern = flcf->catch_stderr->elts;
|
|
1256
|
|
1257 for (i = 0; i < flcf->catch_stderr->nelts; i++) {
|
514
|
1258 if (ngx_strnstr(msg, (char *) pattern[i].data,
|
|
1259 p - msg)
|
|
1260 != NULL)
|
|
1261 {
|
356
|
1262 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
306
|
1263 }
|
|
1264 }
|
|
1265 }
|
|
1266
|
130
|
1267 if (u->buffer.pos == u->buffer.last) {
|
164
|
1268
|
|
1269 if (!f->fastcgi_stdout) {
|
|
1270
|
|
1271 /*
|
|
1272 * the special handling the large number
|
|
1273 * of the PHP warnings to not allocate memory
|
|
1274 */
|
|
1275
|
564
|
1276 #if (NGX_HTTP_CACHE)
|
|
1277 if (r->cache) {
|
|
1278 u->buffer.pos = u->buffer.start
|
|
1279 + r->cache->header_start;
|
|
1280 } else {
|
|
1281 u->buffer.pos = u->buffer.start;
|
|
1282 }
|
612
|
1283 #else
|
|
1284 u->buffer.pos = u->buffer.start;
|
564
|
1285 #endif
|
|
1286 u->buffer.last = u->buffer.pos;
|
|
1287 f->large_stderr = 1;
|
164
|
1288 }
|
|
1289
|
50
|
1290 return NGX_AGAIN;
|
|
1291 }
|
|
1292
|
|
1293 } else {
|
|
1294 f->state = ngx_http_fastcgi_st_version;
|
|
1295 }
|
|
1296
|
|
1297 continue;
|
|
1298 }
|
|
1299
|
|
1300
|
|
1301 /* f->type == NGX_HTTP_FASTCGI_STDOUT */
|
|
1302
|
564
|
1303 #if (NGX_HTTP_CACHE)
|
|
1304
|
566
|
1305 if (f->large_stderr && r->cache) {
|
568
|
1306 u_char *start;
|
|
1307 ssize_t len;
|
|
1308 ngx_http_fastcgi_header_t *fh;
|
564
|
1309
|
|
1310 start = u->buffer.start + r->cache->header_start;
|
|
1311
|
|
1312 len = u->buffer.pos - start - 2 * sizeof(ngx_http_fastcgi_header_t);
|
|
1313
|
|
1314 /*
|
|
1315 * A tail of large stderr output before HTTP header is placed
|
|
1316 * in a cache file without a FastCGI record header.
|
|
1317 * To workaround it we put a dummy FastCGI record header at the
|
|
1318 * start of the stderr output or update r->cache_header_start,
|
|
1319 * if there is no enough place for the record header.
|
|
1320 */
|
|
1321
|
|
1322 if (len >= 0) {
|
|
1323 fh = (ngx_http_fastcgi_header_t *) start;
|
|
1324 fh->version = 1;
|
|
1325 fh->type = NGX_HTTP_FASTCGI_STDERR;
|
|
1326 fh->request_id_hi = 0;
|
|
1327 fh->request_id_lo = 1;
|
|
1328 fh->content_length_hi = (u_char) ((len >> 8) & 0xff);
|
|
1329 fh->content_length_lo = (u_char) (len & 0xff);
|
|
1330 fh->padding_length = 0;
|
|
1331 fh->reserved = 0;
|
|
1332
|
|
1333 } else {
|
|
1334 r->cache->header_start += u->buffer.pos - start
|
|
1335 - sizeof(ngx_http_fastcgi_header_t);
|
|
1336 }
|
|
1337
|
|
1338 f->large_stderr = 0;
|
|
1339 }
|
|
1340
|
|
1341 #endif
|
|
1342
|
164
|
1343 f->fastcgi_stdout = 1;
|
|
1344
|
130
|
1345 start = u->buffer.pos;
|
50
|
1346
|
130
|
1347 if (u->buffer.pos + f->length < u->buffer.last) {
|
50
|
1348
|
|
1349 /*
|
130
|
1350 * set u->buffer.last to the end of the FastCGI record data
|
50
|
1351 * for ngx_http_parse_header_line()
|
|
1352 */
|
|
1353
|
130
|
1354 last = u->buffer.last;
|
|
1355 u->buffer.last = u->buffer.pos + f->length;
|
50
|
1356
|
|
1357 } else {
|
|
1358 last = NULL;
|
|
1359 }
|
|
1360
|
|
1361 for ( ;; ) {
|
|
1362
|
316
|
1363 part_start = u->buffer.pos;
|
512
|
1364 part_end = u->buffer.last;
|
316
|
1365
|
412
|
1366 rc = ngx_http_parse_header_line(r, &u->buffer, 1);
|
50
|
1367
|
|
1368 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1369 "http fastcgi parser: %d", rc);
|
|
1370
|
|
1371 if (rc == NGX_AGAIN) {
|
|
1372 break;
|
|
1373 }
|
|
1374
|
|
1375 if (rc == NGX_OK) {
|
|
1376
|
|
1377 /* a header line has been parsed successfully */
|
|
1378
|
58
|
1379 h = ngx_list_push(&u->headers_in.headers);
|
50
|
1380 if (h == NULL) {
|
356
|
1381 return NGX_ERROR;
|
50
|
1382 }
|
|
1383
|
316
|
1384 if (f->split_parts && f->split_parts->nelts) {
|
|
1385
|
|
1386 part = f->split_parts->elts;
|
|
1387 size = u->buffer.pos - part_start;
|
|
1388
|
|
1389 for (i = 0; i < f->split_parts->nelts; i++) {
|
|
1390 size += part[i].end - part[i].start;
|
|
1391 }
|
|
1392
|
382
|
1393 p = ngx_pnalloc(r->pool, size);
|
316
|
1394 if (p == NULL) {
|
356
|
1395 return NGX_ERROR;
|
316
|
1396 }
|
|
1397
|
|
1398 buf.pos = p;
|
|
1399
|
|
1400 for (i = 0; i < f->split_parts->nelts; i++) {
|
|
1401 p = ngx_cpymem(p, part[i].start,
|
|
1402 part[i].end - part[i].start);
|
|
1403 }
|
|
1404
|
|
1405 p = ngx_cpymem(p, part_start, u->buffer.pos - part_start);
|
|
1406
|
|
1407 buf.last = p;
|
|
1408
|
|
1409 f->split_parts->nelts = 0;
|
|
1410
|
412
|
1411 rc = ngx_http_parse_header_line(r, &buf, 1);
|
316
|
1412
|
|
1413 h->key.len = r->header_name_end - r->header_name_start;
|
|
1414 h->key.data = r->header_name_start;
|
|
1415 h->key.data[h->key.len] = '\0';
|
|
1416
|
|
1417 h->value.len = r->header_end - r->header_start;
|
|
1418 h->value.data = r->header_start;
|
|
1419 h->value.data[h->value.len] = '\0';
|
|
1420
|
382
|
1421 h->lowcase_key = ngx_pnalloc(r->pool, h->key.len);
|
316
|
1422 if (h->lowcase_key == NULL) {
|
356
|
1423 return NGX_ERROR;
|
316
|
1424 }
|
|
1425
|
|
1426 } else {
|
|
1427
|
|
1428 h->key.len = r->header_name_end - r->header_name_start;
|
|
1429 h->value.len = r->header_end - r->header_start;
|
|
1430
|
382
|
1431 h->key.data = ngx_pnalloc(r->pool,
|
|
1432 h->key.len + 1 + h->value.len + 1
|
|
1433 + h->key.len);
|
316
|
1434 if (h->key.data == NULL) {
|
356
|
1435 return NGX_ERROR;
|
316
|
1436 }
|
|
1437
|
|
1438 h->value.data = h->key.data + h->key.len + 1;
|
|
1439 h->lowcase_key = h->key.data + h->key.len + 1
|
|
1440 + h->value.len + 1;
|
|
1441
|
|
1442 ngx_cpystrn(h->key.data, r->header_name_start,
|
|
1443 h->key.len + 1);
|
|
1444 ngx_cpystrn(h->value.data, r->header_start,
|
|
1445 h->value.len + 1);
|
|
1446 }
|
|
1447
|
58
|
1448 h->hash = r->header_hash;
|
|
1449
|
198
|
1450 if (h->key.len == r->lowcase_index) {
|
|
1451 ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len);
|
|
1452
|
|
1453 } else {
|
392
|
1454 ngx_strlow(h->lowcase_key, h->key.data, h->key.len);
|
50
|
1455 }
|
|
1456
|
198
|
1457 hh = ngx_hash_find(&umcf->headers_in_hash, h->hash,
|
|
1458 h->lowcase_key, h->key.len);
|
|
1459
|
|
1460 if (hh && hh->handler(r, h, hh->offset) != NGX_OK) {
|
356
|
1461 return NGX_ERROR;
|
198
|
1462 }
|
|
1463
|
50
|
1464 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1465 "http fastcgi header: \"%V: %V\"",
|
|
1466 &h->key, &h->value);
|
|
1467
|
164
|
1468 if (u->buffer.pos < u->buffer.last) {
|
|
1469 continue;
|
|
1470 }
|
|
1471
|
|
1472 /* the end of the FastCGI record */
|
|
1473
|
|
1474 break;
|
50
|
1475 }
|
|
1476
|
|
1477 if (rc == NGX_HTTP_PARSE_HEADER_DONE) {
|
|
1478
|
|
1479 /* a whole header has been parsed successfully */
|
|
1480
|
|
1481 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1482 "http fastcgi header done");
|
|
1483
|
58
|
1484 if (u->headers_in.status) {
|
|
1485 status_line = &u->headers_in.status->value;
|
50
|
1486
|
|
1487 status = ngx_atoi(status_line->data, 3);
|
|
1488
|
|
1489 if (status == NGX_ERROR) {
|
356
|
1490 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1491 "upstream sent invalid status \"%V\"",
|
|
1492 status_line);
|
|
1493 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
50
|
1494 }
|
|
1495
|
78
|
1496 u->headers_in.status_n = status;
|
|
1497 u->headers_in.status_line = *status_line;
|
50
|
1498
|
392
|
1499 } else if (u->headers_in.location) {
|
|
1500 u->headers_in.status_n = 302;
|
570
|
1501 ngx_str_set(&u->headers_in.status_line,
|
|
1502 "302 Moved Temporarily");
|
392
|
1503
|
50
|
1504 } else {
|
78
|
1505 u->headers_in.status_n = 200;
|
570
|
1506 ngx_str_set(&u->headers_in.status_line, "200 OK");
|
50
|
1507 }
|
|
1508
|
466
|
1509 if (u->state) {
|
|
1510 u->state->status = u->headers_in.status_n;
|
50
|
1511 }
|
|
1512
|
|
1513 break;
|
|
1514 }
|
|
1515
|
|
1516 /* there was error while a header line parsing */
|
|
1517
|
|
1518 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
168
|
1519 "upstream sent invalid header");
|
50
|
1520
|
|
1521 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
|
1522 }
|
|
1523
|
|
1524 if (last) {
|
130
|
1525 u->buffer.last = last;
|
50
|
1526 }
|
|
1527
|
130
|
1528 f->length -= u->buffer.pos - start;
|
50
|
1529
|
|
1530 if (f->length == 0) {
|
|
1531 if (f->padding) {
|
|
1532 f->state = ngx_http_fastcgi_st_padding;
|
|
1533 } else {
|
|
1534 f->state = ngx_http_fastcgi_st_version;
|
|
1535 }
|
|
1536 }
|
|
1537
|
164
|
1538 if (rc == NGX_HTTP_PARSE_HEADER_DONE) {
|
|
1539 return NGX_OK;
|
|
1540 }
|
|
1541
|
316
|
1542 if (rc == NGX_OK) {
|
374
|
1543 continue;
|
164
|
1544 }
|
|
1545
|
316
|
1546 /* rc == NGX_AGAIN */
|
|
1547
|
|
1548 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1549 "upstream split a header line in FastCGI records");
|
|
1550
|
|
1551 if (f->split_parts == NULL) {
|
|
1552 f->split_parts = ngx_array_create(r->pool, 1,
|
|
1553 sizeof(ngx_http_fastcgi_split_part_t));
|
|
1554 if (f->split_parts == NULL) {
|
356
|
1555 return NGX_ERROR;
|
316
|
1556 }
|
164
|
1557 }
|
316
|
1558
|
|
1559 part = ngx_array_push(f->split_parts);
|
|
1560
|
|
1561 part->start = part_start;
|
512
|
1562 part->end = part_end;
|
|
1563
|
|
1564 if (u->buffer.pos < u->buffer.last) {
|
|
1565 continue;
|
|
1566 }
|
316
|
1567
|
|
1568 return NGX_AGAIN;
|
50
|
1569 }
|
|
1570 }
|
|
1571
|
|
1572
|
|
1573 static ngx_int_t
|
|
1574 ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
|
|
1575 {
|
514
|
1576 u_char *m, *msg;
|
50
|
1577 ngx_int_t rc;
|
|
1578 ngx_buf_t *b, **prev;
|
|
1579 ngx_chain_t *cl;
|
|
1580 ngx_http_request_t *r;
|
|
1581 ngx_http_fastcgi_ctx_t *f;
|
|
1582
|
|
1583 if (buf->pos == buf->last) {
|
|
1584 return NGX_OK;
|
|
1585 }
|
|
1586
|
|
1587 r = p->input_ctx;
|
|
1588 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
|
|
1589
|
|
1590 b = NULL;
|
|
1591 prev = &buf->shadow;
|
|
1592
|
|
1593 f->pos = buf->pos;
|
|
1594 f->last = buf->last;
|
|
1595
|
|
1596 for ( ;; ) {
|
|
1597 if (f->state < ngx_http_fastcgi_st_data) {
|
|
1598
|
|
1599 rc = ngx_http_fastcgi_process_record(r, f);
|
|
1600
|
|
1601 if (rc == NGX_AGAIN) {
|
|
1602 break;
|
|
1603 }
|
|
1604
|
|
1605 if (rc == NGX_ERROR) {
|
|
1606 return NGX_ERROR;
|
|
1607 }
|
|
1608
|
|
1609 if (f->type == NGX_HTTP_FASTCGI_STDOUT && f->length == 0) {
|
|
1610 f->state = ngx_http_fastcgi_st_version;
|
|
1611 p->upstream_done = 1;
|
|
1612
|
|
1613 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, p->log, 0,
|
|
1614 "http fastcgi closed stdout");
|
|
1615
|
|
1616 continue;
|
|
1617 }
|
|
1618
|
|
1619 if (f->type == NGX_HTTP_FASTCGI_END_REQUEST) {
|
|
1620 f->state = ngx_http_fastcgi_st_version;
|
|
1621 p->upstream_done = 1;
|
|
1622
|
|
1623 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, p->log, 0,
|
|
1624 "http fastcgi sent end request");
|
|
1625
|
|
1626 break;
|
|
1627 }
|
|
1628 }
|
|
1629
|
|
1630
|
|
1631 if (f->state == ngx_http_fastcgi_st_padding) {
|
|
1632
|
|
1633 if (f->pos + f->padding < f->last) {
|
|
1634 f->state = ngx_http_fastcgi_st_version;
|
|
1635 f->pos += f->padding;
|
|
1636
|
|
1637 continue;
|
|
1638 }
|
|
1639
|
|
1640 if (f->pos + f->padding == f->last) {
|
|
1641 f->state = ngx_http_fastcgi_st_version;
|
|
1642
|
|
1643 break;
|
|
1644 }
|
|
1645
|
|
1646 f->padding -= f->last - f->pos;
|
|
1647
|
|
1648 break;
|
|
1649 }
|
|
1650
|
|
1651
|
|
1652 /* f->state == ngx_http_fastcgi_st_data */
|
|
1653
|
|
1654 if (f->type == NGX_HTTP_FASTCGI_STDERR) {
|
|
1655
|
|
1656 if (f->length) {
|
188
|
1657
|
|
1658 if (f->pos == f->last) {
|
|
1659 break;
|
|
1660 }
|
|
1661
|
514
|
1662 msg = f->pos;
|
50
|
1663
|
|
1664 if (f->pos + f->length <= f->last) {
|
|
1665 f->pos += f->length;
|
|
1666 f->length = 0;
|
|
1667 f->state = ngx_http_fastcgi_st_padding;
|
|
1668
|
126
|
1669 } else {
|
50
|
1670 f->length -= f->last - f->pos;
|
|
1671 f->pos = f->last;
|
|
1672 }
|
|
1673
|
514
|
1674 for (m = f->pos - 1; msg < m; m--) {
|
|
1675 if (*m != LF && *m != CR && *m != '.' && *m != ' ') {
|
|
1676 break;
|
|
1677 }
|
50
|
1678 }
|
|
1679
|
|
1680 ngx_log_error(NGX_LOG_ERR, p->log, 0,
|
514
|
1681 "FastCGI sent in stderr: \"%*s\"",
|
|
1682 m + 1 - msg, msg);
|
50
|
1683
|
|
1684 if (f->pos == f->last) {
|
|
1685 break;
|
|
1686 }
|
|
1687
|
|
1688 } else {
|
|
1689 f->state = ngx_http_fastcgi_st_version;
|
|
1690 }
|
|
1691
|
|
1692 continue;
|
|
1693 }
|
|
1694
|
|
1695
|
|
1696 /* f->type == NGX_HTTP_FASTCGI_STDOUT */
|
|
1697
|
188
|
1698 if (f->pos == f->last) {
|
|
1699 break;
|
|
1700 }
|
|
1701
|
50
|
1702 if (p->free) {
|
|
1703 b = p->free->buf;
|
|
1704 p->free = p->free->next;
|
|
1705
|
|
1706 } else {
|
|
1707 b = ngx_alloc_buf(p->pool);
|
|
1708 if (b == NULL) {
|
|
1709 return NGX_ERROR;
|
|
1710 }
|
|
1711 }
|
|
1712
|
|
1713 ngx_memzero(b, sizeof(ngx_buf_t));
|
|
1714
|
|
1715 b->pos = f->pos;
|
|
1716 b->start = buf->start;
|
|
1717 b->end = buf->end;
|
|
1718 b->tag = p->tag;
|
|
1719 b->temporary = 1;
|
|
1720 b->recycled = 1;
|
|
1721
|
|
1722 *prev = b;
|
|
1723 prev = &b->shadow;
|
|
1724
|
|
1725 cl = ngx_alloc_chain_link(p->pool);
|
|
1726 if (cl == NULL) {
|
|
1727 return NGX_ERROR;
|
|
1728 }
|
|
1729
|
|
1730 cl->buf = b;
|
|
1731 cl->next = NULL;
|
|
1732
|
|
1733 if (p->in) {
|
|
1734 *p->last_in = cl;
|
|
1735 } else {
|
|
1736 p->in = cl;
|
|
1737 }
|
|
1738 p->last_in = &cl->next;
|
|
1739
|
|
1740
|
|
1741 /* STUB */ b->num = buf->num;
|
|
1742
|
274
|
1743 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0,
|
276
|
1744 "input buf #%d %p", b->num, b->pos);
|
50
|
1745
|
|
1746 if (f->pos + f->length < f->last) {
|
|
1747
|
|
1748 if (f->padding) {
|
|
1749 f->state = ngx_http_fastcgi_st_padding;
|
|
1750 } else {
|
|
1751 f->state = ngx_http_fastcgi_st_version;
|
|
1752 }
|
|
1753
|
|
1754 f->pos += f->length;
|
|
1755 b->last = f->pos;
|
|
1756
|
|
1757 continue;
|
|
1758 }
|
|
1759
|
|
1760 if (f->pos + f->length == f->last) {
|
|
1761
|
|
1762 if (f->padding) {
|
|
1763 f->state = ngx_http_fastcgi_st_padding;
|
|
1764 } else {
|
|
1765 f->state = ngx_http_fastcgi_st_version;
|
|
1766 }
|
|
1767
|
|
1768 b->last = f->last;
|
|
1769
|
|
1770 break;
|
|
1771 }
|
|
1772
|
|
1773 f->length -= f->last - f->pos;
|
|
1774
|
|
1775 b->last = f->last;
|
|
1776
|
|
1777 break;
|
|
1778
|
|
1779 }
|
|
1780
|
|
1781 if (b) {
|
|
1782 b->shadow = buf;
|
|
1783 b->last_shadow = 1;
|
|
1784
|
274
|
1785 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0,
|
276
|
1786 "input buf %p %z", b->pos, b->last - b->pos);
|
274
|
1787
|
50
|
1788 return NGX_OK;
|
|
1789 }
|
|
1790
|
|
1791 /* there is no data record in the buf, add it to free chain */
|
|
1792
|
|
1793 if (ngx_event_pipe_add_free_buf(p, buf) != NGX_OK) {
|
|
1794 return NGX_ERROR;
|
|
1795 }
|
|
1796
|
|
1797 return NGX_OK;
|
|
1798 }
|
|
1799
|
|
1800
|
|
1801 static ngx_int_t
|
|
1802 ngx_http_fastcgi_process_record(ngx_http_request_t *r,
|
|
1803 ngx_http_fastcgi_ctx_t *f)
|
|
1804 {
|
|
1805 u_char ch, *p;
|
|
1806 ngx_http_fastcgi_state_e state;
|
|
1807
|
|
1808 state = f->state;
|
|
1809
|
|
1810 for (p = f->pos; p < f->last; p++) {
|
|
1811
|
|
1812 ch = *p;
|
|
1813
|
|
1814 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1815 "http fastcgi record byte: %02Xd", ch);
|
|
1816
|
|
1817 switch (state) {
|
|
1818
|
|
1819 case ngx_http_fastcgi_st_version:
|
|
1820 if (ch != 1) {
|
|
1821 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1822 "upstream sent unsupported FastCGI "
|
|
1823 "protocol version: %d", ch);
|
|
1824 return NGX_ERROR;
|
|
1825 }
|
|
1826 state = ngx_http_fastcgi_st_type;
|
|
1827 break;
|
|
1828
|
|
1829 case ngx_http_fastcgi_st_type:
|
|
1830 switch (ch) {
|
|
1831 case NGX_HTTP_FASTCGI_STDOUT:
|
|
1832 case NGX_HTTP_FASTCGI_STDERR:
|
|
1833 case NGX_HTTP_FASTCGI_END_REQUEST:
|
|
1834 f->type = (ngx_uint_t) ch;
|
|
1835 break;
|
|
1836 default:
|
|
1837 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1838 "upstream sent invalid FastCGI "
|
|
1839 "record type: %d", ch);
|
|
1840 return NGX_ERROR;
|
|
1841
|
|
1842 }
|
|
1843 state = ngx_http_fastcgi_st_request_id_hi;
|
|
1844 break;
|
|
1845
|
|
1846 /* we support the single request per connection */
|
|
1847
|
|
1848 case ngx_http_fastcgi_st_request_id_hi:
|
|
1849 if (ch != 0) {
|
|
1850 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1851 "upstream sent unexpected FastCGI "
|
|
1852 "request id high byte: %d", ch);
|
|
1853 return NGX_ERROR;
|
|
1854 }
|
|
1855 state = ngx_http_fastcgi_st_request_id_lo;
|
|
1856 break;
|
|
1857
|
|
1858 case ngx_http_fastcgi_st_request_id_lo:
|
|
1859 if (ch != 1) {
|
|
1860 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1861 "upstream sent unexpected FastCGI "
|
|
1862 "request id low byte: %d", ch);
|
|
1863 return NGX_ERROR;
|
|
1864 }
|
|
1865 state = ngx_http_fastcgi_st_content_length_hi;
|
|
1866 break;
|
|
1867
|
|
1868 case ngx_http_fastcgi_st_content_length_hi:
|
|
1869 f->length = ch << 8;
|
|
1870 state = ngx_http_fastcgi_st_content_length_lo;
|
|
1871 break;
|
|
1872
|
|
1873 case ngx_http_fastcgi_st_content_length_lo:
|
|
1874 f->length |= (size_t) ch;
|
|
1875 state = ngx_http_fastcgi_st_padding_length;
|
|
1876 break;
|
|
1877
|
|
1878 case ngx_http_fastcgi_st_padding_length:
|
|
1879 f->padding = (size_t) ch;
|
|
1880 state = ngx_http_fastcgi_st_reserved;
|
|
1881 break;
|
|
1882
|
|
1883 case ngx_http_fastcgi_st_reserved:
|
|
1884 state = ngx_http_fastcgi_st_data;
|
|
1885
|
|
1886 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1887 "http fastcgi record length: %z", f->length);
|
|
1888
|
|
1889 f->pos = p + 1;
|
|
1890 f->state = state;
|
|
1891
|
|
1892 return NGX_OK;
|
|
1893
|
|
1894 /* suppress warning */
|
|
1895 case ngx_http_fastcgi_st_data:
|
|
1896 case ngx_http_fastcgi_st_padding:
|
|
1897 break;
|
|
1898 }
|
|
1899 }
|
|
1900
|
|
1901 f->state = state;
|
|
1902
|
|
1903 return NGX_AGAIN;
|
|
1904 }
|
|
1905
|
|
1906
|
|
1907 static void
|
|
1908 ngx_http_fastcgi_abort_request(ngx_http_request_t *r)
|
|
1909 {
|
|
1910 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1911 "abort http fastcgi request");
|
|
1912
|
|
1913 return;
|
|
1914 }
|
|
1915
|
|
1916
|
|
1917 static void
|
|
1918 ngx_http_fastcgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
|
|
1919 {
|
|
1920 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1921 "finalize http fastcgi request");
|
|
1922
|
|
1923 return;
|
|
1924 }
|
|
1925
|
|
1926
|
58
|
1927 static ngx_int_t
|
|
1928 ngx_http_fastcgi_add_variables(ngx_conf_t *cf)
|
50
|
1929 {
|
438
|
1930 ngx_http_variable_t *var, *v;
|
|
1931
|
|
1932 for (v = ngx_http_fastcgi_vars; v->name.len; v++) {
|
|
1933 var = ngx_http_add_variable(cf, &v->name, v->flags);
|
|
1934 if (var == NULL) {
|
|
1935 return NGX_ERROR;
|
|
1936 }
|
|
1937
|
|
1938 var->get_handler = v->get_handler;
|
|
1939 var->data = v->data;
|
50
|
1940 }
|
|
1941
|
58
|
1942 return NGX_OK;
|
50
|
1943 }
|
|
1944
|
|
1945
|
|
1946 static void *
|
|
1947 ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf)
|
|
1948 {
|
|
1949 ngx_http_fastcgi_loc_conf_t *conf;
|
|
1950
|
|
1951 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_fastcgi_loc_conf_t));
|
|
1952 if (conf == NULL) {
|
496
|
1953 return NULL;
|
50
|
1954 }
|
|
1955
|
|
1956 /*
|
|
1957 * set by ngx_pcalloc():
|
|
1958 *
|
|
1959 * conf->upstream.bufs.num = 0;
|
484
|
1960 * conf->upstream.ignore_headers = 0;
|
50
|
1961 * conf->upstream.next_upstream = 0;
|
494
|
1962 * conf->upstream.cache_use_stale = 0;
|
|
1963 * conf->upstream.cache_methods = 0;
|
50
|
1964 * conf->upstream.temp_path = NULL;
|
198
|
1965 * conf->upstream.hide_headers_hash = { NULL, 0 };
|
58
|
1966 * conf->upstream.uri = { 0, NULL };
|
|
1967 * conf->upstream.location = NULL;
|
320
|
1968 * conf->upstream.store_lengths = NULL;
|
|
1969 * conf->upstream.store_values = NULL;
|
58
|
1970 *
|
570
|
1971 * conf->index.len = { 0, NULL };
|
50
|
1972 */
|
|
1973
|
320
|
1974 conf->upstream.store = NGX_CONF_UNSET;
|
|
1975 conf->upstream.store_access = NGX_CONF_UNSET_UINT;
|
130
|
1976 conf->upstream.buffering = NGX_CONF_UNSET;
|
178
|
1977 conf->upstream.ignore_client_abort = NGX_CONF_UNSET;
|
130
|
1978
|
50
|
1979 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC;
|
|
1980 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC;
|
56
|
1981 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC;
|
|
1982
|
50
|
1983 conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE;
|
130
|
1984 conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE;
|
78
|
1985
|
|
1986 conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE;
|
126
|
1987 conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
|
78
|
1988 conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE;
|
58
|
1989
|
|
1990 conf->upstream.pass_request_headers = NGX_CONF_UNSET;
|
|
1991 conf->upstream.pass_request_body = NGX_CONF_UNSET;
|
|
1992
|
466
|
1993 #if (NGX_HTTP_CACHE)
|
|
1994 conf->upstream.cache = NGX_CONF_UNSET_PTR;
|
|
1995 conf->upstream.cache_min_uses = NGX_CONF_UNSET_UINT;
|
588
|
1996 conf->upstream.cache_bypass = NGX_CONF_UNSET_PTR;
|
572
|
1997 conf->upstream.no_cache = NGX_CONF_UNSET_PTR;
|
466
|
1998 conf->upstream.cache_valid = NGX_CONF_UNSET_PTR;
|
|
1999 #endif
|
|
2000
|
356
|
2001 conf->upstream.hide_headers = NGX_CONF_UNSET_PTR;
|
|
2002 conf->upstream.pass_headers = NGX_CONF_UNSET_PTR;
|
|
2003
|
206
|
2004 conf->upstream.intercept_errors = NGX_CONF_UNSET;
|
50
|
2005
|
|
2006 /* "fastcgi_cyclic_temp_file" is disabled */
|
|
2007 conf->upstream.cyclic_temp_file = 0;
|
|
2008
|
332
|
2009 conf->catch_stderr = NGX_CONF_UNSET_PTR;
|
|
2010
|
50
|
2011 return conf;
|
|
2012 }
|
|
2013
|
|
2014
|
|
2015 static char *
|
|
2016 ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
|
2017 {
|
|
2018 ngx_http_fastcgi_loc_conf_t *prev = parent;
|
|
2019 ngx_http_fastcgi_loc_conf_t *conf = child;
|
|
2020
|
58
|
2021 u_char *p;
|
|
2022 size_t size;
|
|
2023 uintptr_t *code;
|
356
|
2024 ngx_uint_t i;
|
576
|
2025 ngx_array_t headers_names;
|
198
|
2026 ngx_keyval_t *src;
|
576
|
2027 ngx_hash_key_t *hk;
|
198
|
2028 ngx_hash_init_t hash;
|
592
|
2029 ngx_http_core_loc_conf_t *clcf;
|
58
|
2030 ngx_http_script_compile_t sc;
|
|
2031 ngx_http_script_copy_code_t *copy;
|
50
|
2032
|
320
|
2033 if (conf->upstream.store != 0) {
|
|
2034 ngx_conf_merge_value(conf->upstream.store,
|
496
|
2035 prev->upstream.store, 0);
|
320
|
2036
|
|
2037 if (conf->upstream.store_lengths == NULL) {
|
|
2038 conf->upstream.store_lengths = prev->upstream.store_lengths;
|
|
2039 conf->upstream.store_values = prev->upstream.store_values;
|
|
2040 }
|
|
2041 }
|
|
2042
|
|
2043 ngx_conf_merge_uint_value(conf->upstream.store_access,
|
|
2044 prev->upstream.store_access, 0600);
|
318
|
2045
|
130
|
2046 ngx_conf_merge_value(conf->upstream.buffering,
|
|
2047 prev->upstream.buffering, 1);
|
|
2048
|
178
|
2049 ngx_conf_merge_value(conf->upstream.ignore_client_abort,
|
|
2050 prev->upstream.ignore_client_abort, 0);
|
|
2051
|
50
|
2052 ngx_conf_merge_msec_value(conf->upstream.connect_timeout,
|
|
2053 prev->upstream.connect_timeout, 60000);
|
56
|
2054
|
50
|
2055 ngx_conf_merge_msec_value(conf->upstream.send_timeout,
|
|
2056 prev->upstream.send_timeout, 60000);
|
|
2057
|
|
2058 ngx_conf_merge_msec_value(conf->upstream.read_timeout,
|
|
2059 prev->upstream.read_timeout, 60000);
|
|
2060
|
56
|
2061 ngx_conf_merge_size_value(conf->upstream.send_lowat,
|
|
2062 prev->upstream.send_lowat, 0);
|
50
|
2063
|
130
|
2064 ngx_conf_merge_size_value(conf->upstream.buffer_size,
|
|
2065 prev->upstream.buffer_size,
|
50
|
2066 (size_t) ngx_pagesize);
|
|
2067
|
56
|
2068
|
50
|
2069 ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs,
|
|
2070 8, ngx_pagesize);
|
|
2071
|
|
2072 if (conf->upstream.bufs.num < 2) {
|
|
2073 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2074 "there must be at least 2 \"fastcgi_buffers\"");
|
|
2075 return NGX_CONF_ERROR;
|
|
2076 }
|
|
2077
|
|
2078
|
130
|
2079 size = conf->upstream.buffer_size;
|
50
|
2080 if (size < conf->upstream.bufs.size) {
|
|
2081 size = conf->upstream.bufs.size;
|
|
2082 }
|
|
2083
|
|
2084
|
78
|
2085 ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf,
|
|
2086 prev->upstream.busy_buffers_size_conf,
|
50
|
2087 NGX_CONF_UNSET_SIZE);
|
|
2088
|
78
|
2089 if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) {
|
50
|
2090 conf->upstream.busy_buffers_size = 2 * size;
|
78
|
2091 } else {
|
|
2092 conf->upstream.busy_buffers_size =
|
|
2093 conf->upstream.busy_buffers_size_conf;
|
|
2094 }
|
50
|
2095
|
78
|
2096 if (conf->upstream.busy_buffers_size < size) {
|
50
|
2097 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2098 "\"fastcgi_busy_buffers_size\" must be equal or bigger than "
|
288
|
2099 "maximum of the value of \"fastcgi_buffer_size\" and "
|
50
|
2100 "one of the \"fastcgi_buffers\"");
|
|
2101
|
|
2102 return NGX_CONF_ERROR;
|
78
|
2103 }
|
50
|
2104
|
78
|
2105 if (conf->upstream.busy_buffers_size
|
|
2106 > (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size)
|
50
|
2107 {
|
|
2108 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2109 "\"fastcgi_busy_buffers_size\" must be less than "
|
|
2110 "the size of all \"fastcgi_buffers\" minus one buffer");
|
|
2111
|
|
2112 return NGX_CONF_ERROR;
|
|
2113 }
|
|
2114
|
|
2115
|
78
|
2116 ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf,
|
|
2117 prev->upstream.temp_file_write_size_conf,
|
50
|
2118 NGX_CONF_UNSET_SIZE);
|
|
2119
|
78
|
2120 if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) {
|
50
|
2121 conf->upstream.temp_file_write_size = 2 * size;
|
78
|
2122 } else {
|
|
2123 conf->upstream.temp_file_write_size =
|
|
2124 conf->upstream.temp_file_write_size_conf;
|
|
2125 }
|
50
|
2126
|
78
|
2127 if (conf->upstream.temp_file_write_size < size) {
|
50
|
2128 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2129 "\"fastcgi_temp_file_write_size\" must be equal or bigger than "
|
288
|
2130 "maximum of the value of \"fastcgi_buffer_size\" and "
|
50
|
2131 "one of the \"fastcgi_buffers\"");
|
|
2132
|
|
2133 return NGX_CONF_ERROR;
|
|
2134 }
|
|
2135
|
|
2136
|
78
|
2137 ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf,
|
|
2138 prev->upstream.max_temp_file_size_conf,
|
50
|
2139 NGX_CONF_UNSET_SIZE);
|
|
2140
|
78
|
2141 if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) {
|
50
|
2142 conf->upstream.max_temp_file_size = 1024 * 1024 * 1024;
|
78
|
2143 } else {
|
|
2144 conf->upstream.max_temp_file_size =
|
|
2145 conf->upstream.max_temp_file_size_conf;
|
|
2146 }
|
50
|
2147
|
78
|
2148 if (conf->upstream.max_temp_file_size != 0
|
|
2149 && conf->upstream.max_temp_file_size < size)
|
50
|
2150 {
|
|
2151 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2152 "\"fastcgi_max_temp_file_size\" must be equal to zero to disable "
|
|
2153 "the temporary files usage or must be equal or bigger than "
|
288
|
2154 "maximum of the value of \"fastcgi_buffer_size\" and "
|
50
|
2155 "one of the \"fastcgi_buffers\"");
|
|
2156
|
|
2157 return NGX_CONF_ERROR;
|
|
2158 }
|
|
2159
|
|
2160
|
484
|
2161 ngx_conf_merge_bitmask_value(conf->upstream.ignore_headers,
|
|
2162 prev->upstream.ignore_headers,
|
|
2163 NGX_CONF_BITMASK_SET);
|
|
2164
|
|
2165
|
50
|
2166 ngx_conf_merge_bitmask_value(conf->upstream.next_upstream,
|
|
2167 prev->upstream.next_upstream,
|
|
2168 (NGX_CONF_BITMASK_SET
|
|
2169 |NGX_HTTP_UPSTREAM_FT_ERROR
|
|
2170 |NGX_HTTP_UPSTREAM_FT_TIMEOUT));
|
|
2171
|
214
|
2172 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) {
|
|
2173 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET
|
|
2174 |NGX_HTTP_UPSTREAM_FT_OFF;
|
|
2175 }
|
|
2176
|
464
|
2177 if (ngx_conf_merge_path_value(cf, &conf->upstream.temp_path,
|
50
|
2178 prev->upstream.temp_path,
|
464
|
2179 &ngx_http_fastcgi_temp_path)
|
|
2180 != NGX_OK)
|
|
2181 {
|
|
2182 return NGX_CONF_ERROR;
|
|
2183 }
|
50
|
2184
|
466
|
2185 #if (NGX_HTTP_CACHE)
|
|
2186
|
|
2187 ngx_conf_merge_ptr_value(conf->upstream.cache,
|
|
2188 prev->upstream.cache, NULL);
|
|
2189
|
|
2190 if (conf->upstream.cache && conf->upstream.cache->data == NULL) {
|
|
2191 ngx_shm_zone_t *shm_zone;
|
|
2192
|
|
2193 shm_zone = conf->upstream.cache;
|
|
2194
|
|
2195 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2196 "\"fastcgi_cache\" zone \"%V\" is unknown",
|
480
|
2197 &shm_zone->shm.name);
|
466
|
2198
|
|
2199 return NGX_CONF_ERROR;
|
|
2200 }
|
|
2201
|
|
2202 ngx_conf_merge_uint_value(conf->upstream.cache_min_uses,
|
|
2203 prev->upstream.cache_min_uses, 1);
|
|
2204
|
|
2205 ngx_conf_merge_bitmask_value(conf->upstream.cache_use_stale,
|
|
2206 prev->upstream.cache_use_stale,
|
|
2207 (NGX_CONF_BITMASK_SET
|
|
2208 |NGX_HTTP_UPSTREAM_FT_OFF));
|
|
2209
|
|
2210 if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_OFF) {
|
|
2211 conf->upstream.cache_use_stale = NGX_CONF_BITMASK_SET
|
|
2212 |NGX_HTTP_UPSTREAM_FT_OFF;
|
|
2213 }
|
|
2214
|
494
|
2215 if (conf->upstream.cache_methods == 0) {
|
|
2216 conf->upstream.cache_methods = prev->upstream.cache_methods;
|
|
2217 }
|
|
2218
|
|
2219 conf->upstream.cache_methods |= NGX_HTTP_GET|NGX_HTTP_HEAD;
|
|
2220
|
588
|
2221 ngx_conf_merge_ptr_value(conf->upstream.cache_bypass,
|
|
2222 prev->upstream.cache_bypass, NULL);
|
|
2223
|
572
|
2224 ngx_conf_merge_ptr_value(conf->upstream.no_cache,
|
|
2225 prev->upstream.no_cache, NULL);
|
|
2226
|
588
|
2227 if (conf->upstream.no_cache && conf->upstream.cache_bypass == NULL) {
|
|
2228 ngx_log_error(NGX_LOG_WARN, cf->log, 0,
|
|
2229 "\"fastcgi_no_cache\" functionality has been changed in 0.8.46, "
|
|
2230 "now it should be used together with \"fastcgi_cache_bypass\"");
|
|
2231 }
|
|
2232
|
466
|
2233 ngx_conf_merge_ptr_value(conf->upstream.cache_valid,
|
|
2234 prev->upstream.cache_valid, NULL);
|
|
2235
|
472
|
2236 if (conf->cache_key.value.data == NULL) {
|
|
2237 conf->cache_key = prev->cache_key;
|
|
2238 }
|
|
2239
|
466
|
2240 #endif
|
|
2241
|
58
|
2242 ngx_conf_merge_value(conf->upstream.pass_request_headers,
|
|
2243 prev->upstream.pass_request_headers, 1);
|
|
2244 ngx_conf_merge_value(conf->upstream.pass_request_body,
|
|
2245 prev->upstream.pass_request_body, 1);
|
|
2246
|
206
|
2247 ngx_conf_merge_value(conf->upstream.intercept_errors,
|
|
2248 prev->upstream.intercept_errors, 0);
|
58
|
2249
|
306
|
2250 ngx_conf_merge_ptr_value(conf->catch_stderr, prev->catch_stderr, NULL);
|
|
2251
|
56
|
2252
|
50
|
2253 ngx_conf_merge_str_value(conf->index, prev->index, "");
|
|
2254
|
356
|
2255 hash.max_size = 512;
|
|
2256 hash.bucket_size = ngx_align(64, ngx_cacheline_size);
|
|
2257 hash.name = "fastcgi_hide_headers_hash";
|
|
2258
|
|
2259 if (ngx_http_upstream_hide_headers_hash(cf, &conf->upstream,
|
584
|
2260 &prev->upstream, ngx_http_fastcgi_hide_headers, &hash)
|
198
|
2261 != NGX_OK)
|
|
2262 {
|
|
2263 return NGX_CONF_ERROR;
|
|
2264 }
|
|
2265
|
260
|
2266 if (conf->upstream.upstream == NULL) {
|
|
2267 conf->upstream.upstream = prev->upstream.upstream;
|
430
|
2268 }
|
|
2269
|
|
2270 if (conf->fastcgi_lengths == NULL) {
|
|
2271 conf->fastcgi_lengths = prev->fastcgi_lengths;
|
|
2272 conf->fastcgi_values = prev->fastcgi_values;
|
56
|
2273 }
|
|
2274
|
592
|
2275 if (conf->upstream.upstream || conf->fastcgi_lengths) {
|
|
2276 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
|
|
2277 if (clcf->handler == NULL && clcf->lmt_excpt) {
|
|
2278 clcf->handler = ngx_http_fastcgi_handler;
|
|
2279 }
|
|
2280 }
|
|
2281
|
438
|
2282 #if (NGX_PCRE)
|
|
2283 if (conf->split_regex == NULL) {
|
|
2284 conf->split_regex = prev->split_regex;
|
|
2285 conf->split_name = prev->split_name;
|
|
2286 }
|
|
2287 #endif
|
|
2288
|
58
|
2289 if (conf->params_source == NULL) {
|
122
|
2290 conf->flushes = prev->flushes;
|
58
|
2291 conf->params_len = prev->params_len;
|
|
2292 conf->params = prev->params;
|
122
|
2293 conf->params_source = prev->params_source;
|
576
|
2294 conf->headers_hash = prev->headers_hash;
|
|
2295
|
|
2296 #if (NGX_HTTP_CACHE)
|
|
2297
|
|
2298 if (conf->params_source == NULL) {
|
|
2299
|
|
2300 if ((conf->upstream.cache == NULL)
|
|
2301 == (prev->upstream.cache == NULL))
|
|
2302 {
|
|
2303 return NGX_CONF_OK;
|
|
2304 }
|
|
2305
|
|
2306 /* 6 is a number of ngx_http_fastcgi_cache_headers entries */
|
|
2307 conf->params_source = ngx_array_create(cf->pool, 6,
|
|
2308 sizeof(ngx_keyval_t));
|
|
2309 if (conf->params_source == NULL) {
|
|
2310 return NGX_CONF_ERROR;
|
|
2311 }
|
|
2312 }
|
|
2313 #else
|
58
|
2314
|
|
2315 if (conf->params_source == NULL) {
|
|
2316 return NGX_CONF_OK;
|
|
2317 }
|
576
|
2318
|
|
2319 #endif
|
58
|
2320 }
|
|
2321
|
|
2322 conf->params_len = ngx_array_create(cf->pool, 64, 1);
|
|
2323 if (conf->params_len == NULL) {
|
|
2324 return NGX_CONF_ERROR;
|
|
2325 }
|
122
|
2326
|
58
|
2327 conf->params = ngx_array_create(cf->pool, 512, 1);
|
|
2328 if (conf->params == NULL) {
|
|
2329 return NGX_CONF_ERROR;
|
|
2330 }
|
|
2331
|
576
|
2332 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t))
|
|
2333 != NGX_OK)
|
|
2334 {
|
|
2335 return NGX_CONF_ERROR;
|
|
2336 }
|
|
2337
|
58
|
2338 src = conf->params_source->elts;
|
576
|
2339
|
|
2340 #if (NGX_HTTP_CACHE)
|
|
2341
|
|
2342 if (conf->upstream.cache) {
|
|
2343 ngx_keyval_t *h, *s;
|
|
2344
|
|
2345 for (h = ngx_http_fastcgi_cache_headers; h->key.len; h++) {
|
|
2346
|
|
2347 for (i = 0; i < conf->params_source->nelts; i++) {
|
|
2348 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) {
|
|
2349 goto next;
|
|
2350 }
|
|
2351 }
|
|
2352
|
|
2353 s = ngx_array_push(conf->params_source);
|
|
2354 if (s == NULL) {
|
58
|
2355 return NGX_CONF_ERROR;
|
|
2356 }
|
|
2357
|
576
|
2358 *s = *h;
|
|
2359
|
|
2360 src = conf->params_source->elts;
|
|
2361
|
|
2362 next:
|
|
2363
|
|
2364 h++;
|
|
2365 }
|
|
2366 }
|
|
2367
|
|
2368 #endif
|
|
2369
|
|
2370 for (i = 0; i < conf->params_source->nelts; i++) {
|
|
2371
|
|
2372 if (src[i].key.len > sizeof("HTTP_") - 1
|
|
2373 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0)
|
|
2374 {
|
|
2375 hk = ngx_array_push(&headers_names);
|
|
2376 if (hk == NULL) {
|
58
|
2377 return NGX_CONF_ERROR;
|
|
2378 }
|
126
|
2379
|
576
|
2380 hk->key.len = src[i].key.len - 5;
|
|
2381 hk->key.data = src[i].key.data + 5;
|
|
2382 hk->key_hash = ngx_hash_key_lc(hk->key.data, hk->key.len);
|
|
2383 hk->value = (void *) 1;
|
|
2384
|
|
2385 if (src[i].value.len == 0) {
|
|
2386 continue;
|
58
|
2387 }
|
576
|
2388 }
|
|
2389
|
|
2390 copy = ngx_array_push_n(conf->params_len,
|
|
2391 sizeof(ngx_http_script_copy_code_t));
|
|
2392 if (copy == NULL) {
|
|
2393 return NGX_CONF_ERROR;
|
|
2394 }
|
|
2395
|
|
2396 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
|
|
2397 copy->len = src[i].key.len;
|
|
2398
|
|
2399
|
|
2400 size = (sizeof(ngx_http_script_copy_code_t)
|
|
2401 + src[i].key.len + sizeof(uintptr_t) - 1)
|
|
2402 & ~(sizeof(uintptr_t) - 1);
|
|
2403
|
|
2404 copy = ngx_array_push_n(conf->params, size);
|
|
2405 if (copy == NULL) {
|
|
2406 return NGX_CONF_ERROR;
|
|
2407 }
|
|
2408
|
|
2409 copy->code = ngx_http_script_copy_code;
|
|
2410 copy->len = src[i].key.len;
|
|
2411
|
|
2412 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t);
|
|
2413 ngx_memcpy(p, src[i].key.data, src[i].key.len);
|
|
2414
|
|
2415
|
|
2416 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
2417
|
|
2418 sc.cf = cf;
|
|
2419 sc.source = &src[i].value;
|
|
2420 sc.flushes = &conf->flushes;
|
|
2421 sc.lengths = &conf->params_len;
|
|
2422 sc.values = &conf->params;
|
|
2423
|
|
2424 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
2425 return NGX_CONF_ERROR;
|
58
|
2426 }
|
|
2427
|
|
2428 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
|
|
2429 if (code == NULL) {
|
|
2430 return NGX_CONF_ERROR;
|
|
2431 }
|
|
2432
|
|
2433 *code = (uintptr_t) NULL;
|
|
2434
|
|
2435
|
|
2436 code = ngx_array_push_n(conf->params, sizeof(uintptr_t));
|
|
2437 if (code == NULL) {
|
|
2438 return NGX_CONF_ERROR;
|
|
2439 }
|
|
2440
|
|
2441 *code = (uintptr_t) NULL;
|
|
2442 }
|
|
2443
|
|
2444 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
|
|
2445 if (code == NULL) {
|
|
2446 return NGX_CONF_ERROR;
|
|
2447 }
|
|
2448
|
|
2449 *code = (uintptr_t) NULL;
|
|
2450
|
576
|
2451
|
|
2452 conf->header_params = headers_names.nelts;
|
|
2453
|
|
2454 hash.hash = &conf->headers_hash;
|
|
2455 hash.key = ngx_hash_key_lc;
|
|
2456 hash.max_size = 512;
|
|
2457 hash.bucket_size = 64;
|
|
2458 hash.name = "fastcgi_params_hash";
|
|
2459 hash.pool = cf->pool;
|
|
2460 hash.temp_pool = NULL;
|
|
2461
|
|
2462 if (ngx_hash_init(&hash, headers_names.elts, headers_names.nelts) != NGX_OK)
|
|
2463 {
|
|
2464 return NGX_CONF_ERROR;
|
|
2465 }
|
|
2466
|
50
|
2467 return NGX_CONF_OK;
|
|
2468 }
|
58
|
2469
|
|
2470
|
122
|
2471 static ngx_int_t
|
|
2472 ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r,
|
|
2473 ngx_http_variable_value_t *v, uintptr_t data)
|
58
|
2474 {
|
|
2475 u_char *p;
|
438
|
2476 ngx_http_fastcgi_ctx_t *f;
|
58
|
2477 ngx_http_fastcgi_loc_conf_t *flcf;
|
|
2478
|
438
|
2479 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
|
|
2480
|
440
|
2481 f = ngx_http_fastcgi_split(r, flcf);
|
|
2482
|
|
2483 if (f == NULL) {
|
438
|
2484 return NGX_ERROR;
|
|
2485 }
|
|
2486
|
|
2487 if (f->script_name.len == 0
|
|
2488 || f->script_name.data[f->script_name.len - 1] != '/')
|
|
2489 {
|
|
2490 v->len = f->script_name.len;
|
284
|
2491 v->valid = 1;
|
340
|
2492 v->no_cacheable = 0;
|
284
|
2493 v->not_found = 0;
|
438
|
2494 v->data = f->script_name.data;
|
284
|
2495
|
122
|
2496 return NGX_OK;
|
58
|
2497 }
|
|
2498
|
438
|
2499 v->len = f->script_name.len + flcf->index.len;
|
|
2500
|
|
2501 v->data = ngx_pnalloc(r->pool, v->len);
|
|
2502 if (v->data == NULL) {
|
|
2503 return NGX_ERROR;
|
|
2504 }
|
|
2505
|
|
2506 p = ngx_copy(v->data, f->script_name.data, f->script_name.len);
|
|
2507 ngx_memcpy(p, flcf->index.data, flcf->index.len);
|
|
2508
|
122
|
2509 return NGX_OK;
|
58
|
2510 }
|
|
2511
|
|
2512
|
438
|
2513 static ngx_int_t
|
|
2514 ngx_http_fastcgi_path_info_variable(ngx_http_request_t *r,
|
|
2515 ngx_http_variable_value_t *v, uintptr_t data)
|
|
2516 {
|
|
2517 ngx_http_fastcgi_ctx_t *f;
|
|
2518 ngx_http_fastcgi_loc_conf_t *flcf;
|
|
2519
|
|
2520 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
|
|
2521
|
440
|
2522 f = ngx_http_fastcgi_split(r, flcf);
|
|
2523
|
|
2524 if (f == NULL) {
|
438
|
2525 return NGX_ERROR;
|
|
2526 }
|
|
2527
|
|
2528 v->len = f->path_info.len;
|
|
2529 v->valid = 1;
|
|
2530 v->no_cacheable = 0;
|
|
2531 v->not_found = 0;
|
|
2532 v->data = f->path_info.data;
|
|
2533
|
|
2534 return NGX_OK;
|
|
2535 }
|
|
2536
|
|
2537
|
440
|
2538 static ngx_http_fastcgi_ctx_t *
|
|
2539 ngx_http_fastcgi_split(ngx_http_request_t *r, ngx_http_fastcgi_loc_conf_t *flcf)
|
438
|
2540 {
|
440
|
2541 ngx_http_fastcgi_ctx_t *f;
|
438
|
2542 #if (NGX_PCRE)
|
440
|
2543 ngx_int_t n;
|
|
2544 int captures[(1 + 2) * 3];
|
|
2545
|
|
2546 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
|
|
2547
|
|
2548 if (f == NULL) {
|
|
2549 f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t));
|
|
2550 if (f == NULL) {
|
|
2551 return NULL;
|
|
2552 }
|
|
2553
|
|
2554 ngx_http_set_ctx(r, f, ngx_http_fastcgi_module);
|
|
2555 }
|
438
|
2556
|
|
2557 if (f->script_name.len) {
|
440
|
2558 return f;
|
438
|
2559 }
|
|
2560
|
|
2561 if (flcf->split_regex == NULL) {
|
|
2562 f->script_name = r->uri;
|
440
|
2563 return f;
|
438
|
2564 }
|
|
2565
|
|
2566 n = ngx_regex_exec(flcf->split_regex, &r->uri, captures, (1 + 2) * 3);
|
|
2567
|
546
|
2568 if (n >= 0) { /* match */
|
|
2569 f->script_name.len = captures[3] - captures[2];
|
592
|
2570 f->script_name.data = r->uri.data + captures[2];
|
546
|
2571
|
|
2572 f->path_info.len = captures[5] - captures[4];
|
592
|
2573 f->path_info.data = r->uri.data + captures[4];
|
546
|
2574
|
|
2575 return f;
|
|
2576 }
|
|
2577
|
438
|
2578 if (n == NGX_REGEX_NO_MATCHED) {
|
|
2579 f->script_name = r->uri;
|
440
|
2580 return f;
|
438
|
2581 }
|
|
2582
|
546
|
2583 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
|
2584 ngx_regex_exec_n " failed: %i on \"%V\" using \"%V\"",
|
|
2585 n, &r->uri, &flcf->split_name);
|
|
2586 return NULL;
|
438
|
2587
|
|
2588 #else
|
|
2589
|
440
|
2590 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
|
|
2591
|
|
2592 if (f == NULL) {
|
|
2593 f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t));
|
|
2594 if (f == NULL) {
|
|
2595 return NULL;
|
|
2596 }
|
|
2597
|
|
2598 ngx_http_set_ctx(r, f, ngx_http_fastcgi_module);
|
|
2599 }
|
|
2600
|
438
|
2601 f->script_name = r->uri;
|
|
2602
|
440
|
2603 return f;
|
438
|
2604
|
|
2605 #endif
|
|
2606 }
|
|
2607
|
|
2608
|
58
|
2609 static char *
|
|
2610 ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
2611 {
|
430
|
2612 ngx_http_fastcgi_loc_conf_t *flcf = conf;
|
|
2613
|
|
2614 ngx_url_t u;
|
|
2615 ngx_str_t *value, *url;
|
|
2616 ngx_uint_t n;
|
|
2617 ngx_http_core_loc_conf_t *clcf;
|
|
2618 ngx_http_script_compile_t sc;
|
|
2619
|
|
2620 if (flcf->upstream.upstream || flcf->fastcgi_lengths) {
|
104
|
2621 return "is duplicate";
|
|
2622 }
|
|
2623
|
430
|
2624 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
|
510
|
2625
|
430
|
2626 clcf->handler = ngx_http_fastcgi_handler;
|
|
2627
|
510
|
2628 if (clcf->name.data[clcf->name.len - 1] == '/') {
|
|
2629 clcf->auto_redirect = 1;
|
|
2630 }
|
|
2631
|
58
|
2632 value = cf->args->elts;
|
|
2633
|
430
|
2634 url = &value[1];
|
|
2635
|
|
2636 n = ngx_http_script_variables_count(url);
|
|
2637
|
|
2638 if (n) {
|
|
2639
|
|
2640 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
2641
|
|
2642 sc.cf = cf;
|
|
2643 sc.source = url;
|
|
2644 sc.lengths = &flcf->fastcgi_lengths;
|
|
2645 sc.values = &flcf->fastcgi_values;
|
|
2646 sc.variables = n;
|
|
2647 sc.complete_lengths = 1;
|
|
2648 sc.complete_values = 1;
|
|
2649
|
|
2650 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
2651 return NGX_CONF_ERROR;
|
|
2652 }
|
|
2653
|
|
2654 return NGX_CONF_OK;
|
|
2655 }
|
|
2656
|
200
|
2657 ngx_memzero(&u, sizeof(ngx_url_t));
|
|
2658
|
|
2659 u.url = value[1];
|
260
|
2660 u.no_resolve = 1;
|
|
2661
|
430
|
2662 flcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0);
|
|
2663 if (flcf->upstream.upstream == NULL) {
|
58
|
2664 return NGX_CONF_ERROR;
|
|
2665 }
|
|
2666
|
|
2667 return NGX_CONF_OK;
|
|
2668 }
|
|
2669
|
|
2670
|
|
2671 static char *
|
438
|
2672 ngx_http_fastcgi_split_path_info(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
2673 {
|
|
2674 #if (NGX_PCRE)
|
|
2675 ngx_http_fastcgi_loc_conf_t *flcf = conf;
|
|
2676
|
546
|
2677 ngx_str_t *value;
|
|
2678 ngx_regex_compile_t rc;
|
|
2679 u_char errstr[NGX_MAX_CONF_ERRSTR];
|
438
|
2680
|
|
2681 value = cf->args->elts;
|
|
2682
|
|
2683 flcf->split_name = value[1];
|
|
2684
|
546
|
2685 ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
|
|
2686
|
|
2687 rc.pattern = value[1];
|
|
2688 rc.pool = cf->pool;
|
|
2689 rc.err.len = NGX_MAX_CONF_ERRSTR;
|
|
2690 rc.err.data = errstr;
|
|
2691
|
|
2692 if (ngx_regex_compile(&rc) != NGX_OK) {
|
|
2693 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err);
|
438
|
2694 return NGX_CONF_ERROR;
|
|
2695 }
|
|
2696
|
546
|
2697 if (rc.captures != 2) {
|
438
|
2698 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2699 "pattern \"%V\" must have 2 captures", &value[1]);
|
|
2700 return NGX_CONF_ERROR;
|
|
2701 }
|
|
2702
|
546
|
2703 flcf->split_regex = rc.regex;
|
|
2704
|
438
|
2705 return NGX_CONF_OK;
|
|
2706
|
|
2707 #else
|
|
2708
|
|
2709 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2710 "\"%V\" requires PCRE library", &cmd->name);
|
|
2711 return NGX_CONF_ERROR;
|
|
2712
|
|
2713 #endif
|
|
2714 }
|
|
2715
|
|
2716
|
|
2717 static char *
|
320
|
2718 ngx_http_fastcgi_store(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
2719 {
|
|
2720 ngx_http_fastcgi_loc_conf_t *flcf = conf;
|
|
2721
|
|
2722 ngx_str_t *value;
|
|
2723 ngx_http_script_compile_t sc;
|
|
2724
|
496
|
2725 if (flcf->upstream.store != NGX_CONF_UNSET
|
|
2726 || flcf->upstream.store_lengths)
|
320
|
2727 {
|
|
2728 return "is duplicate";
|
|
2729 }
|
|
2730
|
|
2731 value = cf->args->elts;
|
|
2732
|
496
|
2733 if (ngx_strcmp(value[1].data, "off") == 0) {
|
|
2734 flcf->upstream.store = 0;
|
320
|
2735 return NGX_CONF_OK;
|
|
2736 }
|
|
2737
|
496
|
2738 #if (NGX_HTTP_CACHE)
|
|
2739
|
|
2740 if (flcf->upstream.cache != NGX_CONF_UNSET_PTR
|
|
2741 && flcf->upstream.cache != NULL)
|
|
2742 {
|
|
2743 return "is incompatible with \"fastcgi_cache\"";
|
|
2744 }
|
|
2745
|
|
2746 #endif
|
|
2747
|
|
2748 if (ngx_strcmp(value[1].data, "on") == 0) {
|
|
2749 flcf->upstream.store = 1;
|
320
|
2750 return NGX_CONF_OK;
|
|
2751 }
|
|
2752
|
|
2753 /* include the terminating '\0' into script */
|
|
2754 value[1].len++;
|
|
2755
|
|
2756 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
2757
|
|
2758 sc.cf = cf;
|
|
2759 sc.source = &value[1];
|
|
2760 sc.lengths = &flcf->upstream.store_lengths;
|
|
2761 sc.values = &flcf->upstream.store_values;
|
340
|
2762 sc.variables = ngx_http_script_variables_count(&value[1]);
|
320
|
2763 sc.complete_lengths = 1;
|
|
2764 sc.complete_values = 1;
|
|
2765
|
|
2766 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
2767 return NGX_CONF_ERROR;
|
|
2768 }
|
|
2769
|
|
2770 return NGX_CONF_OK;
|
|
2771 }
|
|
2772
|
|
2773
|
466
|
2774 #if (NGX_HTTP_CACHE)
|
|
2775
|
|
2776 static char *
|
|
2777 ngx_http_fastcgi_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
2778 {
|
|
2779 ngx_http_fastcgi_loc_conf_t *flcf = conf;
|
|
2780
|
|
2781 ngx_str_t *value;
|
|
2782
|
|
2783 value = cf->args->elts;
|
|
2784
|
|
2785 if (flcf->upstream.cache != NGX_CONF_UNSET_PTR) {
|
|
2786 return "is duplicate";
|
|
2787 }
|
|
2788
|
|
2789 if (ngx_strcmp(value[1].data, "off") == 0) {
|
|
2790 flcf->upstream.cache = NULL;
|
|
2791 return NGX_CONF_OK;
|
|
2792 }
|
|
2793
|
496
|
2794 if (flcf->upstream.store > 0 || flcf->upstream.store_lengths) {
|
|
2795 return "is incompatible with \"fastcgi_store\"";
|
|
2796 }
|
|
2797
|
466
|
2798 flcf->upstream.cache = ngx_shared_memory_add(cf, &value[1], 0,
|
|
2799 &ngx_http_fastcgi_module);
|
|
2800 if (flcf->upstream.cache == NULL) {
|
|
2801 return NGX_CONF_ERROR;
|
|
2802 }
|
|
2803
|
|
2804 return NGX_CONF_OK;
|
|
2805 }
|
|
2806
|
|
2807
|
|
2808 static char *
|
|
2809 ngx_http_fastcgi_cache_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
2810 {
|
|
2811 ngx_http_fastcgi_loc_conf_t *flcf = conf;
|
|
2812
|
|
2813 ngx_str_t *value;
|
|
2814 ngx_http_compile_complex_value_t ccv;
|
|
2815
|
|
2816 value = cf->args->elts;
|
|
2817
|
|
2818 if (flcf->cache_key.value.len) {
|
|
2819 return "is duplicate";
|
|
2820 }
|
|
2821
|
|
2822 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
|
|
2823
|
|
2824 ccv.cf = cf;
|
|
2825 ccv.value = &value[1];
|
|
2826 ccv.complex_value = &flcf->cache_key;
|
|
2827
|
|
2828 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
|
|
2829 return NGX_CONF_ERROR;
|
|
2830 }
|
|
2831
|
|
2832 return NGX_CONF_OK;
|
|
2833 }
|
|
2834
|
|
2835 #endif
|
|
2836
|
|
2837
|
320
|
2838 static char *
|
58
|
2839 ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, void *data)
|
|
2840 {
|
|
2841 #if (NGX_FREEBSD)
|
|
2842 ssize_t *np = data;
|
|
2843
|
222
|
2844 if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) {
|
58
|
2845 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2846 "\"fastcgi_send_lowat\" must be less than %d "
|
|
2847 "(sysctl net.inet.tcp.sendspace)",
|
|
2848 ngx_freebsd_net_inet_tcp_sendspace);
|
|
2849
|
|
2850 return NGX_CONF_ERROR;
|
|
2851 }
|
|
2852
|
|
2853 #elif !(NGX_HAVE_SO_SNDLOWAT)
|
|
2854 ssize_t *np = data;
|
|
2855
|
|
2856 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
2857 "\"fastcgi_send_lowat\" is not supported, ignored");
|
|
2858
|
|
2859 *np = 0;
|
|
2860
|
|
2861 #endif
|
|
2862
|
|
2863 return NGX_CONF_OK;
|
|
2864 }
|