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