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