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