580
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 * Copyright (C) Manlio Perillo (manlio.perillo@gmail.com)
|
|
5 */
|
|
6
|
|
7
|
|
8 #include <ngx_config.h>
|
|
9 #include <ngx_core.h>
|
|
10 #include <ngx_http.h>
|
|
11
|
|
12
|
|
13 typedef struct {
|
|
14 ngx_http_upstream_conf_t upstream;
|
|
15
|
|
16 ngx_array_t *flushes;
|
|
17 ngx_array_t *params_len;
|
|
18 ngx_array_t *params;
|
|
19 ngx_array_t *params_source;
|
|
20
|
|
21 ngx_hash_t headers_hash;
|
|
22 ngx_uint_t header_params;
|
|
23
|
|
24 ngx_array_t *scgi_lengths;
|
|
25 ngx_array_t *scgi_values;
|
|
26
|
|
27 #if (NGX_HTTP_CACHE)
|
|
28 ngx_http_complex_value_t cache_key;
|
|
29 #endif
|
|
30 } ngx_http_scgi_loc_conf_t;
|
|
31
|
|
32
|
|
33 static ngx_int_t ngx_http_scgi_eval(ngx_http_request_t *r,
|
|
34 ngx_http_scgi_loc_conf_t *scf);
|
|
35 static ngx_int_t ngx_http_scgi_create_request(ngx_http_request_t *r);
|
|
36 static ngx_int_t ngx_http_scgi_reinit_request(ngx_http_request_t *r);
|
|
37 static ngx_int_t ngx_http_scgi_process_status_line(ngx_http_request_t *r);
|
|
38 static ngx_int_t ngx_http_scgi_process_header(ngx_http_request_t *r);
|
|
39 static void ngx_http_scgi_abort_request(ngx_http_request_t *r);
|
|
40 static void ngx_http_scgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc);
|
|
41
|
|
42 static void *ngx_http_scgi_create_loc_conf(ngx_conf_t *cf);
|
|
43 static char *ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent,
|
|
44 void *child);
|
648
|
45 static ngx_int_t ngx_http_scgi_merge_params(ngx_conf_t *cf,
|
|
46 ngx_http_scgi_loc_conf_t *conf, ngx_http_scgi_loc_conf_t *prev);
|
580
|
47
|
|
48 static char *ngx_http_scgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
|
49 static char *ngx_http_scgi_store(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
50 void *conf);
|
|
51
|
|
52 #if (NGX_HTTP_CACHE)
|
|
53 static ngx_int_t ngx_http_scgi_create_key(ngx_http_request_t *r);
|
|
54 static char *ngx_http_scgi_cache(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
55 void *conf);
|
|
56 static char *ngx_http_scgi_cache_key(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
57 void *conf);
|
|
58 #endif
|
|
59
|
|
60
|
|
61 static ngx_conf_bitmask_t ngx_http_scgi_next_upstream_masks[] = {
|
|
62 { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR },
|
|
63 { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT },
|
|
64 { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER },
|
|
65 { ngx_string("http_500"), NGX_HTTP_UPSTREAM_FT_HTTP_500 },
|
|
66 { ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 },
|
|
67 { ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 },
|
|
68 { ngx_string("updating"), NGX_HTTP_UPSTREAM_FT_UPDATING },
|
|
69 { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF },
|
|
70 { ngx_null_string, 0 }
|
|
71 };
|
|
72
|
|
73
|
|
74 ngx_module_t ngx_http_scgi_module;
|
|
75
|
|
76
|
|
77 static ngx_command_t ngx_http_scgi_commands[] = {
|
|
78
|
|
79 { ngx_string("scgi_pass"),
|
|
80 NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
|
|
81 ngx_http_scgi_pass,
|
|
82 NGX_HTTP_LOC_CONF_OFFSET,
|
|
83 0,
|
|
84 NULL },
|
|
85
|
|
86 { ngx_string("scgi_store"),
|
|
87 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
88 ngx_http_scgi_store,
|
|
89 NGX_HTTP_LOC_CONF_OFFSET,
|
|
90 0,
|
|
91 NULL },
|
|
92
|
|
93 { ngx_string("scgi_store_access"),
|
|
94 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123,
|
|
95 ngx_conf_set_access_slot,
|
|
96 NGX_HTTP_LOC_CONF_OFFSET,
|
|
97 offsetof(ngx_http_scgi_loc_conf_t, upstream.store_access),
|
|
98 NULL },
|
|
99
|
642
|
100 { ngx_string("scgi_buffering"),
|
|
101 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
102 ngx_conf_set_flag_slot,
|
|
103 NGX_HTTP_LOC_CONF_OFFSET,
|
|
104 offsetof(ngx_http_scgi_loc_conf_t, upstream.buffering),
|
|
105 NULL },
|
|
106
|
580
|
107 { ngx_string("scgi_ignore_client_abort"),
|
|
108 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
109 ngx_conf_set_flag_slot,
|
|
110 NGX_HTTP_LOC_CONF_OFFSET,
|
|
111 offsetof(ngx_http_scgi_loc_conf_t, upstream.ignore_client_abort),
|
|
112 NULL },
|
|
113
|
|
114 { ngx_string("scgi_bind"),
|
|
115 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
116 ngx_http_upstream_bind_set_slot,
|
|
117 NGX_HTTP_LOC_CONF_OFFSET,
|
|
118 offsetof(ngx_http_scgi_loc_conf_t, upstream.local),
|
|
119 NULL },
|
|
120
|
|
121 { ngx_string("scgi_connect_timeout"),
|
|
122 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
123 ngx_conf_set_msec_slot,
|
|
124 NGX_HTTP_LOC_CONF_OFFSET,
|
|
125 offsetof(ngx_http_scgi_loc_conf_t, upstream.connect_timeout),
|
|
126 NULL },
|
|
127
|
|
128 { ngx_string("scgi_send_timeout"),
|
|
129 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
130 ngx_conf_set_msec_slot,
|
|
131 NGX_HTTP_LOC_CONF_OFFSET,
|
|
132 offsetof(ngx_http_scgi_loc_conf_t, upstream.send_timeout),
|
|
133 NULL },
|
|
134
|
|
135 { ngx_string("scgi_buffer_size"),
|
|
136 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
137 ngx_conf_set_size_slot,
|
|
138 NGX_HTTP_LOC_CONF_OFFSET,
|
|
139 offsetof(ngx_http_scgi_loc_conf_t, upstream.buffer_size),
|
|
140 NULL },
|
|
141
|
|
142 { ngx_string("scgi_pass_request_headers"),
|
|
143 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
144 ngx_conf_set_flag_slot,
|
|
145 NGX_HTTP_LOC_CONF_OFFSET,
|
|
146 offsetof(ngx_http_scgi_loc_conf_t, upstream.pass_request_headers),
|
|
147 NULL },
|
|
148
|
|
149 { ngx_string("scgi_pass_request_body"),
|
|
150 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
151 ngx_conf_set_flag_slot,
|
|
152 NGX_HTTP_LOC_CONF_OFFSET,
|
|
153 offsetof(ngx_http_scgi_loc_conf_t, upstream.pass_request_body),
|
|
154 NULL },
|
|
155
|
|
156 { ngx_string("scgi_intercept_errors"),
|
|
157 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
158 ngx_conf_set_flag_slot,
|
|
159 NGX_HTTP_LOC_CONF_OFFSET,
|
|
160 offsetof(ngx_http_scgi_loc_conf_t, upstream.intercept_errors),
|
|
161 NULL },
|
|
162
|
|
163 { ngx_string("scgi_read_timeout"),
|
|
164 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
165 ngx_conf_set_msec_slot,
|
|
166 NGX_HTTP_LOC_CONF_OFFSET,
|
|
167 offsetof(ngx_http_scgi_loc_conf_t, upstream.read_timeout),
|
|
168 NULL },
|
|
169
|
|
170 { ngx_string("scgi_buffers"),
|
|
171 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
|
|
172 ngx_conf_set_bufs_slot,
|
|
173 NGX_HTTP_LOC_CONF_OFFSET,
|
|
174 offsetof(ngx_http_scgi_loc_conf_t, upstream.bufs),
|
|
175 NULL },
|
|
176
|
|
177 { ngx_string("scgi_busy_buffers_size"),
|
|
178 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
179 ngx_conf_set_size_slot,
|
|
180 NGX_HTTP_LOC_CONF_OFFSET,
|
|
181 offsetof(ngx_http_scgi_loc_conf_t, upstream.busy_buffers_size_conf),
|
|
182 NULL },
|
|
183
|
|
184 #if (NGX_HTTP_CACHE)
|
|
185
|
|
186 { ngx_string("scgi_cache"),
|
592
|
187 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
580
|
188 ngx_http_scgi_cache,
|
|
189 NGX_HTTP_LOC_CONF_OFFSET,
|
|
190 0,
|
|
191 NULL },
|
|
192
|
|
193 { ngx_string("scgi_cache_key"),
|
592
|
194 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
580
|
195 ngx_http_scgi_cache_key,
|
|
196 NGX_HTTP_LOC_CONF_OFFSET,
|
|
197 0,
|
|
198 NULL },
|
|
199
|
|
200 { ngx_string("scgi_cache_path"),
|
|
201 NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE,
|
|
202 ngx_http_file_cache_set_slot,
|
|
203 0,
|
|
204 0,
|
|
205 &ngx_http_scgi_module },
|
|
206
|
588
|
207 { ngx_string("scgi_cache_bypass"),
|
|
208 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
209 ngx_http_set_predicate_slot,
|
|
210 NGX_HTTP_LOC_CONF_OFFSET,
|
|
211 offsetof(ngx_http_scgi_loc_conf_t, upstream.cache_bypass),
|
|
212 NULL },
|
|
213
|
580
|
214 { ngx_string("scgi_no_cache"),
|
|
215 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
588
|
216 ngx_http_set_predicate_slot,
|
580
|
217 NGX_HTTP_LOC_CONF_OFFSET,
|
|
218 offsetof(ngx_http_scgi_loc_conf_t, upstream.no_cache),
|
|
219 NULL },
|
|
220
|
|
221 { ngx_string("scgi_cache_valid"),
|
|
222 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
223 ngx_http_file_cache_valid_set_slot,
|
|
224 NGX_HTTP_LOC_CONF_OFFSET,
|
|
225 offsetof(ngx_http_scgi_loc_conf_t, upstream.cache_valid),
|
|
226 NULL },
|
|
227
|
|
228 { ngx_string("scgi_cache_min_uses"),
|
|
229 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
230 ngx_conf_set_num_slot,
|
|
231 NGX_HTTP_LOC_CONF_OFFSET,
|
|
232 offsetof(ngx_http_scgi_loc_conf_t, upstream.cache_min_uses),
|
|
233 NULL },
|
|
234
|
|
235 { ngx_string("scgi_cache_use_stale"),
|
|
236 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
237 ngx_conf_set_bitmask_slot,
|
|
238 NGX_HTTP_LOC_CONF_OFFSET,
|
|
239 offsetof(ngx_http_scgi_loc_conf_t, upstream.cache_use_stale),
|
|
240 &ngx_http_scgi_next_upstream_masks },
|
|
241
|
|
242 { ngx_string("scgi_cache_methods"),
|
|
243 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
244 ngx_conf_set_bitmask_slot,
|
|
245 NGX_HTTP_LOC_CONF_OFFSET,
|
|
246 offsetof(ngx_http_scgi_loc_conf_t, upstream.cache_methods),
|
|
247 &ngx_http_upstream_cache_method_mask },
|
|
248
|
656
|
249 { ngx_string("scgi_cache_lock"),
|
|
250 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
251 ngx_conf_set_flag_slot,
|
|
252 NGX_HTTP_LOC_CONF_OFFSET,
|
|
253 offsetof(ngx_http_scgi_loc_conf_t, upstream.cache_lock),
|
|
254 NULL },
|
|
255
|
|
256 { ngx_string("scgi_cache_lock_timeout"),
|
|
257 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
258 ngx_conf_set_msec_slot,
|
|
259 NGX_HTTP_LOC_CONF_OFFSET,
|
|
260 offsetof(ngx_http_scgi_loc_conf_t, upstream.cache_lock_timeout),
|
|
261 NULL },
|
|
262
|
580
|
263 #endif
|
|
264
|
|
265 { ngx_string("scgi_temp_path"),
|
|
266 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
|
|
267 ngx_conf_set_path_slot,
|
|
268 NGX_HTTP_LOC_CONF_OFFSET,
|
|
269 offsetof(ngx_http_scgi_loc_conf_t, upstream.temp_path),
|
|
270 NULL },
|
|
271
|
|
272 { ngx_string("scgi_max_temp_file_size"),
|
|
273 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
274 ngx_conf_set_size_slot,
|
|
275 NGX_HTTP_LOC_CONF_OFFSET,
|
|
276 offsetof(ngx_http_scgi_loc_conf_t, upstream.max_temp_file_size_conf),
|
|
277 NULL },
|
|
278
|
|
279 { ngx_string("scgi_temp_file_write_size"),
|
|
280 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
281 ngx_conf_set_size_slot,
|
|
282 NGX_HTTP_LOC_CONF_OFFSET,
|
|
283 offsetof(ngx_http_scgi_loc_conf_t, upstream.temp_file_write_size_conf),
|
|
284 NULL },
|
|
285
|
|
286 { ngx_string("scgi_next_upstream"),
|
|
287 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
288 ngx_conf_set_bitmask_slot,
|
|
289 NGX_HTTP_LOC_CONF_OFFSET,
|
|
290 offsetof(ngx_http_scgi_loc_conf_t, upstream.next_upstream),
|
|
291 &ngx_http_scgi_next_upstream_masks },
|
|
292
|
|
293 { ngx_string("scgi_param"),
|
654
|
294 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE23,
|
|
295 ngx_http_upstream_param_set_slot,
|
580
|
296 NGX_HTTP_LOC_CONF_OFFSET,
|
|
297 offsetof(ngx_http_scgi_loc_conf_t, params_source),
|
|
298 NULL },
|
|
299
|
|
300 { ngx_string("scgi_pass_header"),
|
592
|
301 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
580
|
302 ngx_conf_set_str_array_slot,
|
|
303 NGX_HTTP_LOC_CONF_OFFSET,
|
|
304 offsetof(ngx_http_scgi_loc_conf_t, upstream.pass_headers),
|
|
305 NULL },
|
|
306
|
|
307 { ngx_string("scgi_hide_header"),
|
592
|
308 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
580
|
309 ngx_conf_set_str_array_slot,
|
|
310 NGX_HTTP_LOC_CONF_OFFSET,
|
|
311 offsetof(ngx_http_scgi_loc_conf_t, upstream.hide_headers),
|
|
312 NULL },
|
|
313
|
|
314 { ngx_string("scgi_ignore_headers"),
|
|
315 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
316 ngx_conf_set_bitmask_slot,
|
|
317 NGX_HTTP_LOC_CONF_OFFSET,
|
|
318 offsetof(ngx_http_scgi_loc_conf_t, upstream.ignore_headers),
|
584
|
319 &ngx_http_upstream_ignore_headers_masks },
|
580
|
320
|
|
321 ngx_null_command
|
|
322 };
|
|
323
|
|
324
|
|
325 static ngx_http_module_t ngx_http_scgi_module_ctx = {
|
|
326 NULL, /* preconfiguration */
|
|
327 NULL, /* postconfiguration */
|
|
328
|
|
329 NULL, /* create main configuration */
|
|
330 NULL, /* init main configuration */
|
|
331
|
|
332 NULL, /* create server configuration */
|
|
333 NULL, /* merge server configuration */
|
|
334
|
|
335 ngx_http_scgi_create_loc_conf, /* create location configuration */
|
|
336 ngx_http_scgi_merge_loc_conf /* merge location configuration */
|
|
337 };
|
|
338
|
|
339
|
|
340 ngx_module_t ngx_http_scgi_module = {
|
|
341 NGX_MODULE_V1,
|
|
342 &ngx_http_scgi_module_ctx, /* module context */
|
|
343 ngx_http_scgi_commands, /* module directives */
|
|
344 NGX_HTTP_MODULE, /* module type */
|
|
345 NULL, /* init master */
|
|
346 NULL, /* init module */
|
|
347 NULL, /* init process */
|
|
348 NULL, /* init thread */
|
|
349 NULL, /* exit thread */
|
|
350 NULL, /* exit process */
|
|
351 NULL, /* exit master */
|
|
352 NGX_MODULE_V1_PADDING
|
|
353 };
|
|
354
|
|
355
|
|
356 static ngx_str_t ngx_http_scgi_hide_headers[] = {
|
|
357 ngx_string("Status"),
|
|
358 ngx_string("X-Accel-Expires"),
|
|
359 ngx_string("X-Accel-Redirect"),
|
|
360 ngx_string("X-Accel-Limit-Rate"),
|
|
361 ngx_string("X-Accel-Buffering"),
|
|
362 ngx_string("X-Accel-Charset"),
|
|
363 ngx_null_string
|
|
364 };
|
|
365
|
|
366
|
|
367 #if (NGX_HTTP_CACHE)
|
|
368
|
|
369 static ngx_keyval_t ngx_http_scgi_cache_headers[] = {
|
|
370 { ngx_string("HTTP_IF_MODIFIED_SINCE"), ngx_string("") },
|
|
371 { ngx_string("HTTP_IF_UNMODIFIED_SINCE"), ngx_string("") },
|
|
372 { ngx_string("HTTP_IF_NONE_MATCH"), ngx_string("") },
|
|
373 { ngx_string("HTTP_IF_MATCH"), ngx_string("") },
|
|
374 { ngx_string("HTTP_RANGE"), ngx_string("") },
|
|
375 { ngx_string("HTTP_IF_RANGE"), ngx_string("") },
|
|
376 { ngx_null_string, ngx_null_string }
|
|
377 };
|
|
378
|
|
379 #endif
|
|
380
|
|
381
|
|
382 static ngx_path_init_t ngx_http_scgi_temp_path = {
|
|
383 ngx_string(NGX_HTTP_SCGI_TEMP_PATH), { 1, 2, 0 }
|
|
384 };
|
|
385
|
|
386
|
|
387 static ngx_int_t
|
|
388 ngx_http_scgi_handler(ngx_http_request_t *r)
|
|
389 {
|
|
390 ngx_int_t rc;
|
|
391 ngx_http_status_t *status;
|
|
392 ngx_http_upstream_t *u;
|
|
393 ngx_http_scgi_loc_conf_t *scf;
|
|
394
|
|
395 if (r->subrequest_in_memory) {
|
|
396 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
|
397 "ngx_http_scgi_module does not support "
|
|
398 "subrequests in memory");
|
|
399 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
400 }
|
|
401
|
|
402 if (ngx_http_upstream_create(r) != NGX_OK) {
|
|
403 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
404 }
|
|
405
|
|
406 status = ngx_pcalloc(r->pool, sizeof(ngx_http_status_t));
|
|
407 if (status == NULL) {
|
|
408 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
409 }
|
|
410
|
|
411 ngx_http_set_ctx(r, status, ngx_http_scgi_module);
|
|
412
|
|
413 scf = ngx_http_get_module_loc_conf(r, ngx_http_scgi_module);
|
|
414
|
|
415 if (scf->scgi_lengths) {
|
|
416 if (ngx_http_scgi_eval(r, scf) != NGX_OK) {
|
|
417 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
418 }
|
|
419 }
|
|
420
|
|
421 u = r->upstream;
|
|
422
|
|
423 ngx_str_set(&u->schema, "scgi://");
|
|
424 u->output.tag = (ngx_buf_tag_t) &ngx_http_scgi_module;
|
|
425
|
|
426 u->conf = &scf->upstream;
|
|
427
|
|
428 #if (NGX_HTTP_CACHE)
|
|
429 u->create_key = ngx_http_scgi_create_key;
|
|
430 #endif
|
|
431 u->create_request = ngx_http_scgi_create_request;
|
|
432 u->reinit_request = ngx_http_scgi_reinit_request;
|
|
433 u->process_header = ngx_http_scgi_process_status_line;
|
|
434 u->abort_request = ngx_http_scgi_abort_request;
|
|
435 u->finalize_request = ngx_http_scgi_finalize_request;
|
|
436
|
642
|
437 u->buffering = scf->upstream.buffering;
|
580
|
438
|
|
439 u->pipe = ngx_pcalloc(r->pool, sizeof(ngx_event_pipe_t));
|
|
440 if (u->pipe == NULL) {
|
|
441 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
442 }
|
|
443
|
|
444 u->pipe->input_filter = ngx_event_pipe_copy_input_filter;
|
|
445 u->pipe->input_ctx = r;
|
|
446
|
|
447 rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init);
|
|
448
|
|
449 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
|
|
450 return rc;
|
|
451 }
|
|
452
|
|
453 return NGX_DONE;
|
|
454 }
|
|
455
|
|
456
|
|
457 static ngx_int_t
|
|
458 ngx_http_scgi_eval(ngx_http_request_t *r, ngx_http_scgi_loc_conf_t * scf)
|
|
459 {
|
|
460 ngx_url_t url;
|
|
461 ngx_http_upstream_t *u;
|
|
462
|
|
463 ngx_memzero(&url, sizeof(ngx_url_t));
|
|
464
|
|
465 if (ngx_http_script_run(r, &url.url, scf->scgi_lengths->elts, 0,
|
|
466 scf->scgi_values->elts)
|
|
467 == NULL)
|
|
468 {
|
|
469 return NGX_ERROR;
|
|
470 }
|
|
471
|
|
472 url.no_resolve = 1;
|
|
473
|
|
474 if (ngx_parse_url(r->pool, &url) != NGX_OK) {
|
|
475 if (url.err) {
|
|
476 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
477 "%s in upstream \"%V\"", url.err, &url.url);
|
|
478 }
|
|
479
|
|
480 return NGX_ERROR;
|
|
481 }
|
|
482
|
|
483 u = r->upstream;
|
|
484
|
|
485 u->resolved = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_resolved_t));
|
|
486 if (u->resolved == NULL) {
|
|
487 return NGX_ERROR;
|
|
488 }
|
|
489
|
|
490 if (url.addrs && url.addrs[0].sockaddr) {
|
|
491 u->resolved->sockaddr = url.addrs[0].sockaddr;
|
|
492 u->resolved->socklen = url.addrs[0].socklen;
|
|
493 u->resolved->naddrs = 1;
|
|
494 u->resolved->host = url.addrs[0].name;
|
|
495
|
|
496 } else {
|
|
497 u->resolved->host = url.host;
|
|
498 u->resolved->port = url.port;
|
618
|
499 u->resolved->no_port = url.no_port;
|
580
|
500 }
|
|
501
|
|
502 return NGX_OK;
|
|
503 }
|
|
504
|
|
505
|
|
506 #if (NGX_HTTP_CACHE)
|
|
507
|
|
508 static ngx_int_t
|
|
509 ngx_http_scgi_create_key(ngx_http_request_t *r)
|
|
510 {
|
|
511 ngx_str_t *key;
|
|
512 ngx_http_scgi_loc_conf_t *scf;
|
|
513
|
|
514 key = ngx_array_push(&r->cache->keys);
|
|
515 if (key == NULL) {
|
|
516 return NGX_ERROR;
|
|
517 }
|
|
518
|
|
519 scf = ngx_http_get_module_loc_conf(r, ngx_http_scgi_module);
|
|
520
|
|
521 if (ngx_http_complex_value(r, &scf->cache_key, key) != NGX_OK) {
|
|
522 return NGX_ERROR;
|
|
523 }
|
|
524
|
|
525 return NGX_OK;
|
|
526 }
|
|
527
|
|
528 #endif
|
|
529
|
|
530
|
|
531 static ngx_int_t
|
|
532 ngx_http_scgi_create_request(ngx_http_request_t *r)
|
|
533 {
|
|
534 u_char ch, *key, *val, *lowcase_key;
|
654
|
535 size_t len, key_len, val_len, allocated;
|
580
|
536 ngx_buf_t *b;
|
|
537 ngx_str_t *content_length;
|
654
|
538 ngx_uint_t i, n, hash, skip_empty, header_params;
|
580
|
539 ngx_chain_t *cl, *body;
|
|
540 ngx_list_part_t *part;
|
|
541 ngx_table_elt_t *header, **ignored;
|
|
542 ngx_http_script_code_pt code;
|
|
543 ngx_http_script_engine_t e, le;
|
|
544 ngx_http_scgi_loc_conf_t *scf;
|
|
545 ngx_http_script_len_code_pt lcode;
|
|
546 static ngx_str_t zero = ngx_string("0");
|
|
547
|
|
548 content_length = r->headers_in.content_length ?
|
|
549 &r->headers_in.content_length->value : &zero;
|
|
550
|
|
551 len = sizeof("CONTENT_LENGTH") + content_length->len + 1;
|
|
552
|
|
553 header_params = 0;
|
|
554 ignored = NULL;
|
|
555
|
|
556 scf = ngx_http_get_module_loc_conf(r, ngx_http_scgi_module);
|
|
557
|
|
558 if (scf->params_len) {
|
|
559 ngx_memzero(&le, sizeof(ngx_http_script_engine_t));
|
|
560
|
|
561 ngx_http_script_flush_no_cacheable_variables(r, scf->flushes);
|
|
562 le.flushed = 1;
|
|
563
|
|
564 le.ip = scf->params_len->elts;
|
|
565 le.request = r;
|
|
566
|
|
567 while (*(uintptr_t *) le.ip) {
|
|
568
|
|
569 lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
654
|
570 key_len = lcode(&le);
|
580
|
571
|
654
|
572 lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
|
573 skip_empty = lcode(&le);
|
|
574
|
|
575 for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode(&le)) {
|
580
|
576 lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
|
577 }
|
654
|
578 le.ip += sizeof(uintptr_t);
|
650
|
579
|
654
|
580 if (skip_empty && val_len == 0) {
|
|
581 continue;
|
|
582 }
|
|
583
|
|
584 len += key_len + val_len + 1;
|
580
|
585 }
|
|
586 }
|
|
587
|
|
588 if (scf->upstream.pass_request_headers) {
|
|
589
|
|
590 allocated = 0;
|
|
591 lowcase_key = NULL;
|
|
592
|
|
593 if (scf->header_params) {
|
634
|
594 n = 0;
|
|
595 part = &r->headers_in.headers.part;
|
|
596
|
|
597 while (part) {
|
|
598 n += part->nelts;
|
|
599 part = part->next;
|
|
600 }
|
|
601
|
|
602 ignored = ngx_palloc(r->pool, n * sizeof(void *));
|
580
|
603 if (ignored == NULL) {
|
|
604 return NGX_ERROR;
|
|
605 }
|
|
606 }
|
|
607
|
|
608 part = &r->headers_in.headers.part;
|
|
609 header = part->elts;
|
|
610
|
|
611 for (i = 0; /* void */; i++) {
|
|
612
|
|
613 if (i >= part->nelts) {
|
|
614 if (part->next == NULL) {
|
|
615 break;
|
|
616 }
|
|
617
|
|
618 part = part->next;
|
|
619 header = part->elts;
|
|
620 i = 0;
|
|
621 }
|
|
622
|
|
623 if (scf->header_params) {
|
|
624 if (allocated < header[i].key.len) {
|
|
625 allocated = header[i].key.len + 16;
|
|
626 lowcase_key = ngx_pnalloc(r->pool, allocated);
|
|
627 if (lowcase_key == NULL) {
|
|
628 return NGX_ERROR;
|
|
629 }
|
|
630 }
|
|
631
|
|
632 hash = 0;
|
|
633
|
|
634 for (n = 0; n < header[i].key.len; n++) {
|
|
635 ch = header[i].key.data[n];
|
|
636
|
|
637 if (ch >= 'A' && ch <= 'Z') {
|
|
638 ch |= 0x20;
|
|
639
|
|
640 } else if (ch == '-') {
|
|
641 ch = '_';
|
|
642 }
|
|
643
|
|
644 hash = ngx_hash(hash, ch);
|
|
645 lowcase_key[n] = ch;
|
|
646 }
|
|
647
|
|
648 if (ngx_hash_find(&scf->headers_hash, hash, lowcase_key, n)) {
|
|
649 ignored[header_params++] = &header[i];
|
|
650 continue;
|
|
651 }
|
|
652 }
|
|
653
|
|
654 len += sizeof("HTTP_") - 1 + header[i].key.len + 1
|
|
655 + header[i].value.len + 1;
|
|
656 }
|
|
657 }
|
|
658
|
|
659 /* netstring: "length:" + packet + "," */
|
|
660
|
|
661 b = ngx_create_temp_buf(r->pool, NGX_SIZE_T_LEN + 1 + len + 1);
|
|
662 if (b == NULL) {
|
|
663 return NGX_ERROR;
|
|
664 }
|
|
665
|
|
666 cl = ngx_alloc_chain_link(r->pool);
|
|
667 if (cl == NULL) {
|
|
668 return NGX_ERROR;
|
|
669 }
|
|
670
|
|
671 cl->buf = b;
|
|
672
|
|
673 b->last = ngx_snprintf(b->last,
|
|
674 NGX_SIZE_T_LEN + 1 + sizeof("CONTENT_LENGTH")
|
|
675 + NGX_OFF_T_LEN + 1,
|
|
676 "%ui:CONTENT_LENGTH%Z%V%Z",
|
|
677 len, content_length);
|
|
678
|
|
679 if (scf->params_len) {
|
|
680 ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
|
|
681
|
|
682 e.ip = scf->params->elts;
|
|
683 e.pos = b->last;
|
|
684 e.request = r;
|
|
685 e.flushed = 1;
|
|
686
|
654
|
687 le.ip = scf->params_len->elts;
|
|
688
|
|
689 while (*(uintptr_t *) le.ip) {
|
|
690
|
|
691 lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
|
692 lcode(&le); /* key length */
|
|
693
|
|
694 lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
|
695 skip_empty = lcode(&le);
|
|
696
|
|
697 for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode(&le)) {
|
|
698 lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
|
699 }
|
|
700 le.ip += sizeof(uintptr_t);
|
|
701
|
|
702 if (skip_empty && val_len == 0) {
|
|
703 e.skip = 1;
|
|
704
|
|
705 while (*(uintptr_t *) e.ip) {
|
|
706 code = *(ngx_http_script_code_pt *) e.ip;
|
|
707 code((ngx_http_script_engine_t *) &e);
|
|
708 }
|
|
709 e.ip += sizeof(uintptr_t);
|
|
710
|
|
711 e.skip = 0;
|
|
712
|
|
713 continue;
|
|
714 }
|
580
|
715
|
|
716 #if (NGX_DEBUG)
|
|
717 key = e.pos;
|
|
718 #endif
|
|
719 code = *(ngx_http_script_code_pt *) e.ip;
|
|
720 code((ngx_http_script_engine_t *) & e);
|
|
721
|
|
722 #if (NGX_DEBUG)
|
|
723 val = e.pos;
|
|
724 #endif
|
|
725 while (*(uintptr_t *) e.ip) {
|
|
726 code = *(ngx_http_script_code_pt *) e.ip;
|
|
727 code((ngx_http_script_engine_t *) &e);
|
|
728 }
|
|
729 *e.pos++ = '\0';
|
|
730 e.ip += sizeof(uintptr_t);
|
|
731
|
|
732 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
733 "scgi param: \"%s: %s\"", key, val);
|
|
734 }
|
|
735
|
|
736 b->last = e.pos;
|
|
737 }
|
|
738
|
|
739 if (scf->upstream.pass_request_headers) {
|
|
740
|
|
741 part = &r->headers_in.headers.part;
|
|
742 header = part->elts;
|
|
743
|
|
744 for (i = 0; /* void */; i++) {
|
|
745
|
|
746 if (i >= part->nelts) {
|
|
747 if (part->next == NULL) {
|
|
748 break;
|
|
749 }
|
|
750
|
|
751 part = part->next;
|
|
752 header = part->elts;
|
|
753 i = 0;
|
|
754 }
|
|
755
|
|
756 for (n = 0; n < header_params; n++) {
|
|
757 if (&header[i] == ignored[n]) {
|
|
758 goto next;
|
|
759 }
|
|
760 }
|
|
761
|
|
762 key = b->last;
|
|
763 b->last = ngx_cpymem(key, "HTTP_", sizeof("HTTP_") - 1);
|
|
764
|
|
765 for (n = 0; n < header[i].key.len; n++) {
|
|
766 ch = header[i].key.data[n];
|
|
767
|
|
768 if (ch >= 'a' && ch <= 'z') {
|
|
769 ch &= ~0x20;
|
|
770
|
|
771 } else if (ch == '-') {
|
|
772 ch = '_';
|
|
773 }
|
|
774
|
|
775 *b->last++ = ch;
|
|
776 }
|
|
777
|
|
778 *b->last++ = (u_char) 0;
|
|
779
|
|
780 val = b->last;
|
|
781 b->last = ngx_copy(val, header[i].value.data, header[i].value.len);
|
|
782 *b->last++ = (u_char) 0;
|
|
783
|
|
784 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
785 "scgi param: \"%s: %s\"", key, val);
|
|
786
|
|
787 next:
|
|
788
|
|
789 continue;
|
|
790 }
|
|
791 }
|
|
792
|
|
793 *b->last++ = (u_char) ',';
|
|
794
|
|
795 if (scf->upstream.pass_request_body) {
|
|
796 body = r->upstream->request_bufs;
|
|
797 r->upstream->request_bufs = cl;
|
|
798
|
|
799 while (body) {
|
|
800 b = ngx_alloc_buf(r->pool);
|
|
801 if (b == NULL) {
|
|
802 return NGX_ERROR;
|
|
803 }
|
|
804
|
|
805 ngx_memcpy(b, body->buf, sizeof(ngx_buf_t));
|
|
806
|
|
807 cl->next = ngx_alloc_chain_link(r->pool);
|
|
808 if (cl->next == NULL) {
|
|
809 return NGX_ERROR;
|
|
810 }
|
|
811
|
|
812 cl = cl->next;
|
|
813 cl->buf = b;
|
|
814
|
|
815 body = body->next;
|
|
816 }
|
|
817
|
|
818 } else {
|
|
819 r->upstream->request_bufs = cl;
|
|
820 }
|
|
821
|
|
822 cl->next = NULL;
|
|
823
|
|
824 return NGX_OK;
|
|
825 }
|
|
826
|
|
827
|
|
828 static ngx_int_t
|
|
829 ngx_http_scgi_reinit_request(ngx_http_request_t *r)
|
|
830 {
|
|
831 ngx_http_status_t *status;
|
|
832
|
|
833 status = ngx_http_get_module_ctx(r, ngx_http_scgi_module);
|
|
834
|
|
835 if (status == NULL) {
|
|
836 return NGX_OK;
|
|
837 }
|
|
838
|
|
839 status->code = 0;
|
|
840 status->count = 0;
|
|
841 status->start = NULL;
|
|
842 status->end = NULL;
|
|
843
|
|
844 r->upstream->process_header = ngx_http_scgi_process_status_line;
|
|
845
|
|
846 return NGX_OK;
|
|
847 }
|
|
848
|
|
849
|
|
850 static ngx_int_t
|
|
851 ngx_http_scgi_process_status_line(ngx_http_request_t *r)
|
|
852 {
|
|
853 size_t len;
|
|
854 ngx_int_t rc;
|
|
855 ngx_http_status_t *status;
|
|
856 ngx_http_upstream_t *u;
|
|
857
|
|
858 status = ngx_http_get_module_ctx(r, ngx_http_scgi_module);
|
|
859
|
|
860 if (status == NULL) {
|
|
861 return NGX_ERROR;
|
|
862 }
|
|
863
|
|
864 u = r->upstream;
|
|
865
|
|
866 rc = ngx_http_parse_status_line(r, &u->buffer, status);
|
|
867
|
|
868 if (rc == NGX_AGAIN) {
|
|
869 return rc;
|
|
870 }
|
|
871
|
|
872 if (rc == NGX_ERROR) {
|
|
873 u->process_header = ngx_http_scgi_process_header;
|
|
874 return ngx_http_scgi_process_header(r);
|
|
875 }
|
|
876
|
|
877 if (u->state) {
|
|
878 u->state->status = status->code;
|
|
879 }
|
|
880
|
|
881 u->headers_in.status_n = status->code;
|
|
882
|
|
883 len = status->end - status->start;
|
|
884 u->headers_in.status_line.len = len;
|
|
885
|
|
886 u->headers_in.status_line.data = ngx_pnalloc(r->pool, len);
|
|
887 if (u->headers_in.status_line.data == NULL) {
|
|
888 return NGX_ERROR;
|
|
889 }
|
|
890
|
|
891 ngx_memcpy(u->headers_in.status_line.data, status->start, len);
|
|
892
|
|
893 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
894 "http scgi status %ui \"%V\"",
|
|
895 u->headers_in.status_n, &u->headers_in.status_line);
|
|
896
|
|
897 u->process_header = ngx_http_scgi_process_header;
|
|
898
|
|
899 return ngx_http_scgi_process_header(r);
|
|
900 }
|
|
901
|
|
902
|
|
903 static ngx_int_t
|
|
904 ngx_http_scgi_process_header(ngx_http_request_t *r)
|
|
905 {
|
|
906 ngx_str_t *status_line;
|
|
907 ngx_int_t rc, status;
|
|
908 ngx_table_elt_t *h;
|
|
909 ngx_http_upstream_t *u;
|
|
910 ngx_http_upstream_header_t *hh;
|
|
911 ngx_http_upstream_main_conf_t *umcf;
|
|
912
|
|
913 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);
|
|
914
|
|
915 for ( ;; ) {
|
|
916
|
|
917 rc = ngx_http_parse_header_line(r, &r->upstream->buffer, 1);
|
|
918
|
|
919 if (rc == NGX_OK) {
|
|
920
|
|
921 /* a header line has been parsed successfully */
|
|
922
|
|
923 h = ngx_list_push(&r->upstream->headers_in.headers);
|
|
924 if (h == NULL) {
|
|
925 return NGX_ERROR;
|
|
926 }
|
|
927
|
|
928 h->hash = r->header_hash;
|
|
929
|
|
930 h->key.len = r->header_name_end - r->header_name_start;
|
|
931 h->value.len = r->header_end - r->header_start;
|
|
932
|
|
933 h->key.data = ngx_pnalloc(r->pool,
|
|
934 h->key.len + 1 + h->value.len + 1
|
|
935 + h->key.len);
|
|
936 if (h->key.data == NULL) {
|
|
937 return NGX_ERROR;
|
|
938 }
|
|
939
|
|
940 h->value.data = h->key.data + h->key.len + 1;
|
|
941 h->lowcase_key = h->key.data + h->key.len + 1 + h->value.len + 1;
|
|
942
|
|
943 ngx_cpystrn(h->key.data, r->header_name_start, h->key.len + 1);
|
|
944 ngx_cpystrn(h->value.data, r->header_start, h->value.len + 1);
|
|
945
|
|
946 if (h->key.len == r->lowcase_index) {
|
|
947 ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len);
|
|
948
|
|
949 } else {
|
|
950 ngx_strlow(h->lowcase_key, h->key.data, h->key.len);
|
|
951 }
|
|
952
|
|
953 hh = ngx_hash_find(&umcf->headers_in_hash, h->hash,
|
|
954 h->lowcase_key, h->key.len);
|
|
955
|
|
956 if (hh && hh->handler(r, h, hh->offset) != NGX_OK) {
|
|
957 return NGX_ERROR;
|
|
958 }
|
|
959
|
|
960 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
961 "http scgi header: \"%V: %V\"", &h->key, &h->value);
|
|
962
|
|
963 continue;
|
|
964 }
|
|
965
|
|
966 if (rc == NGX_HTTP_PARSE_HEADER_DONE) {
|
|
967
|
|
968 /* a whole header has been parsed successfully */
|
|
969
|
|
970 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
971 "http scgi header done");
|
|
972
|
656
|
973 u = r->upstream;
|
|
974
|
|
975 if (u->headers_in.status_n) {
|
580
|
976 return NGX_OK;
|
|
977 }
|
|
978
|
|
979 if (u->headers_in.status) {
|
|
980 status_line = &u->headers_in.status->value;
|
|
981
|
|
982 status = ngx_atoi(status_line->data, 3);
|
|
983 if (status == NGX_ERROR) {
|
|
984 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
985 "upstream sent invalid status \"%V\"",
|
|
986 status_line);
|
|
987 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
|
988 }
|
|
989
|
|
990 u->headers_in.status_n = status;
|
|
991 u->headers_in.status_line = *status_line;
|
|
992
|
|
993 } else if (u->headers_in.location) {
|
|
994 u->headers_in.status_n = 302;
|
|
995 ngx_str_set(&u->headers_in.status_line,
|
|
996 "302 Moved Temporarily");
|
|
997
|
|
998 } else {
|
|
999 u->headers_in.status_n = 200;
|
|
1000 ngx_str_set(&u->headers_in.status_line, "200 OK");
|
|
1001 }
|
|
1002
|
|
1003 if (u->state) {
|
|
1004 u->state->status = u->headers_in.status_n;
|
|
1005 }
|
|
1006
|
|
1007 return NGX_OK;
|
|
1008 }
|
|
1009
|
|
1010 if (rc == NGX_AGAIN) {
|
|
1011 return NGX_AGAIN;
|
|
1012 }
|
|
1013
|
|
1014 /* there was error while a header line parsing */
|
|
1015
|
|
1016 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1017 "upstream sent invalid header");
|
|
1018
|
|
1019 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
|
1020 }
|
|
1021 }
|
|
1022
|
|
1023
|
|
1024 static void
|
|
1025 ngx_http_scgi_abort_request(ngx_http_request_t *r)
|
|
1026 {
|
|
1027 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1028 "abort http scgi request");
|
|
1029
|
|
1030 return;
|
|
1031 }
|
|
1032
|
|
1033
|
|
1034 static void
|
|
1035 ngx_http_scgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
|
|
1036 {
|
|
1037 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1038 "finalize http scgi request");
|
|
1039
|
|
1040 return;
|
|
1041 }
|
|
1042
|
|
1043
|
|
1044 static void *
|
|
1045 ngx_http_scgi_create_loc_conf(ngx_conf_t *cf)
|
|
1046 {
|
|
1047 ngx_http_scgi_loc_conf_t *conf;
|
|
1048
|
|
1049 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_scgi_loc_conf_t));
|
|
1050 if (conf == NULL) {
|
|
1051 return NULL;
|
|
1052 }
|
|
1053
|
|
1054 conf->upstream.store = NGX_CONF_UNSET;
|
|
1055 conf->upstream.store_access = NGX_CONF_UNSET_UINT;
|
|
1056 conf->upstream.buffering = NGX_CONF_UNSET;
|
|
1057 conf->upstream.ignore_client_abort = NGX_CONF_UNSET;
|
|
1058
|
|
1059 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC;
|
|
1060 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC;
|
|
1061 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC;
|
|
1062
|
|
1063 conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE;
|
|
1064 conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE;
|
|
1065
|
|
1066 conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE;
|
|
1067 conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
|
|
1068 conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE;
|
|
1069
|
|
1070 conf->upstream.pass_request_headers = NGX_CONF_UNSET;
|
|
1071 conf->upstream.pass_request_body = NGX_CONF_UNSET;
|
|
1072
|
|
1073 #if (NGX_HTTP_CACHE)
|
|
1074 conf->upstream.cache = NGX_CONF_UNSET_PTR;
|
|
1075 conf->upstream.cache_min_uses = NGX_CONF_UNSET_UINT;
|
588
|
1076 conf->upstream.cache_bypass = NGX_CONF_UNSET_PTR;
|
|
1077 conf->upstream.no_cache = NGX_CONF_UNSET_PTR;
|
580
|
1078 conf->upstream.cache_valid = NGX_CONF_UNSET_PTR;
|
656
|
1079 conf->upstream.cache_lock = NGX_CONF_UNSET;
|
|
1080 conf->upstream.cache_lock_timeout = NGX_CONF_UNSET_MSEC;
|
580
|
1081 #endif
|
|
1082
|
|
1083 conf->upstream.hide_headers = NGX_CONF_UNSET_PTR;
|
|
1084 conf->upstream.pass_headers = NGX_CONF_UNSET_PTR;
|
|
1085
|
|
1086 conf->upstream.intercept_errors = NGX_CONF_UNSET;
|
|
1087
|
|
1088 /* "scgi_cyclic_temp_file" is disabled */
|
|
1089 conf->upstream.cyclic_temp_file = 0;
|
|
1090
|
642
|
1091 conf->upstream.change_buffering = 1;
|
|
1092
|
632
|
1093 ngx_str_set(&conf->upstream.module, "scgi");
|
|
1094
|
580
|
1095 return conf;
|
|
1096 }
|
|
1097
|
|
1098
|
|
1099 static char *
|
|
1100 ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
|
1101 {
|
|
1102 ngx_http_scgi_loc_conf_t *prev = parent;
|
|
1103 ngx_http_scgi_loc_conf_t *conf = child;
|
|
1104
|
|
1105 size_t size;
|
|
1106 ngx_hash_init_t hash;
|
592
|
1107 ngx_http_core_loc_conf_t *clcf;
|
580
|
1108
|
|
1109 if (conf->upstream.store != 0) {
|
|
1110 ngx_conf_merge_value(conf->upstream.store, prev->upstream.store, 0);
|
|
1111
|
|
1112 if (conf->upstream.store_lengths == NULL) {
|
|
1113 conf->upstream.store_lengths = prev->upstream.store_lengths;
|
|
1114 conf->upstream.store_values = prev->upstream.store_values;
|
|
1115 }
|
|
1116 }
|
|
1117
|
|
1118 ngx_conf_merge_uint_value(conf->upstream.store_access,
|
|
1119 prev->upstream.store_access, 0600);
|
|
1120
|
|
1121 ngx_conf_merge_value(conf->upstream.buffering,
|
|
1122 prev->upstream.buffering, 1);
|
|
1123
|
|
1124 ngx_conf_merge_value(conf->upstream.ignore_client_abort,
|
|
1125 prev->upstream.ignore_client_abort, 0);
|
|
1126
|
|
1127 ngx_conf_merge_msec_value(conf->upstream.connect_timeout,
|
|
1128 prev->upstream.connect_timeout, 60000);
|
|
1129
|
|
1130 ngx_conf_merge_msec_value(conf->upstream.send_timeout,
|
|
1131 prev->upstream.send_timeout, 60000);
|
|
1132
|
|
1133 ngx_conf_merge_msec_value(conf->upstream.read_timeout,
|
|
1134 prev->upstream.read_timeout, 60000);
|
|
1135
|
|
1136 ngx_conf_merge_size_value(conf->upstream.send_lowat,
|
|
1137 prev->upstream.send_lowat, 0);
|
|
1138
|
|
1139 ngx_conf_merge_size_value(conf->upstream.buffer_size,
|
|
1140 prev->upstream.buffer_size,
|
|
1141 (size_t) ngx_pagesize);
|
|
1142
|
|
1143
|
|
1144 ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs,
|
|
1145 8, ngx_pagesize);
|
|
1146
|
|
1147 if (conf->upstream.bufs.num < 2) {
|
|
1148 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1149 "there must be at least 2 \"scgi_buffers\"");
|
|
1150 return NGX_CONF_ERROR;
|
|
1151 }
|
|
1152
|
|
1153
|
|
1154 size = conf->upstream.buffer_size;
|
|
1155 if (size < conf->upstream.bufs.size) {
|
|
1156 size = conf->upstream.bufs.size;
|
|
1157 }
|
|
1158
|
|
1159
|
|
1160 ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf,
|
|
1161 prev->upstream.busy_buffers_size_conf,
|
|
1162 NGX_CONF_UNSET_SIZE);
|
|
1163
|
|
1164 if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) {
|
|
1165 conf->upstream.busy_buffers_size = 2 * size;
|
|
1166 } else {
|
|
1167 conf->upstream.busy_buffers_size =
|
|
1168 conf->upstream.busy_buffers_size_conf;
|
|
1169 }
|
|
1170
|
|
1171 if (conf->upstream.busy_buffers_size < size) {
|
|
1172 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1173 "\"scgi_busy_buffers_size\" must be equal or bigger "
|
|
1174 "than maximum of the value of \"scgi_buffer_size\" and "
|
|
1175 "one of the \"scgi_buffers\"");
|
|
1176
|
|
1177 return NGX_CONF_ERROR;
|
|
1178 }
|
|
1179
|
|
1180 if (conf->upstream.busy_buffers_size
|
|
1181 > (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size)
|
|
1182 {
|
|
1183 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1184 "\"scgi_busy_buffers_size\" must be less than "
|
|
1185 "the size of all \"scgi_buffers\" minus one buffer");
|
|
1186
|
|
1187 return NGX_CONF_ERROR;
|
|
1188 }
|
|
1189
|
|
1190
|
|
1191 ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf,
|
|
1192 prev->upstream.temp_file_write_size_conf,
|
|
1193 NGX_CONF_UNSET_SIZE);
|
|
1194
|
|
1195 if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) {
|
|
1196 conf->upstream.temp_file_write_size = 2 * size;
|
|
1197 } else {
|
|
1198 conf->upstream.temp_file_write_size =
|
|
1199 conf->upstream.temp_file_write_size_conf;
|
|
1200 }
|
|
1201
|
|
1202 if (conf->upstream.temp_file_write_size < size) {
|
|
1203 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1204 "\"scgi_temp_file_write_size\" must be equal or bigger than "
|
|
1205 "maximum of the value of \"scgi_buffer_size\" and "
|
|
1206 "one of the \"scgi_buffers\"");
|
|
1207
|
|
1208 return NGX_CONF_ERROR;
|
|
1209 }
|
|
1210
|
|
1211
|
|
1212 ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf,
|
|
1213 prev->upstream.max_temp_file_size_conf,
|
|
1214 NGX_CONF_UNSET_SIZE);
|
|
1215
|
|
1216 if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) {
|
|
1217 conf->upstream.max_temp_file_size = 1024 * 1024 * 1024;
|
|
1218 } else {
|
|
1219 conf->upstream.max_temp_file_size =
|
|
1220 conf->upstream.max_temp_file_size_conf;
|
|
1221 }
|
|
1222
|
|
1223 if (conf->upstream.max_temp_file_size != 0
|
|
1224 && conf->upstream.max_temp_file_size < size) {
|
|
1225 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1226 "\"scgi_max_temp_file_size\" must be equal to zero to disable "
|
|
1227 "the temporary files usage or must be equal or bigger than "
|
|
1228 "maximum of the value of \"scgi_buffer_size\" and "
|
|
1229 "one of the \"scgi_buffers\"");
|
|
1230
|
|
1231 return NGX_CONF_ERROR;
|
|
1232 }
|
|
1233
|
|
1234
|
|
1235 ngx_conf_merge_bitmask_value(conf->upstream.ignore_headers,
|
|
1236 prev->upstream.ignore_headers,
|
|
1237 NGX_CONF_BITMASK_SET);
|
|
1238
|
|
1239
|
|
1240 ngx_conf_merge_bitmask_value(conf->upstream.next_upstream,
|
|
1241 prev->upstream.next_upstream,
|
|
1242 (NGX_CONF_BITMASK_SET
|
|
1243 |NGX_HTTP_UPSTREAM_FT_ERROR
|
|
1244 |NGX_HTTP_UPSTREAM_FT_TIMEOUT));
|
|
1245
|
|
1246 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) {
|
|
1247 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET
|
|
1248 |NGX_HTTP_UPSTREAM_FT_OFF;
|
|
1249 }
|
|
1250
|
|
1251 if (ngx_conf_merge_path_value(cf, &conf->upstream.temp_path,
|
|
1252 prev->upstream.temp_path,
|
|
1253 &ngx_http_scgi_temp_path)
|
|
1254 != NGX_OK)
|
|
1255 {
|
|
1256 return NGX_CONF_ERROR;
|
|
1257 }
|
|
1258
|
|
1259 #if (NGX_HTTP_CACHE)
|
|
1260
|
|
1261 ngx_conf_merge_ptr_value(conf->upstream.cache,
|
|
1262 prev->upstream.cache, NULL);
|
|
1263
|
|
1264 if (conf->upstream.cache && conf->upstream.cache->data == NULL) {
|
|
1265 ngx_shm_zone_t *shm_zone;
|
|
1266
|
|
1267 shm_zone = conf->upstream.cache;
|
|
1268
|
|
1269 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1270 "\"scgi_cache\" zone \"%V\" is unknown",
|
|
1271 &shm_zone->shm.name);
|
|
1272
|
|
1273 return NGX_CONF_ERROR;
|
|
1274 }
|
|
1275
|
|
1276 ngx_conf_merge_uint_value(conf->upstream.cache_min_uses,
|
|
1277 prev->upstream.cache_min_uses, 1);
|
|
1278
|
|
1279 ngx_conf_merge_bitmask_value(conf->upstream.cache_use_stale,
|
|
1280 prev->upstream.cache_use_stale,
|
|
1281 (NGX_CONF_BITMASK_SET
|
|
1282 |NGX_HTTP_UPSTREAM_FT_OFF));
|
|
1283
|
|
1284 if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_OFF) {
|
|
1285 conf->upstream.cache_use_stale = NGX_CONF_BITMASK_SET
|
|
1286 |NGX_HTTP_UPSTREAM_FT_OFF;
|
|
1287 }
|
|
1288
|
|
1289 if (conf->upstream.cache_methods == 0) {
|
|
1290 conf->upstream.cache_methods = prev->upstream.cache_methods;
|
|
1291 }
|
|
1292
|
|
1293 conf->upstream.cache_methods |= NGX_HTTP_GET|NGX_HTTP_HEAD;
|
|
1294
|
588
|
1295 ngx_conf_merge_ptr_value(conf->upstream.cache_bypass,
|
|
1296 prev->upstream.cache_bypass, NULL);
|
|
1297
|
580
|
1298 ngx_conf_merge_ptr_value(conf->upstream.no_cache,
|
|
1299 prev->upstream.no_cache, NULL);
|
|
1300
|
|
1301 ngx_conf_merge_ptr_value(conf->upstream.cache_valid,
|
|
1302 prev->upstream.cache_valid, NULL);
|
|
1303
|
|
1304 if (conf->cache_key.value.data == NULL) {
|
|
1305 conf->cache_key = prev->cache_key;
|
|
1306 }
|
|
1307
|
656
|
1308 ngx_conf_merge_value(conf->upstream.cache_lock,
|
|
1309 prev->upstream.cache_lock, 0);
|
|
1310
|
|
1311 ngx_conf_merge_msec_value(conf->upstream.cache_lock_timeout,
|
|
1312 prev->upstream.cache_lock_timeout, 5000);
|
|
1313
|
580
|
1314 #endif
|
|
1315
|
|
1316 ngx_conf_merge_value(conf->upstream.pass_request_headers,
|
|
1317 prev->upstream.pass_request_headers, 1);
|
|
1318 ngx_conf_merge_value(conf->upstream.pass_request_body,
|
|
1319 prev->upstream.pass_request_body, 1);
|
|
1320
|
|
1321 ngx_conf_merge_value(conf->upstream.intercept_errors,
|
|
1322 prev->upstream.intercept_errors, 0);
|
|
1323
|
|
1324 hash.max_size = 512;
|
|
1325 hash.bucket_size = ngx_align(64, ngx_cacheline_size);
|
|
1326 hash.name = "scgi_hide_headers_hash";
|
|
1327
|
|
1328 if (ngx_http_upstream_hide_headers_hash(cf, &conf->upstream,
|
584
|
1329 &prev->upstream, ngx_http_scgi_hide_headers, &hash)
|
580
|
1330 != NGX_OK)
|
|
1331 {
|
|
1332 return NGX_CONF_ERROR;
|
|
1333 }
|
|
1334
|
|
1335 if (conf->upstream.upstream == NULL) {
|
|
1336 conf->upstream.upstream = prev->upstream.upstream;
|
|
1337 }
|
|
1338
|
|
1339 if (conf->scgi_lengths == NULL) {
|
|
1340 conf->scgi_lengths = prev->scgi_lengths;
|
|
1341 conf->scgi_values = prev->scgi_values;
|
|
1342 }
|
|
1343
|
592
|
1344 if (conf->upstream.upstream || conf->scgi_lengths) {
|
|
1345 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
|
|
1346 if (clcf->handler == NULL && clcf->lmt_excpt) {
|
|
1347 clcf->handler = ngx_http_scgi_handler;
|
|
1348 }
|
|
1349 }
|
|
1350
|
648
|
1351 if (ngx_http_scgi_merge_params(cf, conf, prev) != NGX_OK) {
|
|
1352 return NGX_CONF_ERROR;
|
|
1353 }
|
|
1354
|
|
1355 return NGX_CONF_OK;
|
|
1356 }
|
|
1357
|
580
|
1358
|
648
|
1359 static ngx_int_t
|
|
1360 ngx_http_scgi_merge_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf,
|
|
1361 ngx_http_scgi_loc_conf_t *prev)
|
|
1362 {
|
|
1363 u_char *p;
|
|
1364 size_t size;
|
|
1365 uintptr_t *code;
|
|
1366 ngx_uint_t i, nsrc;
|
|
1367 ngx_array_t headers_names;
|
580
|
1368 #if (NGX_HTTP_CACHE)
|
648
|
1369 ngx_array_t params_merged;
|
|
1370 #endif
|
|
1371 ngx_hash_key_t *hk;
|
|
1372 ngx_hash_init_t hash;
|
654
|
1373 ngx_http_upstream_param_t *src;
|
648
|
1374 ngx_http_script_compile_t sc;
|
|
1375 ngx_http_script_copy_code_t *copy;
|
580
|
1376
|
648
|
1377 if (conf->params_source == NULL) {
|
|
1378 conf->params_source = prev->params_source;
|
580
|
1379
|
648
|
1380 if (prev->headers_hash.buckets
|
|
1381 #if (NGX_HTTP_CACHE)
|
|
1382 && ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL))
|
|
1383 #endif
|
|
1384 )
|
|
1385 {
|
|
1386 conf->flushes = prev->flushes;
|
|
1387 conf->params_len = prev->params_len;
|
|
1388 conf->params = prev->params;
|
|
1389 conf->headers_hash = prev->headers_hash;
|
|
1390 conf->header_params = prev->header_params;
|
|
1391
|
|
1392 return NGX_OK;
|
580
|
1393 }
|
648
|
1394 }
|
580
|
1395
|
648
|
1396 if (conf->params_source == NULL
|
|
1397 #if (NGX_HTTP_CACHE)
|
|
1398 && (conf->upstream.cache == NULL)
|
580
|
1399 #endif
|
648
|
1400 )
|
|
1401 {
|
|
1402 conf->headers_hash.buckets = (void *) 1;
|
|
1403 return NGX_OK;
|
580
|
1404 }
|
|
1405
|
|
1406 conf->params_len = ngx_array_create(cf->pool, 64, 1);
|
|
1407 if (conf->params_len == NULL) {
|
648
|
1408 return NGX_ERROR;
|
580
|
1409 }
|
|
1410
|
|
1411 conf->params = ngx_array_create(cf->pool, 512, 1);
|
|
1412 if (conf->params == NULL) {
|
648
|
1413 return NGX_ERROR;
|
580
|
1414 }
|
|
1415
|
|
1416 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t))
|
|
1417 != NGX_OK)
|
|
1418 {
|
648
|
1419 return NGX_ERROR;
|
580
|
1420 }
|
|
1421
|
648
|
1422 if (conf->params_source) {
|
|
1423 src = conf->params_source->elts;
|
|
1424 nsrc = conf->params_source->nelts;
|
|
1425
|
|
1426 } else {
|
|
1427 src = NULL;
|
|
1428 nsrc = 0;
|
|
1429 }
|
580
|
1430
|
|
1431 #if (NGX_HTTP_CACHE)
|
|
1432
|
|
1433 if (conf->upstream.cache) {
|
654
|
1434 ngx_keyval_t *h;
|
|
1435 ngx_http_upstream_param_t *s;
|
580
|
1436
|
654
|
1437 if (ngx_array_init(¶ms_merged, cf->temp_pool, 4,
|
|
1438 sizeof(ngx_http_upstream_param_t))
|
648
|
1439 != NGX_OK)
|
|
1440 {
|
|
1441 return NGX_ERROR;
|
|
1442 }
|
|
1443
|
|
1444 for (i = 0; i < nsrc; i++) {
|
580
|
1445
|
648
|
1446 s = ngx_array_push(¶ms_merged);
|
|
1447 if (s == NULL) {
|
|
1448 return NGX_ERROR;
|
|
1449 }
|
|
1450
|
|
1451 *s = src[i];
|
|
1452 }
|
|
1453
|
|
1454 h = ngx_http_scgi_cache_headers;
|
|
1455
|
|
1456 while (h->key.len) {
|
|
1457
|
|
1458 src = params_merged.elts;
|
|
1459 nsrc = params_merged.nelts;
|
|
1460
|
|
1461 for (i = 0; i < nsrc; i++) {
|
580
|
1462 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) {
|
|
1463 goto next;
|
|
1464 }
|
|
1465 }
|
|
1466
|
648
|
1467 s = ngx_array_push(¶ms_merged);
|
580
|
1468 if (s == NULL) {
|
648
|
1469 return NGX_ERROR;
|
580
|
1470 }
|
|
1471
|
654
|
1472 s->key = h->key;
|
|
1473 s->value = h->value;
|
|
1474 s->skip_empty = 0;
|
580
|
1475
|
|
1476 next:
|
|
1477
|
|
1478 h++;
|
|
1479 }
|
648
|
1480
|
|
1481 src = params_merged.elts;
|
|
1482 nsrc = params_merged.nelts;
|
580
|
1483 }
|
|
1484
|
|
1485 #endif
|
|
1486
|
648
|
1487 for (i = 0; i < nsrc; i++) {
|
580
|
1488
|
|
1489 if (src[i].key.len > sizeof("HTTP_") - 1
|
|
1490 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0)
|
|
1491 {
|
|
1492 hk = ngx_array_push(&headers_names);
|
|
1493 if (hk == NULL) {
|
648
|
1494 return NGX_ERROR;
|
580
|
1495 }
|
|
1496
|
|
1497 hk->key.len = src[i].key.len - 5;
|
|
1498 hk->key.data = src[i].key.data + 5;
|
|
1499 hk->key_hash = ngx_hash_key_lc(hk->key.data, hk->key.len);
|
|
1500 hk->value = (void *) 1;
|
|
1501
|
|
1502 if (src[i].value.len == 0) {
|
|
1503 continue;
|
|
1504 }
|
|
1505 }
|
|
1506
|
|
1507 copy = ngx_array_push_n(conf->params_len,
|
|
1508 sizeof(ngx_http_script_copy_code_t));
|
|
1509 if (copy == NULL) {
|
648
|
1510 return NGX_ERROR;
|
580
|
1511 }
|
|
1512
|
|
1513 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
|
|
1514 copy->len = src[i].key.len + 1;
|
|
1515
|
654
|
1516 copy = ngx_array_push_n(conf->params_len,
|
|
1517 sizeof(ngx_http_script_copy_code_t));
|
|
1518 if (copy == NULL) {
|
|
1519 return NGX_ERROR;
|
|
1520 }
|
|
1521
|
|
1522 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
|
|
1523 copy->len = src[i].skip_empty;
|
|
1524
|
580
|
1525
|
|
1526 size = (sizeof(ngx_http_script_copy_code_t)
|
|
1527 + src[i].key.len + 1 + sizeof(uintptr_t) - 1)
|
|
1528 & ~(sizeof(uintptr_t) - 1);
|
|
1529
|
|
1530 copy = ngx_array_push_n(conf->params, size);
|
|
1531 if (copy == NULL) {
|
648
|
1532 return NGX_ERROR;
|
580
|
1533 }
|
|
1534
|
|
1535 copy->code = ngx_http_script_copy_code;
|
|
1536 copy->len = src[i].key.len + 1;
|
|
1537
|
|
1538 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t);
|
|
1539 (void) ngx_cpystrn(p, src[i].key.data, src[i].key.len + 1);
|
|
1540
|
|
1541
|
|
1542 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
1543
|
|
1544 sc.cf = cf;
|
|
1545 sc.source = &src[i].value;
|
|
1546 sc.flushes = &conf->flushes;
|
|
1547 sc.lengths = &conf->params_len;
|
|
1548 sc.values = &conf->params;
|
|
1549
|
|
1550 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
648
|
1551 return NGX_ERROR;
|
580
|
1552 }
|
|
1553
|
|
1554 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
|
|
1555 if (code == NULL) {
|
648
|
1556 return NGX_ERROR;
|
580
|
1557 }
|
|
1558
|
|
1559 *code = (uintptr_t) NULL;
|
|
1560
|
|
1561
|
|
1562 code = ngx_array_push_n(conf->params, sizeof(uintptr_t));
|
|
1563 if (code == NULL) {
|
648
|
1564 return NGX_ERROR;
|
580
|
1565 }
|
|
1566
|
|
1567 *code = (uintptr_t) NULL;
|
|
1568 }
|
|
1569
|
|
1570 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
|
|
1571 if (code == NULL) {
|
648
|
1572 return NGX_ERROR;
|
580
|
1573 }
|
|
1574
|
|
1575 *code = (uintptr_t) NULL;
|
|
1576
|
|
1577 code = ngx_array_push_n(conf->params, sizeof(uintptr_t));
|
|
1578 if (code == NULL) {
|
648
|
1579 return NGX_ERROR;
|
580
|
1580 }
|
|
1581
|
|
1582 *code = (uintptr_t) NULL;
|
|
1583
|
|
1584 conf->header_params = headers_names.nelts;
|
|
1585
|
|
1586 hash.hash = &conf->headers_hash;
|
|
1587 hash.key = ngx_hash_key_lc;
|
|
1588 hash.max_size = 512;
|
|
1589 hash.bucket_size = 64;
|
|
1590 hash.name = "scgi_params_hash";
|
|
1591 hash.pool = cf->pool;
|
|
1592 hash.temp_pool = NULL;
|
|
1593
|
648
|
1594 return ngx_hash_init(&hash, headers_names.elts, headers_names.nelts);
|
580
|
1595 }
|
|
1596
|
|
1597
|
|
1598 static char *
|
|
1599 ngx_http_scgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
1600 {
|
|
1601 ngx_http_scgi_loc_conf_t *scf = conf;
|
|
1602
|
|
1603 ngx_url_t u;
|
|
1604 ngx_str_t *value, *url;
|
|
1605 ngx_uint_t n;
|
|
1606 ngx_http_core_loc_conf_t *clcf;
|
|
1607 ngx_http_script_compile_t sc;
|
|
1608
|
|
1609 if (scf->upstream.upstream || scf->scgi_lengths) {
|
|
1610 return "is duplicate";
|
|
1611 }
|
|
1612
|
|
1613 clcf = ngx_http_conf_get_module_loc_conf (cf, ngx_http_core_module);
|
|
1614 clcf->handler = ngx_http_scgi_handler;
|
|
1615
|
|
1616 value = cf->args->elts;
|
|
1617
|
|
1618 url = &value[1];
|
|
1619
|
|
1620 n = ngx_http_script_variables_count(url);
|
|
1621
|
|
1622 if (n) {
|
|
1623
|
|
1624 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
1625
|
|
1626 sc.cf = cf;
|
|
1627 sc.source = url;
|
|
1628 sc.lengths = &scf->scgi_lengths;
|
|
1629 sc.values = &scf->scgi_values;
|
|
1630 sc.variables = n;
|
|
1631 sc.complete_lengths = 1;
|
|
1632 sc.complete_values = 1;
|
|
1633
|
|
1634 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
1635 return NGX_CONF_ERROR;
|
|
1636 }
|
|
1637
|
|
1638 return NGX_CONF_OK;
|
|
1639 }
|
|
1640
|
|
1641 ngx_memzero(&u, sizeof(ngx_url_t));
|
|
1642
|
|
1643 u.url = value[1];
|
|
1644 u.no_resolve = 1;
|
|
1645
|
|
1646 scf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0);
|
|
1647 if (scf->upstream.upstream == NULL) {
|
|
1648 return NGX_CONF_ERROR;
|
|
1649 }
|
|
1650
|
|
1651 if (clcf->name.data[clcf->name.len - 1] == '/') {
|
|
1652 clcf->auto_redirect = 1;
|
|
1653 }
|
|
1654
|
|
1655 return NGX_CONF_OK;
|
|
1656 }
|
|
1657
|
|
1658
|
|
1659 static char *
|
|
1660 ngx_http_scgi_store(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
1661 {
|
|
1662 ngx_http_scgi_loc_conf_t *scf = conf;
|
|
1663
|
|
1664 ngx_str_t *value;
|
|
1665 ngx_http_script_compile_t sc;
|
|
1666
|
|
1667 if (scf->upstream.store != NGX_CONF_UNSET || scf->upstream.store_lengths) {
|
|
1668 return "is duplicate";
|
|
1669 }
|
|
1670
|
|
1671 value = cf->args->elts;
|
|
1672
|
|
1673 if (ngx_strcmp(value[1].data, "off") == 0) {
|
|
1674 scf->upstream.store = 0;
|
|
1675 return NGX_CONF_OK;
|
|
1676 }
|
|
1677
|
|
1678 #if (NGX_HTTP_CACHE)
|
|
1679
|
|
1680 if (scf->upstream.cache != NGX_CONF_UNSET_PTR
|
|
1681 && scf->upstream.cache != NULL)
|
|
1682 {
|
|
1683 return "is incompatible with \"scgi_cache\"";
|
|
1684 }
|
|
1685
|
|
1686 #endif
|
|
1687
|
|
1688 if (ngx_strcmp(value[1].data, "on") == 0) {
|
|
1689 scf->upstream.store = 1;
|
|
1690 return NGX_CONF_OK;
|
|
1691 }
|
|
1692
|
|
1693 /* include the terminating '\0' into script */
|
|
1694 value[1].len++;
|
|
1695
|
|
1696 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
1697
|
|
1698 sc.cf = cf;
|
|
1699 sc.source = &value[1];
|
|
1700 sc.lengths = &scf->upstream.store_lengths;
|
|
1701 sc.values = &scf->upstream.store_values;
|
|
1702 sc.variables = ngx_http_script_variables_count(&value[1]);;
|
|
1703 sc.complete_lengths = 1;
|
|
1704 sc.complete_values = 1;
|
|
1705
|
|
1706 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
1707 return NGX_CONF_ERROR;
|
|
1708 }
|
|
1709
|
|
1710 return NGX_CONF_OK;
|
|
1711 }
|
|
1712
|
|
1713
|
|
1714 #if (NGX_HTTP_CACHE)
|
|
1715
|
|
1716 static char *
|
|
1717 ngx_http_scgi_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
1718 {
|
|
1719 ngx_http_scgi_loc_conf_t *scf = conf;
|
|
1720
|
|
1721 ngx_str_t *value;
|
|
1722
|
|
1723 value = cf->args->elts;
|
|
1724
|
|
1725 if (scf->upstream.cache != NGX_CONF_UNSET_PTR) {
|
|
1726 return "is duplicate";
|
|
1727 }
|
|
1728
|
|
1729 if (ngx_strcmp(value[1].data, "off") == 0) {
|
|
1730 scf->upstream.cache = NULL;
|
|
1731 return NGX_CONF_OK;
|
|
1732 }
|
|
1733
|
|
1734 if (scf->upstream.store > 0 || scf->upstream.store_lengths) {
|
|
1735 return "is incompatible with \"scgi_store\"";
|
|
1736 }
|
|
1737
|
|
1738 scf->upstream.cache = ngx_shared_memory_add(cf, &value[1], 0,
|
|
1739 &ngx_http_scgi_module);
|
|
1740 if (scf->upstream.cache == NULL) {
|
|
1741 return NGX_CONF_ERROR;
|
|
1742 }
|
|
1743
|
|
1744 return NGX_CONF_OK;
|
|
1745 }
|
|
1746
|
|
1747
|
|
1748 static char *
|
|
1749 ngx_http_scgi_cache_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
1750 {
|
|
1751 ngx_http_scgi_loc_conf_t *scf = conf;
|
|
1752
|
|
1753 ngx_str_t *value;
|
|
1754 ngx_http_compile_complex_value_t ccv;
|
|
1755
|
|
1756 value = cf->args->elts;
|
|
1757
|
|
1758 if (scf->cache_key.value.len) {
|
|
1759 return "is duplicate";
|
|
1760 }
|
|
1761
|
|
1762 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
|
|
1763
|
|
1764 ccv.cf = cf;
|
|
1765 ccv.value = &value[1];
|
|
1766 ccv.complex_value = &scf->cache_key;
|
|
1767
|
|
1768 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
|
|
1769 return NGX_CONF_ERROR;
|
|
1770 }
|
|
1771
|
|
1772 return NGX_CONF_OK;
|
|
1773 }
|
|
1774
|
|
1775 #endif
|