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