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