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