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);
|
370
|
642
|
|
643 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
644 "fastcgi param: \"%*s: %*s\"",
|
|
645 key_len, e.pos - (key_len + val_len),
|
|
646 val_len, e.pos - val_len);
|
50
|
647 }
|
|
648
|
58
|
649 b->last = e.pos;
|
50
|
650 }
|
|
651
|
|
652
|
58
|
653 if (flcf->upstream.pass_request_headers) {
|
50
|
654
|
58
|
655 part = &r->headers_in.headers.part;
|
|
656 header = part->elts;
|
50
|
657
|
58
|
658 for (i = 0; /* void */; i++) {
|
50
|
659
|
58
|
660 if (i >= part->nelts) {
|
|
661 if (part->next == NULL) {
|
126
|
662 break;
|
58
|
663 }
|
126
|
664
|
58
|
665 part = part->next;
|
|
666 header = part->elts;
|
|
667 i = 0;
|
|
668 }
|
50
|
669
|
58
|
670 len = sizeof("HTTP_") - 1 + header[i].key.len;
|
|
671 if (len > 127) {
|
|
672 *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80);
|
|
673 *b->last++ = (u_char) ((len >> 16) & 0xff);
|
|
674 *b->last++ = (u_char) ((len >> 8) & 0xff);
|
|
675 *b->last++ = (u_char) (len & 0xff);
|
126
|
676
|
58
|
677 } else {
|
|
678 *b->last++ = (u_char) len;
|
50
|
679 }
|
|
680
|
58
|
681 len = header[i].value.len;
|
|
682 if (len > 127) {
|
|
683 *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80);
|
|
684 *b->last++ = (u_char) ((len >> 16) & 0xff);
|
|
685 *b->last++ = (u_char) ((len >> 8) & 0xff);
|
|
686 *b->last++ = (u_char) (len & 0xff);
|
50
|
687
|
58
|
688 } else {
|
|
689 *b->last++ = (u_char) len;
|
50
|
690 }
|
|
691
|
58
|
692 b->last = ngx_cpymem(b->last, "HTTP_", sizeof("HTTP_") - 1);
|
50
|
693
|
58
|
694 for (n = 0; n < header[i].key.len; n++) {
|
|
695 ch = header[i].key.data[n];
|
50
|
696
|
58
|
697 if (ch >= 'a' && ch <= 'z') {
|
|
698 ch &= ~0x20;
|
50
|
699
|
58
|
700 } else if (ch == '-') {
|
|
701 ch = '_';
|
|
702 }
|
50
|
703
|
58
|
704 *b->last++ = ch;
|
50
|
705 }
|
|
706
|
122
|
707 b->last = ngx_copy(b->last, header[i].value.data,
|
|
708 header[i].value.len);
|
50
|
709 }
|
|
710 }
|
|
711
|
|
712
|
|
713 if (padding) {
|
|
714 ngx_memzero(b->last, padding);
|
|
715 b->last += padding;
|
|
716 }
|
|
717
|
|
718
|
|
719 h = (ngx_http_fastcgi_header_t *) b->last;
|
|
720 b->last += sizeof(ngx_http_fastcgi_header_t);
|
|
721
|
|
722 h->version = 1;
|
|
723 h->type = NGX_HTTP_FASTCGI_PARAMS;
|
|
724 h->request_id_hi = 0;
|
|
725 h->request_id_lo = 1;
|
|
726 h->content_length_hi = 0;
|
|
727 h->content_length_lo = 0;
|
|
728 h->padding_length = 0;
|
|
729 h->reserved = 0;
|
|
730
|
|
731 h = (ngx_http_fastcgi_header_t *) b->last;
|
|
732 b->last += sizeof(ngx_http_fastcgi_header_t);
|
|
733
|
58
|
734 if (flcf->upstream.pass_request_body) {
|
|
735 body = r->upstream->request_bufs;
|
|
736 r->upstream->request_bufs = cl;
|
50
|
737
|
|
738 #if (NGX_SUPPRESS_WARN)
|
58
|
739 file_pos = 0;
|
|
740 pos = NULL;
|
50
|
741 #endif
|
|
742
|
58
|
743 while (body) {
|
50
|
744
|
58
|
745 if (body->buf->in_file) {
|
|
746 file_pos = body->buf->file_pos;
|
50
|
747
|
58
|
748 } else {
|
|
749 pos = body->buf->pos;
|
50
|
750 }
|
|
751
|
58
|
752 next = 0;
|
50
|
753
|
58
|
754 do {
|
|
755 b = ngx_alloc_buf(r->pool);
|
|
756 if (b == NULL) {
|
|
757 return NGX_ERROR;
|
50
|
758 }
|
|
759
|
58
|
760 ngx_memcpy(b, body->buf, sizeof(ngx_buf_t));
|
|
761
|
|
762 if (body->buf->in_file) {
|
|
763 b->file_pos = file_pos;
|
|
764 file_pos += 32 * 1024;
|
50
|
765
|
292
|
766 if (file_pos >= body->buf->file_last) {
|
58
|
767 file_pos = body->buf->file_last;
|
|
768 next = 1;
|
|
769 }
|
|
770
|
|
771 b->file_last = file_pos;
|
|
772 len = (ngx_uint_t) (file_pos - b->file_pos);
|
|
773
|
|
774 } else {
|
|
775 b->pos = pos;
|
|
776 pos += 32 * 1024;
|
50
|
777
|
292
|
778 if (pos >= body->buf->last) {
|
58
|
779 pos = body->buf->last;
|
|
780 next = 1;
|
|
781 }
|
|
782
|
|
783 b->last = pos;
|
|
784 len = (ngx_uint_t) (pos - b->pos);
|
|
785 }
|
50
|
786
|
58
|
787 padding = 8 - len % 8;
|
|
788 padding = (padding == 8) ? 0 : padding;
|
50
|
789
|
58
|
790 h->version = 1;
|
|
791 h->type = NGX_HTTP_FASTCGI_STDIN;
|
|
792 h->request_id_hi = 0;
|
|
793 h->request_id_lo = 1;
|
|
794 h->content_length_hi = (u_char) ((len >> 8) & 0xff);
|
|
795 h->content_length_lo = (u_char) (len & 0xff);
|
|
796 h->padding_length = (u_char) padding;
|
|
797 h->reserved = 0;
|
50
|
798
|
58
|
799 cl->next = ngx_alloc_chain_link(r->pool);
|
|
800 if (cl->next == NULL) {
|
|
801 return NGX_ERROR;
|
|
802 }
|
50
|
803
|
58
|
804 cl = cl->next;
|
|
805 cl->buf = b;
|
|
806
|
|
807 b = ngx_create_temp_buf(r->pool,
|
|
808 sizeof(ngx_http_fastcgi_header_t)
|
|
809 + padding);
|
|
810 if (b == NULL) {
|
|
811 return NGX_ERROR;
|
|
812 }
|
50
|
813
|
58
|
814 if (padding) {
|
|
815 ngx_memzero(b->last, padding);
|
|
816 b->last += padding;
|
|
817 }
|
|
818
|
|
819 h = (ngx_http_fastcgi_header_t *) b->last;
|
|
820 b->last += sizeof(ngx_http_fastcgi_header_t);
|
50
|
821
|
58
|
822 cl->next = ngx_alloc_chain_link(r->pool);
|
|
823 if (cl->next == NULL) {
|
|
824 return NGX_ERROR;
|
|
825 }
|
|
826
|
|
827 cl = cl->next;
|
|
828 cl->buf = b;
|
50
|
829
|
58
|
830 } while (!next);
|
50
|
831
|
58
|
832 body = body->next;
|
|
833 }
|
50
|
834
|
58
|
835 } else {
|
|
836 r->upstream->request_bufs = cl;
|
50
|
837 }
|
|
838
|
|
839 h->version = 1;
|
|
840 h->type = NGX_HTTP_FASTCGI_STDIN;
|
|
841 h->request_id_hi = 0;
|
|
842 h->request_id_lo = 1;
|
|
843 h->content_length_hi = 0;
|
|
844 h->content_length_lo = 0;
|
|
845 h->padding_length = 0;
|
|
846 h->reserved = 0;
|
|
847
|
|
848 cl->next = NULL;
|
|
849
|
|
850 return NGX_OK;
|
|
851 }
|
|
852
|
|
853
|
|
854 static ngx_int_t
|
|
855 ngx_http_fastcgi_reinit_request(ngx_http_request_t *r)
|
|
856 {
|
|
857 ngx_http_fastcgi_ctx_t *f;
|
|
858
|
|
859 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
|
|
860
|
|
861 if (f == NULL) {
|
|
862 return NGX_OK;
|
|
863 }
|
|
864
|
|
865 f->state = ngx_http_fastcgi_st_version;
|
164
|
866 f->fastcgi_stdout = 0;
|
50
|
867
|
|
868 return NGX_OK;
|
|
869 }
|
|
870
|
|
871
|
56
|
872 static ngx_int_t
|
|
873 ngx_http_fastcgi_process_header(ngx_http_request_t *r)
|
50
|
874 {
|
316
|
875 u_char *p, *start, *last, *part_start;
|
|
876 size_t size;
|
306
|
877 ngx_str_t *status_line, line, *pattern;
|
58
|
878 ngx_int_t rc, status;
|
316
|
879 ngx_buf_t buf;
|
198
|
880 ngx_uint_t i;
|
58
|
881 ngx_table_elt_t *h;
|
|
882 ngx_http_upstream_t *u;
|
|
883 ngx_http_fastcgi_ctx_t *f;
|
|
884 ngx_http_upstream_header_t *hh;
|
306
|
885 ngx_http_fastcgi_loc_conf_t *flcf;
|
316
|
886 ngx_http_fastcgi_split_part_t *part;
|
58
|
887 ngx_http_upstream_main_conf_t *umcf;
|
50
|
888
|
|
889 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
|
|
890
|
58
|
891 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);
|
|
892
|
50
|
893 if (f == NULL) {
|
|
894 f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t));
|
|
895 if (f == NULL) {
|
356
|
896 return NGX_ERROR;
|
50
|
897 }
|
|
898
|
|
899 ngx_http_set_ctx(r, f, ngx_http_fastcgi_module);
|
|
900 }
|
|
901
|
|
902 u = r->upstream;
|
|
903
|
|
904 for ( ;; ) {
|
|
905
|
|
906 if (f->state < ngx_http_fastcgi_st_data) {
|
|
907
|
130
|
908 f->pos = u->buffer.pos;
|
|
909 f->last = u->buffer.last;
|
50
|
910
|
|
911 rc = ngx_http_fastcgi_process_record(r, f);
|
|
912
|
130
|
913 u->buffer.pos = f->pos;
|
|
914 u->buffer.last = f->last;
|
50
|
915
|
|
916 if (rc == NGX_AGAIN) {
|
|
917 return NGX_AGAIN;
|
|
918 }
|
|
919
|
|
920 if (rc == NGX_ERROR) {
|
|
921 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
|
922 }
|
|
923
|
|
924 if (f->type != NGX_HTTP_FASTCGI_STDOUT
|
|
925 && f->type != NGX_HTTP_FASTCGI_STDERR)
|
|
926 {
|
|
927 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
928 "upstream sent unexpected FastCGI record: %d",
|
|
929 f->type);
|
|
930
|
|
931 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
|
932 }
|
|
933
|
|
934 if (f->type == NGX_HTTP_FASTCGI_STDOUT && f->length == 0) {
|
|
935 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
936 "upstream closed prematurely FastCGI stdout");
|
|
937
|
|
938 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
|
939 }
|
|
940 }
|
|
941
|
|
942 if (f->state == ngx_http_fastcgi_st_padding) {
|
|
943
|
130
|
944 if (u->buffer.pos + f->padding < u->buffer.last) {
|
50
|
945 f->state = ngx_http_fastcgi_st_version;
|
130
|
946 u->buffer.pos += f->padding;
|
50
|
947
|
|
948 continue;
|
|
949 }
|
|
950
|
130
|
951 if (u->buffer.pos + f->padding == u->buffer.last) {
|
50
|
952 f->state = ngx_http_fastcgi_st_version;
|
130
|
953 u->buffer.pos = u->buffer.last;
|
50
|
954
|
|
955 return NGX_AGAIN;
|
|
956 }
|
|
957
|
130
|
958 f->padding -= u->buffer.last - u->buffer.pos;
|
|
959 u->buffer.pos = u->buffer.last;
|
50
|
960
|
|
961 return NGX_AGAIN;
|
|
962 }
|
|
963
|
|
964
|
|
965 /* f->state == ngx_http_fastcgi_st_data */
|
|
966
|
|
967 if (f->type == NGX_HTTP_FASTCGI_STDERR) {
|
|
968
|
|
969 if (f->length) {
|
130
|
970 line.data = u->buffer.pos;
|
50
|
971
|
130
|
972 if (u->buffer.pos + f->length <= u->buffer.last) {
|
50
|
973 line.len = f->length;
|
130
|
974 u->buffer.pos += f->length;
|
50
|
975 f->length = 0;
|
|
976 f->state = ngx_http_fastcgi_st_padding;
|
|
977
|
126
|
978 } else {
|
130
|
979 line.len = u->buffer.last - u->buffer.pos;
|
|
980 f->length -= u->buffer.last - u->buffer.pos;
|
|
981 u->buffer.pos = u->buffer.last;
|
50
|
982 }
|
|
983
|
|
984 while (line.data[line.len - 1] == LF
|
|
985 || line.data[line.len - 1] == CR
|
|
986 || line.data[line.len - 1] == '.'
|
|
987 || line.data[line.len - 1] == ' ')
|
|
988 {
|
|
989 line.len--;
|
|
990 }
|
|
991
|
|
992 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
993 "FastCGI sent in stderr: \"%V\"", &line);
|
|
994
|
306
|
995 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
|
|
996
|
|
997 if (flcf->catch_stderr) {
|
|
998 pattern = flcf->catch_stderr->elts;
|
|
999
|
|
1000 line.data[line.len - 1] = '\0';
|
|
1001
|
|
1002 for (i = 0; i < flcf->catch_stderr->nelts; i++) {
|
|
1003 if (ngx_strstr(line.data, pattern[i].data)) {
|
356
|
1004 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
306
|
1005 }
|
|
1006 }
|
|
1007 }
|
|
1008
|
130
|
1009 if (u->buffer.pos == u->buffer.last) {
|
164
|
1010
|
|
1011 if (!f->fastcgi_stdout) {
|
|
1012
|
|
1013 /*
|
|
1014 * the special handling the large number
|
|
1015 * of the PHP warnings to not allocate memory
|
|
1016 */
|
|
1017
|
|
1018 u->buffer.pos = u->buffer.start;
|
|
1019 u->buffer.last = u->buffer.start;
|
|
1020 }
|
|
1021
|
50
|
1022 return NGX_AGAIN;
|
|
1023 }
|
|
1024
|
|
1025 } else {
|
|
1026 f->state = ngx_http_fastcgi_st_version;
|
|
1027 }
|
|
1028
|
|
1029 continue;
|
|
1030 }
|
|
1031
|
|
1032
|
|
1033 /* f->type == NGX_HTTP_FASTCGI_STDOUT */
|
|
1034
|
164
|
1035 f->fastcgi_stdout = 1;
|
|
1036
|
130
|
1037 start = u->buffer.pos;
|
50
|
1038
|
130
|
1039 if (u->buffer.pos + f->length < u->buffer.last) {
|
50
|
1040
|
|
1041 /*
|
130
|
1042 * set u->buffer.last to the end of the FastCGI record data
|
50
|
1043 * for ngx_http_parse_header_line()
|
|
1044 */
|
|
1045
|
130
|
1046 last = u->buffer.last;
|
|
1047 u->buffer.last = u->buffer.pos + f->length;
|
50
|
1048
|
|
1049 } else {
|
|
1050 last = NULL;
|
|
1051 }
|
|
1052
|
|
1053 for ( ;; ) {
|
|
1054
|
316
|
1055 part_start = u->buffer.pos;
|
|
1056
|
130
|
1057 rc = ngx_http_parse_header_line(r, &u->buffer);
|
50
|
1058
|
|
1059 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1060 "http fastcgi parser: %d", rc);
|
|
1061
|
|
1062 if (rc == NGX_AGAIN) {
|
|
1063 break;
|
|
1064 }
|
|
1065
|
|
1066 if (rc == NGX_OK) {
|
|
1067
|
|
1068 /* a header line has been parsed successfully */
|
|
1069
|
58
|
1070 h = ngx_list_push(&u->headers_in.headers);
|
50
|
1071 if (h == NULL) {
|
356
|
1072 return NGX_ERROR;
|
50
|
1073 }
|
|
1074
|
316
|
1075 if (f->split_parts && f->split_parts->nelts) {
|
|
1076
|
|
1077 part = f->split_parts->elts;
|
|
1078 size = u->buffer.pos - part_start;
|
|
1079
|
|
1080 for (i = 0; i < f->split_parts->nelts; i++) {
|
|
1081 size += part[i].end - part[i].start;
|
|
1082 }
|
|
1083
|
|
1084 p = ngx_palloc(r->pool, size);
|
|
1085 if (p == NULL) {
|
356
|
1086 return NGX_ERROR;
|
316
|
1087 }
|
|
1088
|
|
1089 buf.pos = p;
|
|
1090
|
|
1091 for (i = 0; i < f->split_parts->nelts; i++) {
|
|
1092 p = ngx_cpymem(p, part[i].start,
|
|
1093 part[i].end - part[i].start);
|
|
1094 }
|
|
1095
|
|
1096 p = ngx_cpymem(p, part_start, u->buffer.pos - part_start);
|
|
1097
|
|
1098 buf.last = p;
|
|
1099
|
|
1100 f->split_parts->nelts = 0;
|
|
1101
|
|
1102 rc = ngx_http_parse_header_line(r, &buf);
|
|
1103
|
|
1104 h->key.len = r->header_name_end - r->header_name_start;
|
|
1105 h->key.data = r->header_name_start;
|
|
1106 h->key.data[h->key.len] = '\0';
|
|
1107
|
|
1108 h->value.len = r->header_end - r->header_start;
|
|
1109 h->value.data = r->header_start;
|
|
1110 h->value.data[h->value.len] = '\0';
|
|
1111
|
|
1112 h->lowcase_key = ngx_palloc(r->pool, h->key.len);
|
|
1113 if (h->lowcase_key == NULL) {
|
356
|
1114 return NGX_ERROR;
|
316
|
1115 }
|
|
1116
|
|
1117 } else {
|
|
1118
|
|
1119 h->key.len = r->header_name_end - r->header_name_start;
|
|
1120 h->value.len = r->header_end - r->header_start;
|
|
1121
|
|
1122 h->key.data = ngx_palloc(r->pool,
|
|
1123 h->key.len + 1 + h->value.len + 1
|
|
1124 + h->key.len);
|
|
1125 if (h->key.data == NULL) {
|
356
|
1126 return NGX_ERROR;
|
316
|
1127 }
|
|
1128
|
|
1129 h->value.data = h->key.data + h->key.len + 1;
|
|
1130 h->lowcase_key = h->key.data + h->key.len + 1
|
|
1131 + h->value.len + 1;
|
|
1132
|
|
1133 ngx_cpystrn(h->key.data, r->header_name_start,
|
|
1134 h->key.len + 1);
|
|
1135 ngx_cpystrn(h->value.data, r->header_start,
|
|
1136 h->value.len + 1);
|
|
1137 }
|
|
1138
|
58
|
1139 h->hash = r->header_hash;
|
|
1140
|
198
|
1141 if (h->key.len == r->lowcase_index) {
|
|
1142 ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len);
|
|
1143
|
|
1144 } else {
|
|
1145 for (i = 0; i < h->key.len; i++) {
|
336
|
1146 h->lowcase_key[i] = ngx_tolower(h->key.data[i]);
|
50
|
1147 }
|
|
1148 }
|
|
1149
|
198
|
1150 hh = ngx_hash_find(&umcf->headers_in_hash, h->hash,
|
|
1151 h->lowcase_key, h->key.len);
|
|
1152
|
|
1153 if (hh && hh->handler(r, h, hh->offset) != NGX_OK) {
|
356
|
1154 return NGX_ERROR;
|
198
|
1155 }
|
|
1156
|
50
|
1157 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1158 "http fastcgi header: \"%V: %V\"",
|
|
1159 &h->key, &h->value);
|
|
1160
|
164
|
1161 if (u->buffer.pos < u->buffer.last) {
|
|
1162 continue;
|
|
1163 }
|
|
1164
|
|
1165 /* the end of the FastCGI record */
|
|
1166
|
|
1167 break;
|
50
|
1168 }
|
|
1169
|
|
1170 if (rc == NGX_HTTP_PARSE_HEADER_DONE) {
|
|
1171
|
|
1172 /* a whole header has been parsed successfully */
|
|
1173
|
|
1174 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1175 "http fastcgi header done");
|
|
1176
|
58
|
1177 if (u->headers_in.status) {
|
|
1178 status_line = &u->headers_in.status->value;
|
50
|
1179
|
|
1180 status = ngx_atoi(status_line->data, 3);
|
|
1181
|
|
1182 if (status == NGX_ERROR) {
|
356
|
1183 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1184 "upstream sent invalid status \"%V\"",
|
|
1185 status_line);
|
|
1186 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
50
|
1187 }
|
|
1188
|
78
|
1189 u->headers_in.status_n = status;
|
|
1190 u->headers_in.status_line = *status_line;
|
50
|
1191
|
380
|
1192 } else if (u->headers_in.location) {
|
|
1193 u->headers_in.status_n = 302;
|
|
1194 u->headers_in.status_line.len =
|
|
1195 sizeof("302 Moved Temporarily") - 1;
|
|
1196 u->headers_in.status_line.data =
|
|
1197 (u_char *) "302 Moved Temporarily";
|
|
1198
|
50
|
1199 } else {
|
78
|
1200 u->headers_in.status_n = 200;
|
|
1201 u->headers_in.status_line.len = sizeof("200 OK") - 1;
|
|
1202 u->headers_in.status_line.data = (u_char *) "200 OK";
|
50
|
1203 }
|
|
1204
|
78
|
1205 u->state->status = u->headers_in.status_n;
|
50
|
1206 #if 0
|
340
|
1207 if (u->cacheable) {
|
|
1208 u->cacheable = ngx_http_upstream_is_cacheable(r);
|
50
|
1209 }
|
|
1210 #endif
|
|
1211
|
|
1212 break;
|
|
1213 }
|
|
1214
|
|
1215 /* there was error while a header line parsing */
|
|
1216
|
|
1217 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
168
|
1218 "upstream sent invalid header");
|
50
|
1219
|
|
1220 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
|
1221 }
|
|
1222
|
|
1223 if (last) {
|
130
|
1224 u->buffer.last = last;
|
50
|
1225 }
|
|
1226
|
130
|
1227 f->length -= u->buffer.pos - start;
|
50
|
1228
|
|
1229 if (f->length == 0) {
|
|
1230 if (f->padding) {
|
|
1231 f->state = ngx_http_fastcgi_st_padding;
|
|
1232 } else {
|
|
1233 f->state = ngx_http_fastcgi_st_version;
|
|
1234 }
|
|
1235 }
|
|
1236
|
164
|
1237 if (rc == NGX_HTTP_PARSE_HEADER_DONE) {
|
|
1238 return NGX_OK;
|
|
1239 }
|
|
1240
|
316
|
1241 if (rc == NGX_OK) {
|
374
|
1242 continue;
|
164
|
1243 }
|
|
1244
|
316
|
1245 /* rc == NGX_AGAIN */
|
|
1246
|
|
1247 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1248 "upstream split a header line in FastCGI records");
|
|
1249
|
|
1250 if (f->split_parts == NULL) {
|
|
1251 f->split_parts = ngx_array_create(r->pool, 1,
|
|
1252 sizeof(ngx_http_fastcgi_split_part_t));
|
|
1253 if (f->split_parts == NULL) {
|
356
|
1254 return NGX_ERROR;
|
316
|
1255 }
|
164
|
1256 }
|
316
|
1257
|
|
1258 part = ngx_array_push(f->split_parts);
|
|
1259
|
|
1260 part->start = part_start;
|
|
1261 part->end = u->buffer.last;
|
|
1262
|
|
1263 return NGX_AGAIN;
|
50
|
1264 }
|
|
1265 }
|
|
1266
|
|
1267
|
|
1268 static ngx_int_t
|
|
1269 ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
|
|
1270 {
|
|
1271 ngx_int_t rc;
|
|
1272 ngx_buf_t *b, **prev;
|
|
1273 ngx_str_t line;
|
|
1274 ngx_chain_t *cl;
|
|
1275 ngx_http_request_t *r;
|
|
1276 ngx_http_fastcgi_ctx_t *f;
|
|
1277
|
|
1278 if (buf->pos == buf->last) {
|
|
1279 return NGX_OK;
|
|
1280 }
|
|
1281
|
|
1282 r = p->input_ctx;
|
|
1283 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
|
|
1284
|
|
1285 b = NULL;
|
|
1286 prev = &buf->shadow;
|
|
1287
|
|
1288 f->pos = buf->pos;
|
|
1289 f->last = buf->last;
|
|
1290
|
|
1291 for ( ;; ) {
|
|
1292 if (f->state < ngx_http_fastcgi_st_data) {
|
|
1293
|
|
1294 rc = ngx_http_fastcgi_process_record(r, f);
|
|
1295
|
|
1296 if (rc == NGX_AGAIN) {
|
|
1297 break;
|
|
1298 }
|
|
1299
|
|
1300 if (rc == NGX_ERROR) {
|
|
1301 return NGX_ERROR;
|
|
1302 }
|
|
1303
|
|
1304 if (f->type == NGX_HTTP_FASTCGI_STDOUT && f->length == 0) {
|
|
1305 f->state = ngx_http_fastcgi_st_version;
|
|
1306 p->upstream_done = 1;
|
|
1307
|
|
1308 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, p->log, 0,
|
|
1309 "http fastcgi closed stdout");
|
|
1310
|
|
1311 continue;
|
|
1312 }
|
|
1313
|
|
1314 if (f->type == NGX_HTTP_FASTCGI_END_REQUEST) {
|
|
1315 f->state = ngx_http_fastcgi_st_version;
|
|
1316 p->upstream_done = 1;
|
|
1317
|
|
1318 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, p->log, 0,
|
|
1319 "http fastcgi sent end request");
|
|
1320
|
|
1321 break;
|
|
1322 }
|
|
1323 }
|
|
1324
|
|
1325
|
|
1326 if (f->state == ngx_http_fastcgi_st_padding) {
|
|
1327
|
|
1328 if (f->pos + f->padding < f->last) {
|
|
1329 f->state = ngx_http_fastcgi_st_version;
|
|
1330 f->pos += f->padding;
|
|
1331
|
|
1332 continue;
|
|
1333 }
|
|
1334
|
|
1335 if (f->pos + f->padding == f->last) {
|
|
1336 f->state = ngx_http_fastcgi_st_version;
|
|
1337
|
|
1338 break;
|
|
1339 }
|
|
1340
|
|
1341 f->padding -= f->last - f->pos;
|
|
1342
|
|
1343 break;
|
|
1344 }
|
|
1345
|
|
1346
|
|
1347 /* f->state == ngx_http_fastcgi_st_data */
|
|
1348
|
|
1349 if (f->type == NGX_HTTP_FASTCGI_STDERR) {
|
|
1350
|
|
1351 if (f->length) {
|
188
|
1352
|
|
1353 if (f->pos == f->last) {
|
|
1354 break;
|
|
1355 }
|
|
1356
|
50
|
1357 line.data = f->pos;
|
|
1358
|
|
1359 if (f->pos + f->length <= f->last) {
|
|
1360 line.len = f->length;
|
|
1361 f->pos += f->length;
|
|
1362 f->length = 0;
|
|
1363 f->state = ngx_http_fastcgi_st_padding;
|
|
1364
|
126
|
1365 } else {
|
50
|
1366 line.len = f->last - f->pos;
|
|
1367 f->length -= f->last - f->pos;
|
|
1368 f->pos = f->last;
|
|
1369 }
|
|
1370
|
|
1371 while (line.data[line.len - 1] == LF
|
|
1372 || line.data[line.len - 1] == CR
|
|
1373 || line.data[line.len - 1] == '.'
|
|
1374 || line.data[line.len - 1] == ' ')
|
|
1375 {
|
|
1376 line.len--;
|
|
1377 }
|
|
1378
|
|
1379 ngx_log_error(NGX_LOG_ERR, p->log, 0,
|
|
1380 "FastCGI sent in stderr: \"%V\"", &line);
|
|
1381
|
|
1382 if (f->pos == f->last) {
|
|
1383 break;
|
|
1384 }
|
|
1385
|
|
1386 } else {
|
|
1387 f->state = ngx_http_fastcgi_st_version;
|
|
1388 }
|
|
1389
|
|
1390 continue;
|
|
1391 }
|
|
1392
|
|
1393
|
|
1394 /* f->type == NGX_HTTP_FASTCGI_STDOUT */
|
|
1395
|
188
|
1396 if (f->pos == f->last) {
|
|
1397 break;
|
|
1398 }
|
|
1399
|
50
|
1400 if (p->free) {
|
|
1401 b = p->free->buf;
|
|
1402 p->free = p->free->next;
|
|
1403
|
|
1404 } else {
|
|
1405 b = ngx_alloc_buf(p->pool);
|
|
1406 if (b == NULL) {
|
|
1407 return NGX_ERROR;
|
|
1408 }
|
|
1409 }
|
|
1410
|
|
1411 ngx_memzero(b, sizeof(ngx_buf_t));
|
|
1412
|
|
1413 b->pos = f->pos;
|
|
1414 b->start = buf->start;
|
|
1415 b->end = buf->end;
|
|
1416 b->tag = p->tag;
|
|
1417 b->temporary = 1;
|
|
1418 b->recycled = 1;
|
|
1419
|
|
1420 *prev = b;
|
|
1421 prev = &b->shadow;
|
|
1422
|
|
1423 cl = ngx_alloc_chain_link(p->pool);
|
|
1424 if (cl == NULL) {
|
|
1425 return NGX_ERROR;
|
|
1426 }
|
|
1427
|
|
1428 cl->buf = b;
|
|
1429 cl->next = NULL;
|
|
1430
|
|
1431 if (p->in) {
|
|
1432 *p->last_in = cl;
|
|
1433 } else {
|
|
1434 p->in = cl;
|
|
1435 }
|
|
1436 p->last_in = &cl->next;
|
|
1437
|
|
1438
|
|
1439 /* STUB */ b->num = buf->num;
|
|
1440
|
274
|
1441 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0,
|
276
|
1442 "input buf #%d %p", b->num, b->pos);
|
50
|
1443
|
|
1444 if (f->pos + f->length < f->last) {
|
|
1445
|
|
1446 if (f->padding) {
|
|
1447 f->state = ngx_http_fastcgi_st_padding;
|
|
1448 } else {
|
|
1449 f->state = ngx_http_fastcgi_st_version;
|
|
1450 }
|
|
1451
|
|
1452 f->pos += f->length;
|
|
1453 b->last = f->pos;
|
|
1454
|
|
1455 continue;
|
|
1456 }
|
|
1457
|
|
1458 if (f->pos + f->length == f->last) {
|
|
1459
|
|
1460 if (f->padding) {
|
|
1461 f->state = ngx_http_fastcgi_st_padding;
|
|
1462 } else {
|
|
1463 f->state = ngx_http_fastcgi_st_version;
|
|
1464 }
|
|
1465
|
|
1466 b->last = f->last;
|
|
1467
|
|
1468 break;
|
|
1469 }
|
|
1470
|
|
1471 f->length -= f->last - f->pos;
|
|
1472
|
|
1473 b->last = f->last;
|
|
1474
|
|
1475 break;
|
|
1476
|
|
1477 }
|
|
1478
|
|
1479 if (b) {
|
|
1480 b->shadow = buf;
|
|
1481 b->last_shadow = 1;
|
|
1482
|
274
|
1483 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0,
|
276
|
1484 "input buf %p %z", b->pos, b->last - b->pos);
|
274
|
1485
|
50
|
1486 return NGX_OK;
|
|
1487 }
|
|
1488
|
|
1489 /* there is no data record in the buf, add it to free chain */
|
|
1490
|
|
1491 if (ngx_event_pipe_add_free_buf(p, buf) != NGX_OK) {
|
|
1492 return NGX_ERROR;
|
|
1493 }
|
|
1494
|
|
1495 return NGX_OK;
|
|
1496 }
|
|
1497
|
|
1498
|
|
1499 static ngx_int_t
|
|
1500 ngx_http_fastcgi_process_record(ngx_http_request_t *r,
|
|
1501 ngx_http_fastcgi_ctx_t *f)
|
|
1502 {
|
|
1503 u_char ch, *p;
|
|
1504 ngx_http_fastcgi_state_e state;
|
|
1505
|
|
1506 state = f->state;
|
|
1507
|
|
1508 for (p = f->pos; p < f->last; p++) {
|
|
1509
|
|
1510 ch = *p;
|
|
1511
|
|
1512 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1513 "http fastcgi record byte: %02Xd", ch);
|
|
1514
|
|
1515 switch (state) {
|
|
1516
|
|
1517 case ngx_http_fastcgi_st_version:
|
|
1518 if (ch != 1) {
|
|
1519 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1520 "upstream sent unsupported FastCGI "
|
|
1521 "protocol version: %d", ch);
|
|
1522 return NGX_ERROR;
|
|
1523 }
|
|
1524 state = ngx_http_fastcgi_st_type;
|
|
1525 break;
|
|
1526
|
|
1527 case ngx_http_fastcgi_st_type:
|
|
1528 switch (ch) {
|
|
1529 case NGX_HTTP_FASTCGI_STDOUT:
|
|
1530 case NGX_HTTP_FASTCGI_STDERR:
|
|
1531 case NGX_HTTP_FASTCGI_END_REQUEST:
|
|
1532 f->type = (ngx_uint_t) ch;
|
|
1533 break;
|
|
1534 default:
|
|
1535 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1536 "upstream sent invalid FastCGI "
|
|
1537 "record type: %d", ch);
|
|
1538 return NGX_ERROR;
|
|
1539
|
|
1540 }
|
|
1541 state = ngx_http_fastcgi_st_request_id_hi;
|
|
1542 break;
|
|
1543
|
|
1544 /* we support the single request per connection */
|
|
1545
|
|
1546 case ngx_http_fastcgi_st_request_id_hi:
|
|
1547 if (ch != 0) {
|
|
1548 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1549 "upstream sent unexpected FastCGI "
|
|
1550 "request id high byte: %d", ch);
|
|
1551 return NGX_ERROR;
|
|
1552 }
|
|
1553 state = ngx_http_fastcgi_st_request_id_lo;
|
|
1554 break;
|
|
1555
|
|
1556 case ngx_http_fastcgi_st_request_id_lo:
|
|
1557 if (ch != 1) {
|
|
1558 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1559 "upstream sent unexpected FastCGI "
|
|
1560 "request id low byte: %d", ch);
|
|
1561 return NGX_ERROR;
|
|
1562 }
|
|
1563 state = ngx_http_fastcgi_st_content_length_hi;
|
|
1564 break;
|
|
1565
|
|
1566 case ngx_http_fastcgi_st_content_length_hi:
|
|
1567 f->length = ch << 8;
|
|
1568 state = ngx_http_fastcgi_st_content_length_lo;
|
|
1569 break;
|
|
1570
|
|
1571 case ngx_http_fastcgi_st_content_length_lo:
|
|
1572 f->length |= (size_t) ch;
|
|
1573 state = ngx_http_fastcgi_st_padding_length;
|
|
1574 break;
|
|
1575
|
|
1576 case ngx_http_fastcgi_st_padding_length:
|
|
1577 f->padding = (size_t) ch;
|
|
1578 state = ngx_http_fastcgi_st_reserved;
|
|
1579 break;
|
|
1580
|
|
1581 case ngx_http_fastcgi_st_reserved:
|
|
1582 state = ngx_http_fastcgi_st_data;
|
|
1583
|
|
1584 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1585 "http fastcgi record length: %z", f->length);
|
|
1586
|
|
1587 f->pos = p + 1;
|
|
1588 f->state = state;
|
|
1589
|
|
1590 return NGX_OK;
|
|
1591
|
|
1592 /* suppress warning */
|
|
1593 case ngx_http_fastcgi_st_data:
|
|
1594 case ngx_http_fastcgi_st_padding:
|
|
1595 break;
|
|
1596 }
|
|
1597 }
|
|
1598
|
|
1599 f->state = state;
|
|
1600
|
|
1601 return NGX_AGAIN;
|
|
1602 }
|
|
1603
|
|
1604
|
|
1605 static void
|
|
1606 ngx_http_fastcgi_abort_request(ngx_http_request_t *r)
|
|
1607 {
|
|
1608 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1609 "abort http fastcgi request");
|
|
1610
|
|
1611 return;
|
|
1612 }
|
|
1613
|
|
1614
|
|
1615 static void
|
|
1616 ngx_http_fastcgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
|
|
1617 {
|
|
1618 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1619 "finalize http fastcgi request");
|
|
1620
|
|
1621 return;
|
|
1622 }
|
|
1623
|
|
1624
|
58
|
1625 static ngx_int_t
|
|
1626 ngx_http_fastcgi_add_variables(ngx_conf_t *cf)
|
50
|
1627 {
|
58
|
1628 ngx_http_variable_t *var;
|
50
|
1629
|
132
|
1630 var = ngx_http_add_variable(cf, &ngx_http_fastcgi_script_name,
|
340
|
1631 NGX_HTTP_VAR_NOHASH|NGX_HTTP_VAR_NOCACHEABLE);
|
58
|
1632 if (var == NULL) {
|
|
1633 return NGX_ERROR;
|
50
|
1634 }
|
|
1635
|
186
|
1636 var->get_handler = ngx_http_fastcgi_script_name_variable;
|
50
|
1637
|
58
|
1638 return NGX_OK;
|
50
|
1639 }
|
|
1640
|
|
1641
|
|
1642 static void *
|
|
1643 ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf)
|
|
1644 {
|
|
1645 ngx_http_fastcgi_loc_conf_t *conf;
|
|
1646
|
|
1647 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_fastcgi_loc_conf_t));
|
|
1648 if (conf == NULL) {
|
|
1649 return NGX_CONF_ERROR;
|
|
1650 }
|
|
1651
|
|
1652 /*
|
|
1653 * set by ngx_pcalloc():
|
|
1654 *
|
|
1655 * conf->upstream.bufs.num = 0;
|
|
1656 * conf->upstream.next_upstream = 0;
|
|
1657 * conf->upstream.temp_path = NULL;
|
198
|
1658 * conf->upstream.hide_headers_hash = { NULL, 0 };
|
58
|
1659 * conf->upstream.schema = { 0, NULL };
|
|
1660 * conf->upstream.uri = { 0, NULL };
|
|
1661 * conf->upstream.location = NULL;
|
320
|
1662 * conf->upstream.store_lengths = NULL;
|
|
1663 * conf->upstream.store_values = NULL;
|
58
|
1664 *
|
50
|
1665 * conf->index.len = 0;
|
|
1666 * conf->index.data = NULL;
|
|
1667 */
|
|
1668
|
320
|
1669 conf->upstream.store = NGX_CONF_UNSET;
|
|
1670 conf->upstream.store_access = NGX_CONF_UNSET_UINT;
|
130
|
1671 conf->upstream.buffering = NGX_CONF_UNSET;
|
178
|
1672 conf->upstream.ignore_client_abort = NGX_CONF_UNSET;
|
130
|
1673
|
50
|
1674 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC;
|
|
1675 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC;
|
56
|
1676 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC;
|
|
1677
|
50
|
1678 conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE;
|
130
|
1679 conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE;
|
78
|
1680
|
|
1681 conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE;
|
126
|
1682 conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
|
78
|
1683 conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE;
|
58
|
1684
|
|
1685 conf->upstream.pass_request_headers = NGX_CONF_UNSET;
|
|
1686 conf->upstream.pass_request_body = NGX_CONF_UNSET;
|
|
1687
|
356
|
1688 conf->upstream.hide_headers = NGX_CONF_UNSET_PTR;
|
|
1689 conf->upstream.pass_headers = NGX_CONF_UNSET_PTR;
|
|
1690
|
206
|
1691 conf->upstream.intercept_errors = NGX_CONF_UNSET;
|
50
|
1692
|
|
1693 /* "fastcgi_cyclic_temp_file" is disabled */
|
|
1694 conf->upstream.cyclic_temp_file = 0;
|
|
1695
|
332
|
1696 conf->catch_stderr = NGX_CONF_UNSET_PTR;
|
|
1697
|
50
|
1698 return conf;
|
|
1699 }
|
|
1700
|
|
1701
|
|
1702 static char *
|
|
1703 ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
|
1704 {
|
|
1705 ngx_http_fastcgi_loc_conf_t *prev = parent;
|
|
1706 ngx_http_fastcgi_loc_conf_t *conf = child;
|
|
1707
|
58
|
1708 u_char *p;
|
|
1709 size_t size;
|
|
1710 uintptr_t *code;
|
356
|
1711 ngx_uint_t i;
|
198
|
1712 ngx_keyval_t *src;
|
|
1713 ngx_hash_init_t hash;
|
58
|
1714 ngx_http_script_compile_t sc;
|
|
1715 ngx_http_script_copy_code_t *copy;
|
50
|
1716
|
320
|
1717 if (conf->upstream.store != 0) {
|
|
1718 ngx_conf_merge_value(conf->upstream.store,
|
|
1719 prev->upstream.store, 0);
|
|
1720
|
|
1721 if (conf->upstream.store_lengths == NULL) {
|
|
1722 conf->upstream.store_lengths = prev->upstream.store_lengths;
|
|
1723 conf->upstream.store_values = prev->upstream.store_values;
|
|
1724 }
|
|
1725 }
|
|
1726
|
|
1727 ngx_conf_merge_uint_value(conf->upstream.store_access,
|
|
1728 prev->upstream.store_access, 0600);
|
318
|
1729
|
130
|
1730 ngx_conf_merge_value(conf->upstream.buffering,
|
|
1731 prev->upstream.buffering, 1);
|
|
1732
|
178
|
1733 ngx_conf_merge_value(conf->upstream.ignore_client_abort,
|
|
1734 prev->upstream.ignore_client_abort, 0);
|
|
1735
|
50
|
1736 ngx_conf_merge_msec_value(conf->upstream.connect_timeout,
|
|
1737 prev->upstream.connect_timeout, 60000);
|
56
|
1738
|
50
|
1739 ngx_conf_merge_msec_value(conf->upstream.send_timeout,
|
|
1740 prev->upstream.send_timeout, 60000);
|
|
1741
|
|
1742 ngx_conf_merge_msec_value(conf->upstream.read_timeout,
|
|
1743 prev->upstream.read_timeout, 60000);
|
|
1744
|
56
|
1745 ngx_conf_merge_size_value(conf->upstream.send_lowat,
|
|
1746 prev->upstream.send_lowat, 0);
|
50
|
1747
|
130
|
1748 ngx_conf_merge_size_value(conf->upstream.buffer_size,
|
|
1749 prev->upstream.buffer_size,
|
50
|
1750 (size_t) ngx_pagesize);
|
|
1751
|
56
|
1752
|
50
|
1753 ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs,
|
|
1754 8, ngx_pagesize);
|
|
1755
|
|
1756 if (conf->upstream.bufs.num < 2) {
|
|
1757 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1758 "there must be at least 2 \"fastcgi_buffers\"");
|
|
1759 return NGX_CONF_ERROR;
|
|
1760 }
|
|
1761
|
|
1762
|
130
|
1763 size = conf->upstream.buffer_size;
|
50
|
1764 if (size < conf->upstream.bufs.size) {
|
|
1765 size = conf->upstream.bufs.size;
|
|
1766 }
|
|
1767
|
|
1768
|
78
|
1769 ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf,
|
|
1770 prev->upstream.busy_buffers_size_conf,
|
50
|
1771 NGX_CONF_UNSET_SIZE);
|
|
1772
|
78
|
1773 if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) {
|
50
|
1774 conf->upstream.busy_buffers_size = 2 * size;
|
78
|
1775 } else {
|
|
1776 conf->upstream.busy_buffers_size =
|
|
1777 conf->upstream.busy_buffers_size_conf;
|
|
1778 }
|
50
|
1779
|
78
|
1780 if (conf->upstream.busy_buffers_size < size) {
|
50
|
1781 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1782 "\"fastcgi_busy_buffers_size\" must be equal or bigger than "
|
288
|
1783 "maximum of the value of \"fastcgi_buffer_size\" and "
|
50
|
1784 "one of the \"fastcgi_buffers\"");
|
|
1785
|
|
1786 return NGX_CONF_ERROR;
|
78
|
1787 }
|
50
|
1788
|
78
|
1789 if (conf->upstream.busy_buffers_size
|
|
1790 > (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size)
|
50
|
1791 {
|
|
1792 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1793 "\"fastcgi_busy_buffers_size\" must be less than "
|
|
1794 "the size of all \"fastcgi_buffers\" minus one buffer");
|
|
1795
|
|
1796 return NGX_CONF_ERROR;
|
|
1797 }
|
|
1798
|
|
1799
|
78
|
1800 ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf,
|
|
1801 prev->upstream.temp_file_write_size_conf,
|
50
|
1802 NGX_CONF_UNSET_SIZE);
|
|
1803
|
78
|
1804 if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) {
|
50
|
1805 conf->upstream.temp_file_write_size = 2 * size;
|
78
|
1806 } else {
|
|
1807 conf->upstream.temp_file_write_size =
|
|
1808 conf->upstream.temp_file_write_size_conf;
|
|
1809 }
|
50
|
1810
|
78
|
1811 if (conf->upstream.temp_file_write_size < size) {
|
50
|
1812 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1813 "\"fastcgi_temp_file_write_size\" must be equal or bigger than "
|
288
|
1814 "maximum of the value of \"fastcgi_buffer_size\" and "
|
50
|
1815 "one of the \"fastcgi_buffers\"");
|
|
1816
|
|
1817 return NGX_CONF_ERROR;
|
|
1818 }
|
|
1819
|
|
1820
|
78
|
1821 ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf,
|
|
1822 prev->upstream.max_temp_file_size_conf,
|
50
|
1823 NGX_CONF_UNSET_SIZE);
|
|
1824
|
78
|
1825 if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) {
|
50
|
1826 conf->upstream.max_temp_file_size = 1024 * 1024 * 1024;
|
78
|
1827 } else {
|
|
1828 conf->upstream.max_temp_file_size =
|
|
1829 conf->upstream.max_temp_file_size_conf;
|
|
1830 }
|
50
|
1831
|
78
|
1832 if (conf->upstream.max_temp_file_size != 0
|
|
1833 && conf->upstream.max_temp_file_size < size)
|
50
|
1834 {
|
|
1835 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1836 "\"fastcgi_max_temp_file_size\" must be equal to zero to disable "
|
|
1837 "the temporary files usage or must be equal or bigger than "
|
288
|
1838 "maximum of the value of \"fastcgi_buffer_size\" and "
|
50
|
1839 "one of the \"fastcgi_buffers\"");
|
|
1840
|
|
1841 return NGX_CONF_ERROR;
|
|
1842 }
|
|
1843
|
|
1844
|
|
1845 ngx_conf_merge_bitmask_value(conf->upstream.next_upstream,
|
|
1846 prev->upstream.next_upstream,
|
|
1847 (NGX_CONF_BITMASK_SET
|
|
1848 |NGX_HTTP_UPSTREAM_FT_ERROR
|
|
1849 |NGX_HTTP_UPSTREAM_FT_TIMEOUT));
|
|
1850
|
214
|
1851 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) {
|
|
1852 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET
|
|
1853 |NGX_HTTP_UPSTREAM_FT_OFF;
|
|
1854 }
|
|
1855
|
50
|
1856 ngx_conf_merge_path_value(conf->upstream.temp_path,
|
|
1857 prev->upstream.temp_path,
|
|
1858 NGX_HTTP_FASTCGI_TEMP_PATH, 1, 2, 0,
|
|
1859 ngx_garbage_collector_temp_handler, cf);
|
|
1860
|
58
|
1861 ngx_conf_merge_value(conf->upstream.pass_request_headers,
|
|
1862 prev->upstream.pass_request_headers, 1);
|
|
1863 ngx_conf_merge_value(conf->upstream.pass_request_body,
|
|
1864 prev->upstream.pass_request_body, 1);
|
|
1865
|
206
|
1866 ngx_conf_merge_value(conf->upstream.intercept_errors,
|
|
1867 prev->upstream.intercept_errors, 0);
|
58
|
1868
|
306
|
1869 ngx_conf_merge_ptr_value(conf->catch_stderr, prev->catch_stderr, NULL);
|
|
1870
|
56
|
1871
|
50
|
1872 ngx_conf_merge_str_value(conf->index, prev->index, "");
|
|
1873
|
356
|
1874 hash.max_size = 512;
|
|
1875 hash.bucket_size = ngx_align(64, ngx_cacheline_size);
|
|
1876 hash.name = "fastcgi_hide_headers_hash";
|
|
1877
|
|
1878 if (ngx_http_upstream_hide_headers_hash(cf, &conf->upstream,
|
|
1879 &prev->upstream,
|
|
1880 ngx_http_fastcgi_hide_headers,
|
|
1881 &hash)
|
198
|
1882 != NGX_OK)
|
|
1883 {
|
|
1884 return NGX_CONF_ERROR;
|
|
1885 }
|
|
1886
|
260
|
1887 if (conf->upstream.upstream == NULL) {
|
|
1888 conf->upstream.upstream = prev->upstream.upstream;
|
178
|
1889 conf->upstream.schema = prev->upstream.schema;
|
56
|
1890 }
|
|
1891
|
58
|
1892 if (conf->params_source == NULL) {
|
122
|
1893 conf->flushes = prev->flushes;
|
58
|
1894 conf->params_len = prev->params_len;
|
|
1895 conf->params = prev->params;
|
122
|
1896 conf->params_source = prev->params_source;
|
58
|
1897
|
|
1898 if (conf->params_source == NULL) {
|
|
1899 return NGX_CONF_OK;
|
|
1900 }
|
|
1901 }
|
|
1902
|
|
1903 conf->params_len = ngx_array_create(cf->pool, 64, 1);
|
|
1904 if (conf->params_len == NULL) {
|
|
1905 return NGX_CONF_ERROR;
|
|
1906 }
|
122
|
1907
|
58
|
1908 conf->params = ngx_array_create(cf->pool, 512, 1);
|
|
1909 if (conf->params == NULL) {
|
|
1910 return NGX_CONF_ERROR;
|
|
1911 }
|
|
1912
|
|
1913 src = conf->params_source->elts;
|
|
1914 for (i = 0; i < conf->params_source->nelts; i++) {
|
|
1915
|
|
1916 if (ngx_http_script_variables_count(&src[i].value) == 0) {
|
|
1917 copy = ngx_array_push_n(conf->params_len,
|
|
1918 sizeof(ngx_http_script_copy_code_t));
|
|
1919 if (copy == NULL) {
|
|
1920 return NGX_CONF_ERROR;
|
|
1921 }
|
|
1922
|
|
1923 copy->code = (ngx_http_script_code_pt)
|
|
1924 ngx_http_script_copy_len_code;
|
|
1925 copy->len = src[i].key.len;
|
|
1926
|
|
1927
|
|
1928 copy = ngx_array_push_n(conf->params_len,
|
|
1929 sizeof(ngx_http_script_copy_code_t));
|
|
1930 if (copy == NULL) {
|
|
1931 return NGX_CONF_ERROR;
|
|
1932 }
|
|
1933
|
|
1934 copy->code = (ngx_http_script_code_pt)
|
|
1935 ngx_http_script_copy_len_code;
|
|
1936 copy->len = src[i].value.len;
|
|
1937
|
|
1938
|
|
1939 size = (sizeof(ngx_http_script_copy_code_t)
|
|
1940 + src[i].key.len + src[i].value.len
|
|
1941 + sizeof(uintptr_t) - 1)
|
|
1942 & ~(sizeof(uintptr_t) - 1);
|
|
1943
|
|
1944 copy = ngx_array_push_n(conf->params, size);
|
|
1945 if (copy == NULL) {
|
|
1946 return NGX_CONF_ERROR;
|
|
1947 }
|
126
|
1948
|
58
|
1949 copy->code = ngx_http_script_copy_code;
|
|
1950 copy->len = src[i].key.len + src[i].value.len;
|
|
1951
|
|
1952 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t);
|
|
1953
|
|
1954 p = ngx_cpymem(p, src[i].key.data, src[i].key.len);
|
|
1955 ngx_memcpy(p, src[i].value.data, src[i].value.len);
|
|
1956
|
|
1957 } else {
|
|
1958 copy = ngx_array_push_n(conf->params_len,
|
|
1959 sizeof(ngx_http_script_copy_code_t));
|
|
1960 if (copy == NULL) {
|
|
1961 return NGX_CONF_ERROR;
|
|
1962 }
|
|
1963
|
|
1964 copy->code = (ngx_http_script_code_pt)
|
|
1965 ngx_http_script_copy_len_code;
|
|
1966 copy->len = src[i].key.len;
|
|
1967
|
|
1968
|
|
1969 size = (sizeof(ngx_http_script_copy_code_t)
|
|
1970 + src[i].key.len + sizeof(uintptr_t) - 1)
|
|
1971 & ~(sizeof(uintptr_t) - 1);
|
|
1972
|
|
1973 copy = ngx_array_push_n(conf->params, size);
|
|
1974 if (copy == NULL) {
|
|
1975 return NGX_CONF_ERROR;
|
|
1976 }
|
126
|
1977
|
58
|
1978 copy->code = ngx_http_script_copy_code;
|
|
1979 copy->len = src[i].key.len;
|
|
1980
|
|
1981 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t);
|
|
1982 ngx_memcpy(p, src[i].key.data, src[i].key.len);
|
|
1983
|
|
1984
|
|
1985 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
1986
|
|
1987 sc.cf = cf;
|
|
1988 sc.source = &src[i].value;
|
122
|
1989 sc.flushes = &conf->flushes;
|
58
|
1990 sc.lengths = &conf->params_len;
|
|
1991 sc.values = &conf->params;
|
|
1992
|
|
1993 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
1994 return NGX_CONF_ERROR;
|
|
1995 }
|
|
1996 }
|
|
1997
|
|
1998 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
|
|
1999 if (code == NULL) {
|
|
2000 return NGX_CONF_ERROR;
|
|
2001 }
|
|
2002
|
|
2003 *code = (uintptr_t) NULL;
|
|
2004
|
|
2005
|
|
2006 code = ngx_array_push_n(conf->params, sizeof(uintptr_t));
|
|
2007 if (code == NULL) {
|
|
2008 return NGX_CONF_ERROR;
|
|
2009 }
|
|
2010
|
|
2011 *code = (uintptr_t) NULL;
|
|
2012 }
|
|
2013
|
|
2014 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
|
|
2015 if (code == NULL) {
|
|
2016 return NGX_CONF_ERROR;
|
|
2017 }
|
|
2018
|
|
2019 *code = (uintptr_t) NULL;
|
|
2020
|
50
|
2021 return NGX_CONF_OK;
|
|
2022 }
|
58
|
2023
|
|
2024
|
122
|
2025 static ngx_int_t
|
|
2026 ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r,
|
|
2027 ngx_http_variable_value_t *v, uintptr_t data)
|
58
|
2028 {
|
|
2029 u_char *p;
|
|
2030 ngx_http_fastcgi_loc_conf_t *flcf;
|
|
2031
|
284
|
2032 if (r->uri.len) {
|
|
2033 v->valid = 1;
|
340
|
2034 v->no_cacheable = 0;
|
284
|
2035 v->not_found = 0;
|
|
2036
|
|
2037 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
|
|
2038
|
|
2039 if (r->uri.data[r->uri.len - 1] != '/') {
|
|
2040 v->len = r->uri.len;
|
|
2041 v->data = r->uri.data;
|
|
2042 return NGX_OK;
|
|
2043 }
|
|
2044
|
|
2045 v->len = r->uri.len + flcf->index.len;
|
|
2046
|
|
2047 v->data = ngx_palloc(r->pool, v->len);
|
|
2048 if (v->data == NULL) {
|
|
2049 return NGX_ERROR;
|
|
2050 }
|
|
2051
|
|
2052 p = ngx_copy(v->data, r->uri.data, r->uri.len);
|
|
2053 ngx_memcpy(p, flcf->index.data, flcf->index.len);
|
|
2054
|
|
2055 } else {
|
|
2056 v->len = 0;
|
|
2057 v->valid = 1;
|
340
|
2058 v->no_cacheable = 0;
|
284
|
2059 v->not_found = 0;
|
|
2060 v->data = NULL;
|
|
2061
|
122
|
2062 return NGX_OK;
|
58
|
2063 }
|
|
2064
|
122
|
2065 return NGX_OK;
|
58
|
2066 }
|
|
2067
|
|
2068
|
|
2069 static char *
|
|
2070 ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
2071 {
|
|
2072 ngx_http_fastcgi_loc_conf_t *lcf = conf;
|
|
2073
|
200
|
2074 ngx_url_t u;
|
58
|
2075 ngx_str_t *value;
|
|
2076 ngx_http_core_loc_conf_t *clcf;
|
|
2077
|
104
|
2078 if (lcf->upstream.schema.len) {
|
|
2079 return "is duplicate";
|
|
2080 }
|
|
2081
|
58
|
2082 value = cf->args->elts;
|
|
2083
|
200
|
2084 ngx_memzero(&u, sizeof(ngx_url_t));
|
|
2085
|
|
2086 u.url = value[1];
|
260
|
2087 u.no_resolve = 1;
|
|
2088
|
|
2089 lcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0);
|
|
2090 if (lcf->upstream.upstream == NULL) {
|
58
|
2091 return NGX_CONF_ERROR;
|
|
2092 }
|
|
2093
|
|
2094 lcf->upstream.schema.len = sizeof("fastcgi://") - 1;
|
|
2095 lcf->upstream.schema.data = (u_char *) "fastcgi://";
|
|
2096
|
|
2097 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
|
|
2098
|
|
2099 clcf->handler = ngx_http_fastcgi_handler;
|
|
2100
|
|
2101 if (clcf->name.data[clcf->name.len - 1] == '/') {
|
|
2102 clcf->auto_redirect = 1;
|
|
2103 }
|
|
2104
|
|
2105 return NGX_CONF_OK;
|
|
2106 }
|
|
2107
|
|
2108
|
|
2109 static char *
|
320
|
2110 ngx_http_fastcgi_store(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
2111 {
|
|
2112 ngx_http_fastcgi_loc_conf_t *flcf = conf;
|
|
2113
|
|
2114 ngx_str_t *value;
|
|
2115 ngx_http_script_compile_t sc;
|
|
2116
|
|
2117 if (flcf->upstream.store != NGX_CONF_UNSET || flcf->upstream.store_lengths)
|
|
2118 {
|
|
2119 return "is duplicate";
|
|
2120 }
|
|
2121
|
|
2122 value = cf->args->elts;
|
|
2123
|
|
2124 if (ngx_strcmp(value[1].data, "on") == 0) {
|
|
2125 flcf->upstream.store = 1;
|
|
2126 return NGX_CONF_OK;
|
|
2127 }
|
|
2128
|
|
2129 if (ngx_strcmp(value[1].data, "off") == 0) {
|
|
2130 flcf->upstream.store = 0;
|
|
2131 return NGX_CONF_OK;
|
|
2132 }
|
|
2133
|
|
2134 /* include the terminating '\0' into script */
|
|
2135 value[1].len++;
|
|
2136
|
|
2137 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
2138
|
|
2139 sc.cf = cf;
|
|
2140 sc.source = &value[1];
|
|
2141 sc.lengths = &flcf->upstream.store_lengths;
|
|
2142 sc.values = &flcf->upstream.store_values;
|
340
|
2143 sc.variables = ngx_http_script_variables_count(&value[1]);
|
320
|
2144 sc.complete_lengths = 1;
|
|
2145 sc.complete_values = 1;
|
|
2146
|
|
2147 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
2148 return NGX_CONF_ERROR;
|
|
2149 }
|
|
2150
|
|
2151 return NGX_CONF_OK;
|
|
2152 }
|
|
2153
|
|
2154
|
|
2155 static char *
|
58
|
2156 ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, void *data)
|
|
2157 {
|
|
2158 #if (NGX_FREEBSD)
|
|
2159 ssize_t *np = data;
|
|
2160
|
222
|
2161 if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) {
|
58
|
2162 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2163 "\"fastcgi_send_lowat\" must be less than %d "
|
|
2164 "(sysctl net.inet.tcp.sendspace)",
|
|
2165 ngx_freebsd_net_inet_tcp_sendspace);
|
|
2166
|
|
2167 return NGX_CONF_ERROR;
|
|
2168 }
|
|
2169
|
|
2170 #elif !(NGX_HAVE_SO_SNDLOWAT)
|
|
2171 ssize_t *np = data;
|
|
2172
|
|
2173 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
2174 "\"fastcgi_send_lowat\" is not supported, ignored");
|
|
2175
|
|
2176 *np = 0;
|
|
2177
|
|
2178 #endif
|
|
2179
|
|
2180 return NGX_CONF_OK;
|
|
2181 }
|
260
|
2182
|
|
2183
|
|
2184 static char *
|
|
2185 ngx_http_fastcgi_upstream_max_fails_unsupported(ngx_conf_t *cf,
|
|
2186 ngx_command_t *cmd, void *conf)
|
|
2187 {
|
|
2188 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2189 "\"fastcgi_upstream_max_fails\" is not supported, "
|
|
2190 "use the \"max_fails\" parameter of the \"server\" directive ",
|
|
2191 "inside the \"upstream\" block");
|
|
2192
|
|
2193 return NGX_CONF_ERROR;
|
|
2194 }
|
|
2195
|
|
2196
|
|
2197 static char *
|
|
2198 ngx_http_fastcgi_upstream_fail_timeout_unsupported(ngx_conf_t *cf,
|
|
2199 ngx_command_t *cmd, void *conf)
|
|
2200 {
|
|
2201 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2202 "\"fastcgi_upstream_fail_timeout\" is not supported, "
|
|
2203 "use the \"fail_timeout\" parameter of the \"server\" directive ",
|
|
2204 "inside the \"upstream\" block");
|
|
2205
|
|
2206 return NGX_CONF_ERROR;
|
|
2207 }
|