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