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