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