Mercurial > hg > nginx
annotate src/http/modules/ngx_http_proxy_module.c @ 2412:086c20fe2e97
set default gzip_buffers to 32 4k or 16 8k
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 16 Dec 2008 16:15:52 +0000 |
parents | d88e757cc7d8 |
children | 7af1e5fe102c |
rev | line source |
---|---|
507 | 1 |
577 | 2 /* |
507 | 3 * Copyright (C) Igor Sysoev |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 #include <ngx_http.h> | |
10 | |
11 | |
509 | 12 typedef struct ngx_http_proxy_redirect_s ngx_http_proxy_redirect_t; |
13 | |
14 typedef ngx_int_t (*ngx_http_proxy_redirect_pt)(ngx_http_request_t *r, | |
15 ngx_table_elt_t *h, size_t prefix, ngx_http_proxy_redirect_t *pr); | |
507 | 16 |
509 | 17 struct ngx_http_proxy_redirect_s { |
651 | 18 ngx_http_proxy_redirect_pt handler; |
19 ngx_str_t redirect; | |
507 | 20 |
509 | 21 union { |
651 | 22 ngx_str_t text; |
509 | 23 |
24 struct { | |
651 | 25 void *lengths; |
26 void *values; | |
509 | 27 } vars; |
507 | 28 |
651 | 29 void *regex; |
509 | 30 } replacement; |
31 }; | |
32 | |
33 | |
34 typedef struct { | |
2391
d88e757cc7d8
delete surplus upstream.schema field
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
35 ngx_str_t schema; |
1658 | 36 ngx_str_t host_header; |
37 ngx_str_t port; | |
38 ngx_str_t uri; | |
39 } ngx_http_proxy_vars_t; | |
40 | |
41 | |
42 typedef struct { | |
651 | 43 ngx_http_upstream_conf_t upstream; |
44 | |
45 ngx_array_t *flushes; | |
46 ngx_array_t *body_set_len; | |
47 ngx_array_t *body_set; | |
48 ngx_array_t *headers_set_len; | |
49 ngx_array_t *headers_set; | |
50 ngx_hash_t headers_set_hash; | |
51 | |
52 ngx_array_t *headers_source; | |
53 ngx_array_t *headers_names; | |
54 | |
1658 | 55 ngx_array_t *proxy_lengths; |
56 ngx_array_t *proxy_values; | |
57 | |
651 | 58 ngx_array_t *redirects; |
59 | |
60 ngx_str_t body_source; | |
61 | |
62 ngx_str_t method; | |
1658 | 63 ngx_str_t location; |
64 ngx_str_t url; | |
65 | |
66 ngx_http_proxy_vars_t vars; | |
651 | 67 |
68 ngx_flag_t redirect; | |
1180
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
69 |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
70 ngx_uint_t headers_hash_max_size; |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
71 ngx_uint_t headers_hash_bucket_size; |
507 | 72 } ngx_http_proxy_loc_conf_t; |
73 | |
74 | |
75 typedef struct { | |
651 | 76 ngx_uint_t status; |
77 ngx_uint_t status_count; | |
78 u_char *status_start; | |
79 u_char *status_end; | |
80 | |
1658 | 81 ngx_http_proxy_vars_t vars; |
82 | |
651 | 83 size_t internal_body_length; |
509 | 84 } ngx_http_proxy_ctx_t; |
507 | 85 |
86 | |
509 | 87 #define NGX_HTTP_PROXY_PARSE_NO_HEADER 20 |
507 | 88 |
89 | |
1658 | 90 static ngx_int_t ngx_http_proxy_eval(ngx_http_request_t *r, |
91 ngx_http_proxy_ctx_t *ctx, ngx_http_proxy_loc_conf_t *plcf); | |
507 | 92 static ngx_int_t ngx_http_proxy_create_request(ngx_http_request_t *r); |
93 static ngx_int_t ngx_http_proxy_reinit_request(ngx_http_request_t *r); | |
509 | 94 static ngx_int_t ngx_http_proxy_process_status_line(ngx_http_request_t *r); |
95 static ngx_int_t ngx_http_proxy_parse_status_line(ngx_http_request_t *r, | |
1658 | 96 ngx_http_proxy_ctx_t *ctx); |
507 | 97 static ngx_int_t ngx_http_proxy_process_header(ngx_http_request_t *r); |
98 static void ngx_http_proxy_abort_request(ngx_http_request_t *r); | |
99 static void ngx_http_proxy_finalize_request(ngx_http_request_t *r, | |
100 ngx_int_t rc); | |
101 | |
573 | 102 static ngx_int_t ngx_http_proxy_host_variable(ngx_http_request_t *r, |
103 ngx_http_variable_value_t *v, uintptr_t data); | |
104 static ngx_int_t ngx_http_proxy_port_variable(ngx_http_request_t *r, | |
105 ngx_http_variable_value_t *v, uintptr_t data); | |
106 static ngx_int_t | |
509 | 107 ngx_http_proxy_add_x_forwarded_for_variable(ngx_http_request_t *r, |
573 | 108 ngx_http_variable_value_t *v, uintptr_t data); |
577 | 109 static ngx_int_t |
110 ngx_http_proxy_internal_body_length_variable(ngx_http_request_t *r, | |
111 ngx_http_variable_value_t *v, uintptr_t data); | |
509 | 112 static ngx_int_t ngx_http_proxy_rewrite_redirect(ngx_http_request_t *r, |
113 ngx_table_elt_t *h, size_t prefix); | |
507 | 114 |
509 | 115 static ngx_int_t ngx_http_proxy_add_variables(ngx_conf_t *cf); |
507 | 116 static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf); |
117 static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, | |
118 void *parent, void *child); | |
119 | |
120 static char *ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, | |
121 void *conf); | |
509 | 122 static char *ngx_http_proxy_redirect(ngx_conf_t *cf, ngx_command_t *cmd, |
123 void *conf); | |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
124 static char *ngx_http_proxy_store(ngx_conf_t *cf, ngx_command_t *cmd, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
125 void *conf); |
507 | 126 |
127 static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data); | |
128 | |
884 | 129 static char *ngx_http_proxy_upstream_max_fails_unsupported(ngx_conf_t *cf, |
130 ngx_command_t *cmd, void *conf); | |
131 static char *ngx_http_proxy_upstream_fail_timeout_unsupported(ngx_conf_t *cf, | |
132 ngx_command_t *cmd, void *conf); | |
133 | |
1658 | 134 #if (NGX_HTTP_SSL) |
135 static ngx_int_t ngx_http_proxy_set_ssl(ngx_conf_t *cf, | |
136 ngx_http_proxy_loc_conf_t *plcf); | |
137 #endif | |
138 static ngx_int_t ngx_http_proxy_set_vars(ngx_pool_t *pool, ngx_url_t *u, | |
139 ngx_http_proxy_vars_t *v); | |
140 | |
509 | 141 |
507 | 142 static ngx_conf_post_t ngx_http_proxy_lowat_post = |
509 | 143 { ngx_http_proxy_lowat_check }; |
144 | |
507 | 145 |
146 static ngx_conf_bitmask_t ngx_http_proxy_next_upstream_masks[] = { | |
147 { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR }, | |
148 { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT }, | |
149 { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER }, | |
150 { ngx_string("http_500"), NGX_HTTP_UPSTREAM_FT_HTTP_500 }, | |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2256
diff
changeset
|
151 { ngx_string("http_502"), NGX_HTTP_UPSTREAM_FT_HTTP_502 }, |
623 | 152 { ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 }, |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2256
diff
changeset
|
153 { ngx_string("http_504"), NGX_HTTP_UPSTREAM_FT_HTTP_504 }, |
507 | 154 { ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 }, |
665 | 155 { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF }, |
507 | 156 { ngx_null_string, 0 } |
157 }; | |
158 | |
159 | |
160 static ngx_command_t ngx_http_proxy_commands[] = { | |
161 | |
162 { ngx_string("proxy_pass"), | |
843
ebab9490204c
allow proxy_pass inside limit_except
Igor Sysoev <igor@sysoev.ru>
parents:
812
diff
changeset
|
163 NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_HTTP_LMT_CONF|NGX_CONF_TAKE1, |
507 | 164 ngx_http_proxy_pass, |
165 NGX_HTTP_LOC_CONF_OFFSET, | |
166 0, | |
167 NULL }, | |
168 | |
509 | 169 { ngx_string("proxy_redirect"), |
170 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12, | |
171 ngx_http_proxy_redirect, | |
172 NGX_HTTP_LOC_CONF_OFFSET, | |
173 0, | |
174 NULL }, | |
175 | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1244
diff
changeset
|
176 { ngx_string("proxy_store"), |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
177 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
178 ngx_http_proxy_store, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
179 NGX_HTTP_LOC_CONF_OFFSET, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
180 0, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
181 NULL }, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
182 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
183 { ngx_string("proxy_store_access"), |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1244
diff
changeset
|
184 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123, |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1244
diff
changeset
|
185 ngx_conf_set_access_slot, |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1244
diff
changeset
|
186 NGX_HTTP_LOC_CONF_OFFSET, |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
187 offsetof(ngx_http_proxy_loc_conf_t, upstream.store_access), |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1244
diff
changeset
|
188 NULL }, |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1244
diff
changeset
|
189 |
581 | 190 { ngx_string("proxy_buffering"), |
191 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
192 ngx_conf_set_flag_slot, | |
193 NGX_HTTP_LOC_CONF_OFFSET, | |
194 offsetof(ngx_http_proxy_loc_conf_t, upstream.buffering), | |
195 NULL }, | |
196 | |
629 | 197 { ngx_string("proxy_ignore_client_abort"), |
198 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
199 ngx_conf_set_flag_slot, | |
200 NGX_HTTP_LOC_CONF_OFFSET, | |
201 offsetof(ngx_http_proxy_loc_conf_t, upstream.ignore_client_abort), | |
202 NULL }, | |
203 | |
507 | 204 { ngx_string("proxy_connect_timeout"), |
205 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
206 ngx_conf_set_msec_slot, | |
207 NGX_HTTP_LOC_CONF_OFFSET, | |
208 offsetof(ngx_http_proxy_loc_conf_t, upstream.connect_timeout), | |
209 NULL }, | |
210 | |
211 { ngx_string("proxy_send_timeout"), | |
212 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
213 ngx_conf_set_msec_slot, | |
214 NGX_HTTP_LOC_CONF_OFFSET, | |
215 offsetof(ngx_http_proxy_loc_conf_t, upstream.send_timeout), | |
216 NULL }, | |
217 | |
218 { ngx_string("proxy_send_lowat"), | |
219 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
220 ngx_conf_set_size_slot, | |
221 NGX_HTTP_LOC_CONF_OFFSET, | |
222 offsetof(ngx_http_proxy_loc_conf_t, upstream.send_lowat), | |
223 &ngx_http_proxy_lowat_post }, | |
224 | |
657 | 225 { ngx_string("proxy_intercept_errors"), |
226 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
227 ngx_conf_set_flag_slot, | |
228 NGX_HTTP_LOC_CONF_OFFSET, | |
229 offsetof(ngx_http_proxy_loc_conf_t, upstream.intercept_errors), | |
230 NULL }, | |
231 | |
509 | 232 { ngx_string("proxy_set_header"), |
233 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, | |
649 | 234 ngx_conf_set_keyval_slot, |
507 | 235 NGX_HTTP_LOC_CONF_OFFSET, |
509 | 236 offsetof(ngx_http_proxy_loc_conf_t, headers_source), |
507 | 237 NULL }, |
238 | |
1180
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
239 { ngx_string("proxy_headers_hash_max_size"), |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
240 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
241 ngx_conf_set_num_slot, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
242 NGX_HTTP_LOC_CONF_OFFSET, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
243 offsetof(ngx_http_proxy_loc_conf_t, headers_hash_max_size), |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
244 NULL }, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
245 |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
246 { ngx_string("proxy_headers_hash_bucket_size"), |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
247 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
248 ngx_conf_set_num_slot, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
249 NGX_HTTP_LOC_CONF_OFFSET, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
250 offsetof(ngx_http_proxy_loc_conf_t, headers_hash_bucket_size), |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
251 NULL }, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
252 |
577 | 253 { ngx_string("proxy_set_body"), |
254 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
255 ngx_conf_set_str_slot, | |
256 NGX_HTTP_LOC_CONF_OFFSET, | |
257 offsetof(ngx_http_proxy_loc_conf_t, body_source), | |
258 NULL }, | |
259 | |
509 | 260 { ngx_string("proxy_method"), |
261 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
561 | 262 ngx_conf_set_str_slot, |
509 | 263 NGX_HTTP_LOC_CONF_OFFSET, |
561 | 264 offsetof(ngx_http_proxy_loc_conf_t, method), |
265 NULL }, | |
509 | 266 |
267 { ngx_string("proxy_pass_request_headers"), | |
507 | 268 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
269 ngx_conf_set_flag_slot, | |
270 NGX_HTTP_LOC_CONF_OFFSET, | |
509 | 271 offsetof(ngx_http_proxy_loc_conf_t, upstream.pass_request_headers), |
507 | 272 NULL }, |
273 | |
509 | 274 { ngx_string("proxy_pass_request_body"), |
507 | 275 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
276 ngx_conf_set_flag_slot, | |
277 NGX_HTTP_LOC_CONF_OFFSET, | |
509 | 278 offsetof(ngx_http_proxy_loc_conf_t, upstream.pass_request_body), |
507 | 279 NULL }, |
280 | |
581 | 281 { ngx_string("proxy_buffer_size"), |
282 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
283 ngx_conf_set_size_slot, | |
284 NGX_HTTP_LOC_CONF_OFFSET, | |
285 offsetof(ngx_http_proxy_loc_conf_t, upstream.buffer_size), | |
286 NULL }, | |
287 | |
507 | 288 { ngx_string("proxy_read_timeout"), |
289 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
290 ngx_conf_set_msec_slot, | |
291 NGX_HTTP_LOC_CONF_OFFSET, | |
292 offsetof(ngx_http_proxy_loc_conf_t, upstream.read_timeout), | |
293 NULL }, | |
294 | |
295 { ngx_string("proxy_buffers"), | |
296 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, | |
297 ngx_conf_set_bufs_slot, | |
298 NGX_HTTP_LOC_CONF_OFFSET, | |
299 offsetof(ngx_http_proxy_loc_conf_t, upstream.bufs), | |
300 NULL }, | |
301 | |
302 { ngx_string("proxy_busy_buffers_size"), | |
303 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
304 ngx_conf_set_size_slot, | |
305 NGX_HTTP_LOC_CONF_OFFSET, | |
529 | 306 offsetof(ngx_http_proxy_loc_conf_t, upstream.busy_buffers_size_conf), |
507 | 307 NULL }, |
308 | |
309 { ngx_string("proxy_temp_path"), | |
310 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234, | |
311 ngx_conf_set_path_slot, | |
312 NGX_HTTP_LOC_CONF_OFFSET, | |
313 offsetof(ngx_http_proxy_loc_conf_t, upstream.temp_path), | |
314 (void *) ngx_garbage_collector_temp_handler }, | |
315 | |
316 { ngx_string("proxy_max_temp_file_size"), | |
317 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
318 ngx_conf_set_size_slot, | |
319 NGX_HTTP_LOC_CONF_OFFSET, | |
529 | 320 offsetof(ngx_http_proxy_loc_conf_t, upstream.max_temp_file_size_conf), |
507 | 321 NULL }, |
322 | |
323 { ngx_string("proxy_temp_file_write_size"), | |
324 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
325 ngx_conf_set_size_slot, | |
326 NGX_HTTP_LOC_CONF_OFFSET, | |
529 | 327 offsetof(ngx_http_proxy_loc_conf_t, upstream.temp_file_write_size_conf), |
507 | 328 NULL }, |
329 | |
330 { ngx_string("proxy_next_upstream"), | |
547 | 331 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, |
507 | 332 ngx_conf_set_bitmask_slot, |
333 NGX_HTTP_LOC_CONF_OFFSET, | |
334 offsetof(ngx_http_proxy_loc_conf_t, upstream.next_upstream), | |
335 &ngx_http_proxy_next_upstream_masks }, | |
336 | |
561 | 337 { ngx_string("proxy_upstream_max_fails"), |
338 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
884 | 339 ngx_http_proxy_upstream_max_fails_unsupported, |
340 0, | |
341 0, | |
561 | 342 NULL }, |
343 | |
344 { ngx_string("proxy_upstream_fail_timeout"), | |
345 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
884 | 346 ngx_http_proxy_upstream_fail_timeout_unsupported, |
347 0, | |
348 0, | |
561 | 349 NULL }, |
350 | |
649 | 351 { ngx_string("proxy_pass_header"), |
507 | 352 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
649 | 353 ngx_conf_set_str_array_slot, |
507 | 354 NGX_HTTP_LOC_CONF_OFFSET, |
649 | 355 offsetof(ngx_http_proxy_loc_conf_t, upstream.pass_headers), |
507 | 356 NULL }, |
357 | |
649 | 358 { ngx_string("proxy_hide_header"), |
507 | 359 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
649 | 360 ngx_conf_set_str_array_slot, |
507 | 361 NGX_HTTP_LOC_CONF_OFFSET, |
649 | 362 offsetof(ngx_http_proxy_loc_conf_t, upstream.hide_headers), |
507 | 363 NULL }, |
364 | |
2184 | 365 #if (NGX_HTTP_SSL) |
366 | |
367 { ngx_string("proxy_ssl_session_reuse"), | |
368 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
369 ngx_conf_set_flag_slot, | |
370 NGX_HTTP_LOC_CONF_OFFSET, | |
371 offsetof(ngx_http_proxy_loc_conf_t, upstream.ssl_session_reuse), | |
372 NULL }, | |
373 | |
374 #endif | |
375 | |
507 | 376 ngx_null_command |
377 }; | |
378 | |
379 | |
667 | 380 static ngx_http_module_t ngx_http_proxy_module_ctx = { |
509 | 381 ngx_http_proxy_add_variables, /* preconfiguration */ |
382 NULL, /* postconfiguration */ | |
507 | 383 |
384 NULL, /* create main configuration */ | |
385 NULL, /* init main configuration */ | |
386 | |
387 NULL, /* create server configuration */ | |
388 NULL, /* merge server configuration */ | |
389 | |
390 ngx_http_proxy_create_loc_conf, /* create location configration */ | |
391 ngx_http_proxy_merge_loc_conf /* merge location configration */ | |
392 }; | |
393 | |
394 | |
395 ngx_module_t ngx_http_proxy_module = { | |
509 | 396 NGX_MODULE_V1, |
507 | 397 &ngx_http_proxy_module_ctx, /* module context */ |
398 ngx_http_proxy_commands, /* module directives */ | |
399 NGX_HTTP_MODULE, /* module type */ | |
541 | 400 NULL, /* init master */ |
509 | 401 NULL, /* init module */ |
541 | 402 NULL, /* init process */ |
403 NULL, /* init thread */ | |
404 NULL, /* exit thread */ | |
405 NULL, /* exit process */ | |
406 NULL, /* exit master */ | |
407 NGX_MODULE_V1_PADDING | |
507 | 408 }; |
409 | |
410 | |
411 static char ngx_http_proxy_version[] = " HTTP/1.0" CRLF; | |
412 | |
509 | 413 |
649 | 414 static ngx_keyval_t ngx_http_proxy_headers[] = { |
415 { ngx_string("Host"), ngx_string("$proxy_host") }, | |
416 { ngx_string("Connection"), ngx_string("close") }, | |
417 { ngx_string("Keep-Alive"), ngx_string("") }, | |
2067 | 418 { ngx_string("Expect"), ngx_string("") }, |
649 | 419 { ngx_null_string, ngx_null_string } |
420 }; | |
421 | |
422 | |
423 static ngx_str_t ngx_http_proxy_hide_headers[] = { | |
424 ngx_string("Date"), | |
425 ngx_string("Server"), | |
426 ngx_string("X-Pad"), | |
427 ngx_string("X-Accel-Expires"), | |
428 ngx_string("X-Accel-Redirect"), | |
429 ngx_string("X-Accel-Limit-Rate"), | |
1886
2819956d1ca0
add X-Accel-Charset to ingored header, fix X-Accel-Buffering
Igor Sysoev <igor@sysoev.ru>
parents:
1774
diff
changeset
|
430 ngx_string("X-Accel-Buffering"), |
2819956d1ca0
add X-Accel-Charset to ingored header, fix X-Accel-Buffering
Igor Sysoev <igor@sysoev.ru>
parents:
1774
diff
changeset
|
431 ngx_string("X-Accel-Charset"), |
649 | 432 ngx_null_string |
509 | 433 }; |
434 | |
435 | |
436 static ngx_http_variable_t ngx_http_proxy_vars[] = { | |
437 | |
637 | 438 { ngx_string("proxy_host"), NULL, ngx_http_proxy_host_variable, 0, |
1925
6fd26b0e1009
non cacheable $proxy_host and $proxy_port
Igor Sysoev <igor@sysoev.ru>
parents:
1912
diff
changeset
|
439 NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 }, |
509 | 440 |
637 | 441 { ngx_string("proxy_port"), NULL, ngx_http_proxy_port_variable, 0, |
1925
6fd26b0e1009
non cacheable $proxy_host and $proxy_port
Igor Sysoev <igor@sysoev.ru>
parents:
1912
diff
changeset
|
442 NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 }, |
509 | 443 |
637 | 444 { ngx_string("proxy_add_x_forwarded_for"), NULL, |
583 | 445 ngx_http_proxy_add_x_forwarded_for_variable, 0, NGX_HTTP_VAR_NOHASH, 0 }, |
509 | 446 |
447 #if 0 | |
637 | 448 { ngx_string("proxy_add_via"), NULL, NULL, 0, NGX_HTTP_VAR_NOHASH, 0 }, |
509 | 449 #endif |
450 | |
637 | 451 { ngx_string("proxy_internal_body_length"), NULL, |
583 | 452 ngx_http_proxy_internal_body_length_variable, 0, NGX_HTTP_VAR_NOHASH, 0 }, |
577 | 453 |
637 | 454 { ngx_null_string, NULL, NULL, 0, 0, 0 } |
509 | 455 }; |
507 | 456 |
457 | |
458 static ngx_int_t | |
459 ngx_http_proxy_handler(ngx_http_request_t *r) | |
577 | 460 { |
507 | 461 ngx_int_t rc; |
462 ngx_http_upstream_t *u; | |
1658 | 463 ngx_http_proxy_ctx_t *ctx; |
507 | 464 ngx_http_proxy_loc_conf_t *plcf; |
577 | 465 |
507 | 466 u = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_t)); |
467 if (u == NULL) { | |
468 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
469 } | |
577 | 470 |
1658 | 471 r->upstream = u; |
472 | |
473 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_ctx_t)); | |
474 if (ctx == NULL) { | |
475 return NGX_ERROR; | |
476 } | |
477 | |
478 ngx_http_set_ctx(r, ctx, ngx_http_proxy_module); | |
479 | |
480 plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module); | |
481 | |
482 if (plcf->proxy_lengths == 0) { | |
483 ctx->vars = plcf->vars; | |
2391
d88e757cc7d8
delete surplus upstream.schema field
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
484 u->schema = plcf->vars.schema; |
1658 | 485 #if (NGX_HTTP_SSL) |
486 u->ssl = (plcf->upstream.ssl != NULL); | |
487 #endif | |
488 | |
489 } else { | |
490 if (ngx_http_proxy_eval(r, ctx, plcf) != NGX_OK) { | |
491 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
492 } | |
493 } | |
494 | |
507 | 495 u->peer.log = r->connection->log; |
496 u->peer.log_error = NGX_ERROR_ERR; | |
497 #if (NGX_THREADS) | |
498 u->peer.lock = &r->connection->lock; | |
499 #endif | |
500 | |
501 u->output.tag = (ngx_buf_tag_t) &ngx_http_proxy_module; | |
502 | |
503 u->conf = &plcf->upstream; | |
504 | |
505 u->create_request = ngx_http_proxy_create_request; | |
506 u->reinit_request = ngx_http_proxy_reinit_request; | |
509 | 507 u->process_header = ngx_http_proxy_process_status_line; |
507 | 508 u->abort_request = ngx_http_proxy_abort_request; |
509 u->finalize_request = ngx_http_proxy_finalize_request; | |
510 | |
509 | 511 if (plcf->redirects) { |
512 u->rewrite_redirect = ngx_http_proxy_rewrite_redirect; | |
513 } | |
514 | |
649 | 515 u->buffering = plcf->upstream.buffering; |
516 | |
517 u->pipe = ngx_pcalloc(r->pool, sizeof(ngx_event_pipe_t)); | |
518 if (u->pipe == NULL) { | |
519 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
581 | 520 } |
507 | 521 |
649 | 522 u->pipe->input_filter = ngx_event_pipe_copy_input_filter; |
523 | |
509 | 524 u->accel = 1; |
577 | 525 |
507 | 526 rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init); |
527 | |
528 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { | |
529 return rc; | |
530 } | |
531 | |
532 return NGX_DONE; | |
533 } | |
534 | |
535 | |
536 static ngx_int_t | |
1658 | 537 ngx_http_proxy_eval(ngx_http_request_t *r, ngx_http_proxy_ctx_t *ctx, |
538 ngx_http_proxy_loc_conf_t *plcf) | |
539 { | |
2284
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2268
diff
changeset
|
540 u_char *p; |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2268
diff
changeset
|
541 size_t add; |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2268
diff
changeset
|
542 u_short port; |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2268
diff
changeset
|
543 ngx_str_t proxy; |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2268
diff
changeset
|
544 ngx_url_t u; |
1658 | 545 |
546 if (ngx_http_script_run(r, &proxy, plcf->proxy_lengths->elts, 0, | |
547 plcf->proxy_values->elts) | |
548 == NULL) | |
549 { | |
550 return NGX_ERROR; | |
551 } | |
552 | |
553 if (ngx_strncasecmp(proxy.data, (u_char *) "http://", 7) == 0) { | |
554 | |
555 add = 7; | |
556 port = 80; | |
557 | |
558 #if (NGX_HTTP_SSL) | |
559 | |
560 } else if (ngx_strncasecmp(proxy.data, (u_char *) "https://", 8) == 0) { | |
561 | |
562 add = 8; | |
563 port = 443; | |
564 r->upstream->ssl = 1; | |
565 | |
566 #endif | |
567 | |
568 } else { | |
569 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
570 "invalid URL prefix in \"%V\"", &proxy); | |
571 return NGX_ERROR; | |
572 } | |
573 | |
574 r->upstream->schema.len = add; | |
575 r->upstream->schema.data = proxy.data; | |
576 | |
577 ngx_memzero(&u, sizeof(ngx_url_t)); | |
578 | |
579 u.url.len = proxy.len - add; | |
580 u.url.data = proxy.data + add; | |
581 u.default_port = port; | |
582 u.uri_part = 1; | |
583 u.no_resolve = 1; | |
584 | |
585 if (ngx_parse_url(r->pool, &u) != NGX_OK) { | |
586 if (u.err) { | |
587 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
588 "%s in upstream \"%V\"", u.err, &u.url); | |
589 } | |
590 | |
591 return NGX_ERROR; | |
592 } | |
593 | |
2284
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2268
diff
changeset
|
594 if (u.uri.len && u.uri.data[0] == '?') { |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2268
diff
changeset
|
595 p = ngx_pnalloc(r->pool, u.uri.len + 1); |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2268
diff
changeset
|
596 if (p == NULL) { |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2268
diff
changeset
|
597 return NGX_ERROR; |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2268
diff
changeset
|
598 } |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2268
diff
changeset
|
599 |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2268
diff
changeset
|
600 *p++ = '/'; |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2268
diff
changeset
|
601 ngx_memcpy(p, u.uri.data, u.uri.len); |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2268
diff
changeset
|
602 |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2268
diff
changeset
|
603 u.uri.len++; |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2268
diff
changeset
|
604 u.uri.data = p - 1; |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2268
diff
changeset
|
605 } |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2268
diff
changeset
|
606 |
1658 | 607 if (ngx_http_proxy_set_vars(r->pool, &u, &ctx->vars) != NGX_OK) { |
608 return NGX_ERROR; | |
609 } | |
610 | |
611 r->upstream->resolved = ngx_pcalloc(r->pool, | |
612 sizeof(ngx_http_upstream_resolved_t)); | |
613 if (r->upstream->resolved == NULL) { | |
614 return NGX_ERROR; | |
615 } | |
616 | |
617 r->upstream->resolved->host = u.host; | |
618 r->upstream->resolved->port = (in_port_t) (u.no_port ? u.default_port: | |
619 u.port); | |
2285 | 620 r->upstream->resolved->no_port = u.no_port; |
1658 | 621 |
622 return NGX_OK; | |
623 } | |
624 | |
625 | |
626 static ngx_int_t | |
507 | 627 ngx_http_proxy_create_request(ngx_http_request_t *r) |
628 { | |
577 | 629 size_t len, loc_len, body_len; |
509 | 630 uintptr_t escape; |
631 ngx_buf_t *b; | |
649 | 632 ngx_str_t method; |
633 ngx_uint_t i, unparsed_uri; | |
509 | 634 ngx_chain_t *cl, *body; |
635 ngx_list_part_t *part; | |
636 ngx_table_elt_t *header; | |
637 ngx_http_upstream_t *u; | |
1658 | 638 ngx_http_proxy_ctx_t *ctx; |
509 | 639 ngx_http_script_code_pt code; |
640 ngx_http_script_engine_t e, le; | |
641 ngx_http_proxy_loc_conf_t *plcf; | |
642 ngx_http_script_len_code_pt lcode; | |
507 | 643 |
644 u = r->upstream; | |
645 | |
646 plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module); | |
647 | |
561 | 648 if (u->method.len) { |
649 /* HEAD was changed to GET to cache response */ | |
650 method = u->method; | |
651 method.len++; | |
652 | |
653 } else if (plcf->method.len) { | |
654 method = plcf->method; | |
655 | |
507 | 656 } else { |
561 | 657 method = r->method_name; |
658 method.len++; | |
507 | 659 } |
660 | |
1667 | 661 len = method.len + sizeof(ngx_http_proxy_version) - 1 + sizeof(CRLF) - 1; |
662 | |
507 | 663 escape = 0; |
1658 | 664 loc_len = 0; |
665 unparsed_uri = 0; | |
666 | |
667 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
668 | |
669 if (plcf->proxy_lengths) { | |
1667 | 670 len += ctx->vars.uri.len; |
1658 | 671 |
672 } else if (ctx->vars.uri.len == 0 && r->valid_unparsed_uri && r == r->main) | |
673 { | |
609 | 674 unparsed_uri = 1; |
1667 | 675 len += r->unparsed_uri.len; |
507 | 676 |
677 } else { | |
1658 | 678 loc_len = (r->valid_location && ctx->vars.uri.len) ? |
679 plcf->location.len : 0; | |
680 | |
1466
943f2ba615cd
escape internal request URI in proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
1353
diff
changeset
|
681 if (r->quoted_uri || r->internal) { |
509 | 682 escape = 2 * ngx_escape_uri(NULL, r->uri.data + loc_len, |
683 r->uri.len - loc_len, NGX_ESCAPE_URI); | |
507 | 684 } |
685 | |
1688 | 686 len += ctx->vars.uri.len + r->uri.len - loc_len + escape |
687 + sizeof("?") - 1 + r->args.len; | |
507 | 688 } |
689 | |
1565 | 690 ngx_http_script_flush_no_cacheable_variables(r, plcf->flushes); |
573 | 691 |
577 | 692 if (plcf->body_set_len) { |
693 le.ip = plcf->body_set_len->elts; | |
694 le.request = r; | |
695 le.flushed = 1; | |
696 body_len = 0; | |
697 | |
698 while (*(uintptr_t *) le.ip) { | |
699 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
700 body_len += lcode(&le); | |
701 } | |
702 | |
1658 | 703 ctx->internal_body_length = body_len; |
577 | 704 len += body_len; |
705 } | |
706 | |
509 | 707 le.ip = plcf->headers_set_len->elts; |
708 le.request = r; | |
573 | 709 le.flushed = 1; |
507 | 710 |
509 | 711 while (*(uintptr_t *) le.ip) { |
712 while (*(uintptr_t *) le.ip) { | |
713 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
714 len += lcode(&le); | |
715 } | |
716 le.ip += sizeof(uintptr_t); | |
507 | 717 } |
718 | |
719 | |
509 | 720 if (plcf->upstream.pass_request_headers) { |
721 part = &r->headers_in.headers.part; | |
722 header = part->elts; | |
723 | |
724 for (i = 0; /* void */; i++) { | |
507 | 725 |
509 | 726 if (i >= part->nelts) { |
727 if (part->next == NULL) { | |
728 break; | |
729 } | |
730 | |
731 part = part->next; | |
732 header = part->elts; | |
577 | 733 i = 0; |
507 | 734 } |
735 | |
649 | 736 if (ngx_hash_find(&plcf->headers_set_hash, header[i].hash, |
737 header[i].lowcase_key, header[i].key.len)) | |
509 | 738 { |
739 continue; | |
740 } | |
741 | |
742 len += header[i].key.len + sizeof(": ") - 1 | |
743 + header[i].value.len + sizeof(CRLF) - 1; | |
507 | 744 } |
509 | 745 } |
507 | 746 |
747 | |
748 b = ngx_create_temp_buf(r->pool, len); | |
749 if (b == NULL) { | |
750 return NGX_ERROR; | |
751 } | |
752 | |
753 cl = ngx_alloc_chain_link(r->pool); | |
754 if (cl == NULL) { | |
755 return NGX_ERROR; | |
756 } | |
757 | |
758 cl->buf = b; | |
759 | |
760 | |
761 /* the request line */ | |
762 | |
573 | 763 b->last = ngx_copy(b->last, method.data, method.len); |
507 | 764 |
555 | 765 u->uri.data = b->last; |
766 | |
1658 | 767 if (plcf->proxy_lengths) { |
768 b->last = ngx_copy(b->last, ctx->vars.uri.data, ctx->vars.uri.len); | |
769 | |
770 } else if (unparsed_uri) { | |
573 | 771 b->last = ngx_copy(b->last, r->unparsed_uri.data, r->unparsed_uri.len); |
772 | |
507 | 773 } else { |
555 | 774 if (r->valid_location) { |
1658 | 775 b->last = ngx_copy(b->last, ctx->vars.uri.data, ctx->vars.uri.len); |
555 | 776 } |
551 | 777 |
507 | 778 if (escape) { |
509 | 779 ngx_escape_uri(b->last, r->uri.data + loc_len, |
780 r->uri.len - loc_len, NGX_ESCAPE_URI); | |
781 b->last += r->uri.len - loc_len + escape; | |
507 | 782 |
577 | 783 } else { |
573 | 784 b->last = ngx_copy(b->last, r->uri.data + loc_len, |
785 r->uri.len - loc_len); | |
507 | 786 } |
787 | |
788 if (r->args.len > 0) { | |
789 *b->last++ = '?'; | |
573 | 790 b->last = ngx_copy(b->last, r->args.data, r->args.len); |
507 | 791 } |
792 } | |
793 | |
555 | 794 u->uri.len = b->last - u->uri.data; |
795 | |
507 | 796 b->last = ngx_cpymem(b->last, ngx_http_proxy_version, |
797 sizeof(ngx_http_proxy_version) - 1); | |
798 | |
577 | 799 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); |
507 | 800 |
801 e.ip = plcf->headers_set->elts; | |
802 e.pos = b->last; | |
509 | 803 e.request = r; |
573 | 804 e.flushed = 1; |
507 | 805 |
509 | 806 le.ip = plcf->headers_set_len->elts; |
807 | |
808 while (*(uintptr_t *) le.ip) { | |
809 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
515 | 810 |
811 /* skip the header line name length */ | |
812 (void) lcode(&le); | |
509 | 813 |
814 if (*(ngx_http_script_len_code_pt *) le.ip) { | |
815 | |
816 for (len = 0; *(uintptr_t *) le.ip; len += lcode(&le)) { | |
817 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
818 } | |
819 | |
820 e.skip = (len == sizeof(CRLF) - 1) ? 1 : 0; | |
821 | |
822 } else { | |
823 e.skip = 0; | |
824 } | |
825 | |
826 le.ip += sizeof(uintptr_t); | |
827 | |
828 while (*(uintptr_t *) e.ip) { | |
829 code = *(ngx_http_script_code_pt *) e.ip; | |
830 code((ngx_http_script_engine_t *) &e); | |
577 | 831 } |
509 | 832 e.ip += sizeof(uintptr_t); |
507 | 833 } |
834 | |
835 b->last = e.pos; | |
836 | |
837 | |
509 | 838 if (plcf->upstream.pass_request_headers) { |
839 part = &r->headers_in.headers.part; | |
840 header = part->elts; | |
577 | 841 |
509 | 842 for (i = 0; /* void */; i++) { |
507 | 843 |
509 | 844 if (i >= part->nelts) { |
845 if (part->next == NULL) { | |
846 break; | |
847 } | |
848 | |
849 part = part->next; | |
850 header = part->elts; | |
577 | 851 i = 0; |
507 | 852 } |
853 | |
649 | 854 if (ngx_hash_find(&plcf->headers_set_hash, header[i].hash, |
855 header[i].lowcase_key, header[i].key.len)) | |
509 | 856 { |
857 continue; | |
858 } | |
507 | 859 |
573 | 860 b->last = ngx_copy(b->last, header[i].key.data, header[i].key.len); |
507 | 861 |
509 | 862 *b->last++ = ':'; *b->last++ = ' '; |
507 | 863 |
573 | 864 b->last = ngx_copy(b->last, header[i].value.data, |
865 header[i].value.len); | |
507 | 866 |
509 | 867 *b->last++ = CR; *b->last++ = LF; |
507 | 868 |
509 | 869 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
870 "http proxy header: \"%V: %V\"", | |
871 &header[i].key, &header[i].value); | |
872 } | |
507 | 873 } |
874 | |
577 | 875 |
507 | 876 /* add "\r\n" at the header end */ |
877 *b->last++ = CR; *b->last++ = LF; | |
878 | |
577 | 879 if (plcf->body_set) { |
880 e.ip = plcf->body_set->elts; | |
881 e.pos = b->last; | |
882 | |
883 while (*(uintptr_t *) e.ip) { | |
884 code = *(ngx_http_script_code_pt *) e.ip; | |
885 code((ngx_http_script_engine_t *) &e); | |
886 } | |
579 | 887 |
888 b->last = e.pos; | |
577 | 889 } |
890 | |
1774 | 891 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
892 "http proxy header:\n\"%*s\"", | |
893 (size_t) (b->last - b->pos), b->pos); | |
507 | 894 |
577 | 895 if (plcf->body_set == NULL && plcf->upstream.pass_request_body) { |
509 | 896 |
897 body = u->request_bufs; | |
898 u->request_bufs = cl; | |
899 | |
900 while (body) { | |
901 b = ngx_alloc_buf(r->pool); | |
902 if (b == NULL) { | |
903 return NGX_ERROR; | |
904 } | |
905 | |
906 ngx_memcpy(b, body->buf, sizeof(ngx_buf_t)); | |
907 | |
908 cl->next = ngx_alloc_chain_link(r->pool); | |
909 if (cl->next == NULL) { | |
910 return NGX_ERROR; | |
911 } | |
912 | |
913 cl = cl->next; | |
914 cl->buf = b; | |
915 | |
916 body = body->next; | |
917 } | |
918 | |
611 | 919 b->flush = 1; |
920 | |
509 | 921 } else { |
922 u->request_bufs = cl; | |
923 } | |
924 | |
925 cl->next = NULL; | |
926 | |
507 | 927 return NGX_OK; |
928 } | |
929 | |
930 | |
931 static ngx_int_t | |
932 ngx_http_proxy_reinit_request(ngx_http_request_t *r) | |
933 { | |
1658 | 934 ngx_http_proxy_ctx_t *ctx; |
935 | |
936 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
937 | |
938 if (ctx == NULL) { | |
509 | 939 return NGX_OK; |
940 } | |
941 | |
1658 | 942 ctx->status = 0; |
943 ctx->status_count = 0; | |
944 ctx->status_start = NULL; | |
945 ctx->status_end = NULL; | |
509 | 946 |
947 r->upstream->process_header = ngx_http_proxy_process_status_line; | |
948 | |
949 return NGX_OK; | |
950 } | |
951 | |
952 | |
953 static ngx_int_t | |
954 ngx_http_proxy_process_status_line(ngx_http_request_t *r) | |
955 { | |
956 ngx_int_t rc; | |
957 ngx_http_upstream_t *u; | |
1658 | 958 ngx_http_proxy_ctx_t *ctx; |
959 | |
960 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
961 | |
962 if (ctx == NULL) { | |
1699
976db8c6fb64
return NGX_ERROR instead of NGX_HTTP_INTERNAL_SERVER_ERROR in u->parse_header()
Igor Sysoev <igor@sysoev.ru>
parents:
1688
diff
changeset
|
963 return NGX_ERROR; |
509 | 964 } |
965 | |
1658 | 966 rc = ngx_http_proxy_parse_status_line(r, ctx); |
509 | 967 |
968 if (rc == NGX_AGAIN) { | |
969 return rc; | |
970 } | |
971 | |
972 u = r->upstream; | |
973 | |
974 if (rc == NGX_HTTP_PROXY_PARSE_NO_HEADER) { | |
975 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
577 | 976 "upstream sent no valid HTTP/1.0 header"); |
509 | 977 |
619 | 978 #if 0 |
509 | 979 if (u->accel) { |
980 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | |
981 } | |
619 | 982 #endif |
509 | 983 |
984 r->http_version = NGX_HTTP_VERSION_9; | |
1616 | 985 u->headers_in.status_n = NGX_HTTP_OK; |
986 u->state->status = NGX_HTTP_OK; | |
577 | 987 |
509 | 988 return NGX_OK; |
989 } | |
990 | |
1658 | 991 u->headers_in.status_n = ctx->status; |
992 u->state->status = ctx->status; | |
993 | |
994 u->headers_in.status_line.len = ctx->status_end - ctx->status_start; | |
2049 | 995 u->headers_in.status_line.data = ngx_pnalloc(r->pool, |
996 u->headers_in.status_line.len); | |
529 | 997 if (u->headers_in.status_line.data == NULL) { |
1699
976db8c6fb64
return NGX_ERROR instead of NGX_HTTP_INTERNAL_SERVER_ERROR in u->parse_header()
Igor Sysoev <igor@sysoev.ru>
parents:
1688
diff
changeset
|
998 return NGX_ERROR; |
509 | 999 } |
573 | 1000 |
1658 | 1001 ngx_memcpy(u->headers_in.status_line.data, ctx->status_start, |
529 | 1002 u->headers_in.status_line.len); |
509 | 1003 |
1004 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1005 "http proxy status %ui \"%V\"", | |
936 | 1006 u->headers_in.status_n, &u->headers_in.status_line); |
509 | 1007 |
1008 u->process_header = ngx_http_proxy_process_header; | |
1009 | |
1010 return ngx_http_proxy_process_header(r); | |
1011 } | |
1012 | |
1013 | |
1014 static ngx_int_t | |
1658 | 1015 ngx_http_proxy_parse_status_line(ngx_http_request_t *r, |
1016 ngx_http_proxy_ctx_t *ctx) | |
509 | 1017 { |
1018 u_char ch; | |
1658 | 1019 u_char *p; |
509 | 1020 ngx_http_upstream_t *u; |
1021 enum { | |
1022 sw_start = 0, | |
1023 sw_H, | |
1024 sw_HT, | |
1025 sw_HTT, | |
1026 sw_HTTP, | |
1027 sw_first_major_digit, | |
1028 sw_major_digit, | |
1029 sw_first_minor_digit, | |
1030 sw_minor_digit, | |
1031 sw_status, | |
1032 sw_space_after_status, | |
1033 sw_status_text, | |
1034 sw_almost_done | |
577 | 1035 } state; |
509 | 1036 |
1037 u = r->upstream; | |
1038 | |
1039 state = r->state; | |
1040 | |
1658 | 1041 for (p = u->buffer.pos; p < u->buffer.last; p++) { |
1042 ch = *p; | |
509 | 1043 |
1044 switch (state) { | |
1045 | |
1046 /* "HTTP/" */ | |
1047 case sw_start: | |
1048 switch (ch) { | |
577 | 1049 case 'H': |
509 | 1050 state = sw_H; |
1051 break; | |
1052 default: | |
1053 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1054 } | |
1055 break; | |
1056 | |
577 | 1057 case sw_H: |
509 | 1058 switch (ch) { |
577 | 1059 case 'T': |
509 | 1060 state = sw_HT; |
1061 break; | |
1062 default: | |
1063 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1064 } | |
1065 break; | |
1066 | |
1067 case sw_HT: | |
1068 switch (ch) { | |
577 | 1069 case 'T': |
509 | 1070 state = sw_HTT; |
1071 break; | |
1072 default: | |
1073 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1074 } | |
1075 break; | |
1076 | |
1077 case sw_HTT: | |
1078 switch (ch) { | |
577 | 1079 case 'P': |
509 | 1080 state = sw_HTTP; |
1081 break; | |
1082 default: | |
1083 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1084 } | |
1085 break; | |
1086 | |
1087 case sw_HTTP: | |
1088 switch (ch) { | |
577 | 1089 case '/': |
509 | 1090 state = sw_first_major_digit; |
1091 break; | |
1092 default: | |
1093 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1094 } | |
1095 break; | |
1096 | |
1097 /* the first digit of major HTTP version */ | |
1098 case sw_first_major_digit: | |
1099 if (ch < '1' || ch > '9') { | |
1100 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1101 } | |
1102 | |
1103 state = sw_major_digit; | |
1104 break; | |
1105 | |
1106 /* the major HTTP version or dot */ | |
1107 case sw_major_digit: | |
1108 if (ch == '.') { | |
1109 state = sw_first_minor_digit; | |
1110 break; | |
1111 } | |
1112 | |
1113 if (ch < '0' || ch > '9') { | |
1114 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1115 } | |
1116 | |
1117 break; | |
1118 | |
1119 /* the first digit of minor HTTP version */ | |
1120 case sw_first_minor_digit: | |
1121 if (ch < '0' || ch > '9') { | |
1122 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1123 } | |
1124 | |
1125 state = sw_minor_digit; | |
1126 break; | |
1127 | |
1128 /* the minor HTTP version or the end of the request line */ | |
1129 case sw_minor_digit: | |
1130 if (ch == ' ') { | |
1131 state = sw_status; | |
1132 break; | |
1133 } | |
1134 | |
1135 if (ch < '0' || ch > '9') { | |
1136 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1137 } | |
1138 | |
1139 break; | |
1140 | |
1141 /* HTTP status code */ | |
1142 case sw_status: | |
619 | 1143 if (ch == ' ') { |
1144 break; | |
1145 } | |
1146 | |
509 | 1147 if (ch < '0' || ch > '9') { |
1148 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1149 } | |
1150 | |
1658 | 1151 ctx->status = ctx->status * 10 + ch - '0'; |
1152 | |
1153 if (++ctx->status_count == 3) { | |
509 | 1154 state = sw_space_after_status; |
1658 | 1155 ctx->status_start = p - 2; |
509 | 1156 } |
1157 | |
1158 break; | |
1159 | |
1160 /* space or end of line */ | |
1161 case sw_space_after_status: | |
1162 switch (ch) { | |
577 | 1163 case ' ': |
509 | 1164 state = sw_status_text; |
1165 break; | |
1166 case '.': /* IIS may send 403.1, 403.2, etc */ | |
1167 state = sw_status_text; | |
1168 break; | |
1169 case CR: | |
1170 state = sw_almost_done; | |
1171 break; | |
1172 case LF: | |
1173 goto done; | |
1174 default: | |
1175 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1176 } | |
1177 break; | |
1178 | |
1179 /* any text until end of line */ | |
1180 case sw_status_text: | |
1181 switch (ch) { | |
1182 case CR: | |
1183 state = sw_almost_done; | |
1184 | |
1185 break; | |
1186 case LF: | |
1187 goto done; | |
1188 } | |
1189 break; | |
1190 | |
527 | 1191 /* end of status line */ |
509 | 1192 case sw_almost_done: |
1658 | 1193 ctx->status_end = p - 1; |
509 | 1194 switch (ch) { |
1195 case LF: | |
1196 goto done; | |
1197 default: | |
1198 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1199 } | |
1200 } | |
1201 } | |
1202 | |
1658 | 1203 u->buffer.pos = p; |
509 | 1204 r->state = state; |
1205 | |
1206 return NGX_AGAIN; | |
1207 | |
1208 done: | |
1209 | |
1658 | 1210 u->buffer.pos = p + 1; |
1211 | |
1212 if (ctx->status_end == NULL) { | |
1213 ctx->status_end = p; | |
509 | 1214 } |
1215 | |
1216 r->state = sw_start; | |
1217 | |
507 | 1218 return NGX_OK; |
1219 } | |
1220 | |
1221 | |
1222 static ngx_int_t | |
1223 ngx_http_proxy_process_header(ngx_http_request_t *r) | |
1224 { | |
509 | 1225 ngx_int_t rc; |
1226 ngx_table_elt_t *h; | |
1227 ngx_http_upstream_header_t *hh; | |
1228 ngx_http_upstream_main_conf_t *umcf; | |
1229 | |
1230 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); | |
1231 | |
2024 | 1232 for ( ;; ) { |
509 | 1233 |
2256 | 1234 rc = ngx_http_parse_header_line(r, &r->upstream->buffer, 1); |
509 | 1235 |
1236 if (rc == NGX_OK) { | |
1237 | |
1238 /* a header line has been parsed successfully */ | |
507 | 1239 |
509 | 1240 h = ngx_list_push(&r->upstream->headers_in.headers); |
1241 if (h == NULL) { | |
1699
976db8c6fb64
return NGX_ERROR instead of NGX_HTTP_INTERNAL_SERVER_ERROR in u->parse_header()
Igor Sysoev <igor@sysoev.ru>
parents:
1688
diff
changeset
|
1242 return NGX_ERROR; |
509 | 1243 } |
1244 | |
1245 h->hash = r->header_hash; | |
1246 | |
1247 h->key.len = r->header_name_end - r->header_name_start; | |
1248 h->value.len = r->header_end - r->header_start; | |
1249 | |
2049 | 1250 h->key.data = ngx_pnalloc(r->pool, |
649 | 1251 h->key.len + 1 + h->value.len + 1 + h->key.len); |
509 | 1252 if (h->key.data == NULL) { |
1699
976db8c6fb64
return NGX_ERROR instead of NGX_HTTP_INTERNAL_SERVER_ERROR in u->parse_header()
Igor Sysoev <igor@sysoev.ru>
parents:
1688
diff
changeset
|
1253 return NGX_ERROR; |
509 | 1254 } |
1255 | |
1256 h->value.data = h->key.data + h->key.len + 1; | |
649 | 1257 h->lowcase_key = h->key.data + h->key.len + 1 + h->value.len + 1; |
507 | 1258 |
509 | 1259 ngx_cpystrn(h->key.data, r->header_name_start, h->key.len + 1); |
1260 ngx_cpystrn(h->value.data, r->header_start, h->value.len + 1); | |
1261 | |
649 | 1262 if (h->key.len == r->lowcase_index) { |
1263 ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len); | |
1264 | |
1265 } else { | |
2135 | 1266 ngx_strlow(h->lowcase_key, h->key.data, h->key.len); |
509 | 1267 } |
1268 | |
649 | 1269 hh = ngx_hash_find(&umcf->headers_in_hash, h->hash, |
1270 h->lowcase_key, h->key.len); | |
1271 | |
1272 if (hh && hh->handler(r, h, hh->offset) != NGX_OK) { | |
1699
976db8c6fb64
return NGX_ERROR instead of NGX_HTTP_INTERNAL_SERVER_ERROR in u->parse_header()
Igor Sysoev <igor@sysoev.ru>
parents:
1688
diff
changeset
|
1273 return NGX_ERROR; |
649 | 1274 } |
1275 | |
509 | 1276 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1277 "http proxy header: \"%V: %V\"", | |
1278 &h->key, &h->value); | |
1279 | |
1280 continue; | |
1281 } | |
1282 | |
1283 if (rc == NGX_HTTP_PARSE_HEADER_DONE) { | |
1284 | |
1285 /* a whole header has been parsed successfully */ | |
1286 | |
1287 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1288 "http proxy header done"); | |
1289 | |
649 | 1290 /* |
1291 * if no "Server" and "Date" in header line, | |
1292 * then add the special empty headers | |
1293 */ | |
1294 | |
1295 if (r->upstream->headers_in.server == NULL) { | |
1296 h = ngx_list_push(&r->upstream->headers_in.headers); | |
1297 if (h == NULL) { | |
1699
976db8c6fb64
return NGX_ERROR instead of NGX_HTTP_INTERNAL_SERVER_ERROR in u->parse_header()
Igor Sysoev <igor@sysoev.ru>
parents:
1688
diff
changeset
|
1298 return NGX_ERROR; |
649 | 1299 } |
1300 | |
1301 h->hash = ngx_hash(ngx_hash(ngx_hash(ngx_hash( | |
1302 ngx_hash('s', 'e'), 'r'), 'v'), 'e'), 'r'); | |
1303 | |
1304 h->key.len = sizeof("Server") - 1; | |
1305 h->key.data = (u_char *) "Server"; | |
1306 h->value.len = 0; | |
1307 h->value.data = NULL; | |
1308 h->lowcase_key = (u_char *) "server"; | |
1309 } | |
1310 | |
1311 if (r->upstream->headers_in.date == NULL) { | |
1312 h = ngx_list_push(&r->upstream->headers_in.headers); | |
1313 if (h == NULL) { | |
1699
976db8c6fb64
return NGX_ERROR instead of NGX_HTTP_INTERNAL_SERVER_ERROR in u->parse_header()
Igor Sysoev <igor@sysoev.ru>
parents:
1688
diff
changeset
|
1314 return NGX_ERROR; |
649 | 1315 } |
1316 | |
1317 h->hash = ngx_hash(ngx_hash(ngx_hash('d', 'a'), 't'), 'e'); | |
1318 | |
1319 h->key.len = sizeof("Date") - 1; | |
1320 h->key.data = (u_char *) "Date"; | |
1321 h->value.len = 0; | |
1322 h->value.data = NULL; | |
1323 h->lowcase_key = (u_char *) "date"; | |
1324 } | |
1325 | |
509 | 1326 return NGX_OK; |
1327 } | |
1328 | |
521 | 1329 if (rc == NGX_AGAIN) { |
1330 return NGX_AGAIN; | |
1331 } | |
1332 | |
509 | 1333 /* there was error while a header line parsing */ |
1334 | |
1335 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
619 | 1336 "upstream sent invalid header"); |
509 | 1337 |
1338 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | |
1339 } | |
507 | 1340 } |
1341 | |
1342 | |
1343 static void | |
1344 ngx_http_proxy_abort_request(ngx_http_request_t *r) | |
1345 { | |
1346 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1347 "abort http proxy request"); | |
577 | 1348 |
507 | 1349 return; |
1350 } | |
1351 | |
1352 | |
1353 static void | |
1354 ngx_http_proxy_finalize_request(ngx_http_request_t *r, ngx_int_t rc) | |
577 | 1355 { |
507 | 1356 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1357 "finalize http proxy request"); | |
1358 | |
1359 return; | |
1360 } | |
1361 | |
1362 | |
573 | 1363 static ngx_int_t |
1364 ngx_http_proxy_host_variable(ngx_http_request_t *r, | |
1365 ngx_http_variable_value_t *v, uintptr_t data) | |
507 | 1366 { |
1658 | 1367 ngx_http_proxy_ctx_t *ctx; |
1368 | |
1369 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
1370 | |
1371 if (ctx == NULL) { | |
1372 v->not_found = 1; | |
1373 return NGX_OK; | |
1374 } | |
1375 | |
1376 v->len = ctx->vars.host_header.len; | |
577 | 1377 v->valid = 1; |
1565 | 1378 v->no_cacheable = 0; |
573 | 1379 v->not_found = 0; |
1658 | 1380 v->data = ctx->vars.host_header.data; |
507 | 1381 |
573 | 1382 return NGX_OK; |
507 | 1383 } |
1384 | |
1385 | |
573 | 1386 static ngx_int_t |
1387 ngx_http_proxy_port_variable(ngx_http_request_t *r, | |
1388 ngx_http_variable_value_t *v, uintptr_t data) | |
507 | 1389 { |
1658 | 1390 ngx_http_proxy_ctx_t *ctx; |
1391 | |
1392 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
1393 | |
1394 if (ctx == NULL) { | |
1395 v->not_found = 1; | |
1396 return NGX_OK; | |
1397 } | |
1398 | |
1399 v->len = ctx->vars.port.len; | |
577 | 1400 v->valid = 1; |
1565 | 1401 v->no_cacheable = 0; |
573 | 1402 v->not_found = 0; |
1658 | 1403 v->data = ctx->vars.port.data; |
509 | 1404 |
573 | 1405 return NGX_OK; |
509 | 1406 } |
1407 | |
1408 | |
573 | 1409 static ngx_int_t |
509 | 1410 ngx_http_proxy_add_x_forwarded_for_variable(ngx_http_request_t *r, |
573 | 1411 ngx_http_variable_value_t *v, uintptr_t data) |
509 | 1412 { |
573 | 1413 u_char *p; |
509 | 1414 |
577 | 1415 v->valid = 1; |
1565 | 1416 v->no_cacheable = 0; |
573 | 1417 v->not_found = 0; |
509 | 1418 |
1419 if (r->headers_in.x_forwarded_for == NULL) { | |
573 | 1420 v->len = r->connection->addr_text.len; |
1421 v->data = r->connection->addr_text.data; | |
1422 return NGX_OK; | |
509 | 1423 } |
1424 | |
573 | 1425 v->len = r->headers_in.x_forwarded_for->value.len |
1426 + sizeof(", ") - 1 + r->connection->addr_text.len; | |
509 | 1427 |
2049 | 1428 p = ngx_pnalloc(r->pool, v->len); |
509 | 1429 if (p == NULL) { |
573 | 1430 return NGX_ERROR; |
509 | 1431 } |
1432 | |
573 | 1433 v->data = p; |
509 | 1434 |
573 | 1435 p = ngx_copy(p, r->headers_in.x_forwarded_for->value.data, |
1436 r->headers_in.x_forwarded_for->value.len); | |
509 | 1437 |
1438 *p++ = ','; *p++ = ' '; | |
1439 | |
1440 ngx_memcpy(p, r->connection->addr_text.data, r->connection->addr_text.len); | |
1441 | |
573 | 1442 return NGX_OK; |
509 | 1443 } |
1444 | |
1445 | |
1446 static ngx_int_t | |
577 | 1447 ngx_http_proxy_internal_body_length_variable(ngx_http_request_t *r, |
1448 ngx_http_variable_value_t *v, uintptr_t data) | |
1449 { | |
1658 | 1450 ngx_http_proxy_ctx_t *ctx; |
1451 | |
1452 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
1453 | |
1454 if (ctx == NULL) { | |
577 | 1455 v->not_found = 1; |
1456 return NGX_OK; | |
1457 } | |
1458 | |
1459 v->valid = 1; | |
1565 | 1460 v->no_cacheable = 0; |
577 | 1461 v->not_found = 0; |
1462 | |
2049 | 1463 v->data = ngx_pnalloc(r->connection->pool, NGX_SIZE_T_LEN); |
577 | 1464 |
1465 if (v->data == NULL) { | |
1466 return NGX_ERROR; | |
1467 } | |
1468 | |
1658 | 1469 v->len = ngx_sprintf(v->data, "%uz", ctx->internal_body_length) - v->data; |
577 | 1470 |
1471 return NGX_OK; | |
1472 } | |
1473 | |
1474 | |
1475 static ngx_int_t | |
509 | 1476 ngx_http_proxy_rewrite_redirect(ngx_http_request_t *r, ngx_table_elt_t *h, |
1477 size_t prefix) | |
1478 { | |
1479 ngx_int_t rc; | |
1480 ngx_uint_t i; | |
1481 ngx_http_proxy_loc_conf_t *plcf; | |
1482 ngx_http_proxy_redirect_t *pr; | |
1483 | |
1484 plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module); | |
1485 | |
1486 pr = plcf->redirects->elts; | |
1487 | |
1488 if (pr == NULL) { | |
1489 return NGX_DECLINED; | |
1490 } | |
1491 | |
1492 for (i = 0; i < plcf->redirects->nelts; i++) { | |
605 | 1493 rc = pr[i].handler(r, h, prefix, &pr[i]); |
509 | 1494 |
1495 if (rc != NGX_DECLINED) { | |
1496 return rc; | |
1497 } | |
1498 } | |
1499 | |
1500 return NGX_DECLINED; | |
1501 } | |
1502 | |
1503 | |
1504 static ngx_int_t | |
1505 ngx_http_proxy_rewrite_redirect_text(ngx_http_request_t *r, ngx_table_elt_t *h, | |
1506 size_t prefix, ngx_http_proxy_redirect_t *pr) | |
1507 { | |
1508 size_t len; | |
1509 u_char *data, *p; | |
1510 | |
1511 if (pr->redirect.len > h->value.len - prefix | |
1512 || ngx_rstrncmp(h->value.data + prefix, pr->redirect.data, | |
1513 pr->redirect.len) != 0) | |
1514 { | |
1515 return NGX_DECLINED; | |
1516 } | |
1517 | |
1518 len = prefix + pr->replacement.text.len + h->value.len - pr->redirect.len; | |
507 | 1519 |
2049 | 1520 data = ngx_pnalloc(r->pool, len); |
509 | 1521 if (data == NULL) { |
1522 return NGX_ERROR; | |
1523 } | |
1524 | |
1525 p = data; | |
1526 | |
573 | 1527 p = ngx_copy(p, h->value.data, prefix); |
509 | 1528 |
653 | 1529 if (pr->replacement.text.len) { |
1530 p = ngx_copy(p, pr->replacement.text.data, pr->replacement.text.len); | |
1531 } | |
509 | 1532 |
1533 ngx_memcpy(p, h->value.data + prefix + pr->redirect.len, | |
1534 h->value.len - pr->redirect.len - prefix); | |
1535 | |
1536 h->value.len = len; | |
1537 h->value.data = data; | |
1538 | |
1539 return NGX_OK; | |
1540 } | |
1541 | |
1542 | |
1543 static ngx_int_t | |
1544 ngx_http_proxy_rewrite_redirect_vars(ngx_http_request_t *r, ngx_table_elt_t *h, | |
1545 size_t prefix, ngx_http_proxy_redirect_t *pr) | |
1546 { | |
1547 size_t len; | |
1548 u_char *data, *p; | |
1549 ngx_http_script_code_pt code; | |
1550 ngx_http_script_engine_t e; | |
1551 ngx_http_script_len_code_pt lcode; | |
1552 | |
1553 if (pr->redirect.len > h->value.len - prefix | |
1554 || ngx_rstrncmp(h->value.data + prefix, pr->redirect.data, | |
1555 pr->redirect.len) != 0) | |
1556 { | |
1557 return NGX_DECLINED; | |
1558 } | |
1559 | |
1560 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); | |
1561 | |
1562 e.ip = pr->replacement.vars.lengths; | |
1563 e.request = r; | |
1564 | |
723
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1565 len = prefix + h->value.len - pr->redirect.len; |
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1566 |
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1567 while (*(uintptr_t *) e.ip) { |
509 | 1568 lcode = *(ngx_http_script_len_code_pt *) e.ip; |
723
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1569 len += lcode(&e); |
509 | 1570 } |
1571 | |
2049 | 1572 data = ngx_pnalloc(r->pool, len); |
509 | 1573 if (data == NULL) { |
1574 return NGX_ERROR; | |
1575 } | |
1576 | |
1577 p = data; | |
1578 | |
573 | 1579 p = ngx_copy(p, h->value.data, prefix); |
509 | 1580 |
1581 e.ip = pr->replacement.vars.values; | |
1582 e.pos = p; | |
1583 | |
1584 while (*(uintptr_t *) e.ip) { | |
1585 code = *(ngx_http_script_code_pt *) e.ip; | |
1586 code(&e); | |
1587 } | |
1588 | |
723
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1589 ngx_memcpy(e.pos, h->value.data + prefix + pr->redirect.len, |
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1590 h->value.len - pr->redirect.len - prefix); |
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1591 |
509 | 1592 h->value.len = len; |
1593 h->value.data = data; | |
1594 | |
1595 return NGX_OK; | |
1596 } | |
1597 | |
1598 | |
1599 static ngx_int_t | |
1600 ngx_http_proxy_add_variables(ngx_conf_t *cf) | |
1601 { | |
1602 ngx_http_variable_t *var, *v; | |
1603 | |
1604 for (v = ngx_http_proxy_vars; v->name.len; v++) { | |
1605 var = ngx_http_add_variable(cf, &v->name, v->flags); | |
1606 if (var == NULL) { | |
1607 return NGX_ERROR; | |
1608 } | |
1609 | |
637 | 1610 var->get_handler = v->get_handler; |
509 | 1611 var->data = v->data; |
1612 } | |
1613 | |
1614 return NGX_OK; | |
507 | 1615 } |
1616 | |
1617 | |
1618 static void * | |
1619 ngx_http_proxy_create_loc_conf(ngx_conf_t *cf) | |
1620 { | |
1621 ngx_http_proxy_loc_conf_t *conf; | |
1622 | |
1623 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_proxy_loc_conf_t)); | |
1624 if (conf == NULL) { | |
1625 return NGX_CONF_ERROR; | |
1626 } | |
1627 | |
1628 /* | |
1629 * set by ngx_pcalloc(): | |
1630 * | |
1631 * conf->upstream.bufs.num = 0; | |
1632 * conf->upstream.next_upstream = 0; | |
1633 * conf->upstream.temp_path = NULL; | |
649 | 1634 * conf->upstream.hide_headers_hash = { NULL, 0 }; |
509 | 1635 * conf->upstream.uri = { 0, NULL }; |
1636 * conf->upstream.location = NULL; | |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1637 * conf->upstream.store_lengths = NULL; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1638 * conf->upstream.store_values = NULL; |
509 | 1639 * |
561 | 1640 * conf->method = NULL; |
509 | 1641 * conf->headers_source = NULL; |
1642 * conf->headers_set_len = NULL; | |
1643 * conf->headers_set = NULL; | |
1644 * conf->headers_set_hash = NULL; | |
577 | 1645 * conf->body_set_len = NULL; |
1646 * conf->body_set = NULL; | |
1647 * conf->body_source = { 0, NULL }; | |
509 | 1648 * conf->rewrite_locations = NULL; |
507 | 1649 */ |
577 | 1650 |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1651 conf->upstream.store = NGX_CONF_UNSET; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1652 conf->upstream.store_access = NGX_CONF_UNSET_UINT; |
581 | 1653 conf->upstream.buffering = NGX_CONF_UNSET; |
629 | 1654 conf->upstream.ignore_client_abort = NGX_CONF_UNSET; |
581 | 1655 |
507 | 1656 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC; |
1657 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC; | |
1658 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC; | |
1659 | |
1660 conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE; | |
581 | 1661 conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE; |
529 | 1662 |
1663 conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE; | |
577 | 1664 conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE; |
529 | 1665 conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE; |
509 | 1666 |
1667 conf->upstream.pass_request_headers = NGX_CONF_UNSET; | |
1668 conf->upstream.pass_request_body = NGX_CONF_UNSET; | |
561 | 1669 |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
1670 conf->upstream.hide_headers = NGX_CONF_UNSET_PTR; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
1671 conf->upstream.pass_headers = NGX_CONF_UNSET_PTR; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
1672 |
657 | 1673 conf->upstream.intercept_errors = NGX_CONF_UNSET; |
2184 | 1674 #if (NGX_HTTP_SSL) |
1675 conf->upstream.ssl_session_reuse = NGX_CONF_UNSET; | |
1676 #endif | |
507 | 1677 |
1678 /* "proxy_cyclic_temp_file" is disabled */ | |
1679 conf->upstream.cyclic_temp_file = 0; | |
1680 | |
509 | 1681 conf->redirect = NGX_CONF_UNSET; |
649 | 1682 conf->upstream.change_buffering = 1; |
507 | 1683 |
1180
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1684 conf->headers_hash_max_size = NGX_CONF_UNSET_UINT; |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1685 conf->headers_hash_bucket_size = NGX_CONF_UNSET_UINT; |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1686 |
507 | 1687 return conf; |
1688 } | |
1689 | |
1690 | |
1691 static char * | |
1692 ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | |
1693 { | |
1694 ngx_http_proxy_loc_conf_t *prev = parent; | |
1695 ngx_http_proxy_loc_conf_t *conf = child; | |
1696 | |
509 | 1697 u_char *p; |
1698 size_t size; | |
1699 uintptr_t *code; | |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
1700 ngx_uint_t i; |
649 | 1701 ngx_keyval_t *src, *s, *h; |
1702 ngx_hash_key_t *hk; | |
1703 ngx_hash_init_t hash; | |
509 | 1704 ngx_http_proxy_redirect_t *pr; |
1705 ngx_http_script_compile_t sc; | |
1706 ngx_http_script_copy_code_t *copy; | |
1707 | |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1708 if (conf->upstream.store != 0) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1709 ngx_conf_merge_value(conf->upstream.store, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1710 prev->upstream.store, 0); |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1711 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1712 if (conf->upstream.store_lengths == NULL) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1713 conf->upstream.store_lengths = prev->upstream.store_lengths; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1714 conf->upstream.store_values = prev->upstream.store_values; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1715 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1716 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1717 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1718 ngx_conf_merge_uint_value(conf->upstream.store_access, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1719 prev->upstream.store_access, 0600); |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1244
diff
changeset
|
1720 |
581 | 1721 ngx_conf_merge_value(conf->upstream.buffering, |
1722 prev->upstream.buffering, 1); | |
1723 | |
629 | 1724 ngx_conf_merge_value(conf->upstream.ignore_client_abort, |
1725 prev->upstream.ignore_client_abort, 0); | |
1726 | |
507 | 1727 ngx_conf_merge_msec_value(conf->upstream.connect_timeout, |
1728 prev->upstream.connect_timeout, 60000); | |
1729 | |
1730 ngx_conf_merge_msec_value(conf->upstream.send_timeout, | |
1731 prev->upstream.send_timeout, 60000); | |
1732 | |
1733 ngx_conf_merge_msec_value(conf->upstream.read_timeout, | |
1734 prev->upstream.read_timeout, 60000); | |
1735 | |
1736 ngx_conf_merge_size_value(conf->upstream.send_lowat, | |
1737 prev->upstream.send_lowat, 0); | |
1738 | |
581 | 1739 ngx_conf_merge_size_value(conf->upstream.buffer_size, |
1740 prev->upstream.buffer_size, | |
507 | 1741 (size_t) ngx_pagesize); |
1742 | |
1743 ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs, | |
1744 8, ngx_pagesize); | |
1745 | |
1746 if (conf->upstream.bufs.num < 2) { | |
577 | 1747 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
507 | 1748 "there must be at least 2 \"proxy_buffers\""); |
1749 return NGX_CONF_ERROR; | |
1750 } | |
577 | 1751 |
507 | 1752 |
581 | 1753 size = conf->upstream.buffer_size; |
577 | 1754 if (size < conf->upstream.bufs.size) { |
507 | 1755 size = conf->upstream.bufs.size; |
1756 } | |
1757 | |
1758 | |
529 | 1759 ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf, |
1760 prev->upstream.busy_buffers_size_conf, | |
507 | 1761 NGX_CONF_UNSET_SIZE); |
1762 | |
529 | 1763 if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) { |
507 | 1764 conf->upstream.busy_buffers_size = 2 * size; |
529 | 1765 } else { |
1766 conf->upstream.busy_buffers_size = | |
1767 conf->upstream.busy_buffers_size_conf; | |
1768 } | |
577 | 1769 |
529 | 1770 if (conf->upstream.busy_buffers_size < size) { |
507 | 1771 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1772 "\"proxy_busy_buffers_size\" must be equal or bigger than " | |
1125
2d978e1443ed
use the contemporary directives
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
1773 "maximum of the value of \"proxy_buffer_size\" and " |
507 | 1774 "one of the \"proxy_buffers\""); |
1775 | |
1776 return NGX_CONF_ERROR; | |
529 | 1777 } |
507 | 1778 |
529 | 1779 if (conf->upstream.busy_buffers_size |
1780 > (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size) | |
507 | 1781 { |
1782 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1783 "\"proxy_busy_buffers_size\" must be less than " | |
1784 "the size of all \"proxy_buffers\" minus one buffer"); | |
1785 | |
1786 return NGX_CONF_ERROR; | |
1787 } | |
529 | 1788 |
507 | 1789 |
529 | 1790 ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf, |
1791 prev->upstream.temp_file_write_size_conf, | |
507 | 1792 NGX_CONF_UNSET_SIZE); |
1793 | |
529 | 1794 if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) { |
507 | 1795 conf->upstream.temp_file_write_size = 2 * size; |
529 | 1796 } else { |
1797 conf->upstream.temp_file_write_size = | |
1798 conf->upstream.temp_file_write_size_conf; | |
1799 } | |
577 | 1800 |
529 | 1801 if (conf->upstream.temp_file_write_size < size) { |
507 | 1802 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1803 "\"proxy_temp_file_write_size\" must be equal or bigger than " | |
1125
2d978e1443ed
use the contemporary directives
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
1804 "maximum of the value of \"proxy_buffer_size\" and " |
507 | 1805 "one of the \"proxy_buffers\""); |
1806 | |
1807 return NGX_CONF_ERROR; | |
1808 } | |
1809 | |
529 | 1810 ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf, |
1811 prev->upstream.max_temp_file_size_conf, | |
507 | 1812 NGX_CONF_UNSET_SIZE); |
1813 | |
529 | 1814 if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) { |
507 | 1815 conf->upstream.max_temp_file_size = 1024 * 1024 * 1024; |
529 | 1816 } else { |
1817 conf->upstream.max_temp_file_size = | |
1818 conf->upstream.max_temp_file_size_conf; | |
1819 } | |
507 | 1820 |
529 | 1821 if (conf->upstream.max_temp_file_size != 0 |
1822 && conf->upstream.max_temp_file_size < size) | |
507 | 1823 { |
1824 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
561 | 1825 "\"proxy_max_temp_file_size\" must be equal to zero to disable " |
507 | 1826 "the temporary files usage or must be equal or bigger than " |
1125
2d978e1443ed
use the contemporary directives
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
1827 "maximum of the value of \"proxy_buffer_size\" and " |
561 | 1828 "one of the \"proxy_buffers\""); |
507 | 1829 |
1830 return NGX_CONF_ERROR; | |
1831 } | |
1832 | |
529 | 1833 |
507 | 1834 ngx_conf_merge_bitmask_value(conf->upstream.next_upstream, |
1835 prev->upstream.next_upstream, | |
1836 (NGX_CONF_BITMASK_SET | |
1837 |NGX_HTTP_UPSTREAM_FT_ERROR | |
1838 |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); | |
1839 | |
665 | 1840 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) { |
1841 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET | |
1842 |NGX_HTTP_UPSTREAM_FT_OFF; | |
1843 } | |
1844 | |
509 | 1845 ngx_conf_merge_path_value(conf->upstream.temp_path, |
1846 prev->upstream.temp_path, | |
1847 NGX_HTTP_PROXY_TEMP_PATH, 1, 2, 0, | |
1848 ngx_garbage_collector_temp_handler, cf); | |
507 | 1849 |
561 | 1850 if (conf->method.len == 0) { |
1851 conf->method = prev->method; | |
1852 | |
1853 } else { | |
1854 conf->method.data[conf->method.len] = ' '; | |
1855 conf->method.len++; | |
509 | 1856 } |
1857 | |
1858 ngx_conf_merge_value(conf->upstream.pass_request_headers, | |
1859 prev->upstream.pass_request_headers, 1); | |
1860 ngx_conf_merge_value(conf->upstream.pass_request_body, | |
1861 prev->upstream.pass_request_body, 1); | |
1862 | |
657 | 1863 ngx_conf_merge_value(conf->upstream.intercept_errors, |
1864 prev->upstream.intercept_errors, 0); | |
509 | 1865 |
2184 | 1866 #if (NGX_HTTP_SSL) |
1867 ngx_conf_merge_value(conf->upstream.ssl_session_reuse, | |
1868 prev->upstream.ssl_session_reuse, 1); | |
1869 #endif | |
1870 | |
509 | 1871 ngx_conf_merge_value(conf->redirect, prev->redirect, 1); |
1872 | |
1873 if (conf->redirect) { | |
507 | 1874 |
509 | 1875 if (conf->redirects == NULL) { |
1876 conf->redirects = prev->redirects; | |
1877 } | |
1878 | |
1658 | 1879 if (conf->redirects == NULL && conf->url.data) { |
509 | 1880 |
1881 conf->redirects = ngx_array_create(cf->pool, 1, | |
1882 sizeof(ngx_http_proxy_redirect_t)); | |
1883 if (conf->redirects == NULL) { | |
1884 return NGX_CONF_ERROR; | |
1885 } | |
1886 | |
1887 pr = ngx_array_push(conf->redirects); | |
1888 if (pr == NULL) { | |
1889 return NGX_CONF_ERROR; | |
1890 } | |
1891 | |
1892 pr->handler = ngx_http_proxy_rewrite_redirect_text; | |
1658 | 1893 pr->redirect = conf->url; |
1894 | |
1895 if (conf->vars.uri.len) { | |
1896 pr->replacement.text = conf->location; | |
653 | 1897 |
1898 } else { | |
1899 pr->replacement.text.len = 0; | |
1900 pr->replacement.text.data = NULL; | |
1901 } | |
509 | 1902 } |
1903 } | |
1904 | |
1658 | 1905 /* STUB */ |
1906 if (prev->proxy_lengths) { | |
1907 conf->proxy_lengths = prev->proxy_lengths; | |
1908 conf->proxy_values = prev->proxy_values; | |
1909 } | |
1910 | |
1180
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1911 ngx_conf_merge_uint_value(conf->headers_hash_max_size, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1912 prev->headers_hash_max_size, 512); |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1913 |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1914 ngx_conf_merge_uint_value(conf->headers_hash_bucket_size, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1915 prev->headers_hash_bucket_size, 64); |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1916 |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1917 conf->headers_hash_bucket_size = ngx_align(conf->headers_hash_bucket_size, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1918 ngx_cacheline_size); |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1919 |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
1920 hash.max_size = conf->headers_hash_max_size; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
1921 hash.bucket_size = conf->headers_hash_bucket_size; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
1922 hash.name = "proxy_headers_hash"; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
1923 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
1924 if (ngx_http_upstream_hide_headers_hash(cf, &conf->upstream, |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
1925 &prev->upstream, |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
1926 ngx_http_proxy_hide_headers, &hash) |
649 | 1927 != NGX_OK) |
1928 { | |
1929 return NGX_CONF_ERROR; | |
1930 } | |
1931 | |
884 | 1932 if (conf->upstream.upstream == NULL) { |
1933 conf->upstream.upstream = prev->upstream.upstream; | |
1658 | 1934 conf->vars = prev->vars; |
507 | 1935 } |
1936 | |
577 | 1937 |
1938 if (conf->body_source.data == NULL) { | |
1939 conf->body_source = prev->body_source; | |
1940 conf->body_set_len = prev->body_set_len; | |
1941 conf->body_set = prev->body_set; | |
1942 } | |
1943 | |
579 | 1944 if (conf->body_source.data && conf->body_set_len == NULL) { |
577 | 1945 |
1946 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
1947 | |
1948 sc.cf = cf; | |
1949 sc.source = &conf->body_source; | |
1950 sc.flushes = &conf->flushes; | |
1951 sc.lengths = &conf->body_set_len; | |
1952 sc.values = &conf->body_set; | |
1953 sc.complete_lengths = 1; | |
1954 sc.complete_values = 1; | |
1955 | |
1956 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
1957 return NGX_CONF_ERROR; | |
1958 } | |
1959 | |
1960 if (conf->headers_source == NULL) { | |
1961 conf->headers_source = ngx_array_create(cf->pool, 4, | |
649 | 1962 sizeof(ngx_keyval_t)); |
577 | 1963 if (conf->headers_source == NULL) { |
1964 return NGX_CONF_ERROR; | |
1965 } | |
1966 } | |
1967 | |
1968 s = ngx_array_push(conf->headers_source); | |
1969 if (s == NULL) { | |
1970 return NGX_CONF_ERROR; | |
1971 } | |
1972 | |
1973 s->key.len = sizeof("Content-Length") - 1; | |
1974 s->key.data = (u_char *) "Content-Length"; | |
1975 s->value.len = sizeof("$proxy_internal_body_length") - 1; | |
1976 s->value.data = (u_char *) "$proxy_internal_body_length"; | |
1977 } | |
1978 | |
1979 | |
509 | 1980 if (conf->headers_source == NULL) { |
573 | 1981 conf->flushes = prev->flushes; |
507 | 1982 conf->headers_set_len = prev->headers_set_len; |
1983 conf->headers_set = prev->headers_set; | |
1984 conf->headers_set_hash = prev->headers_set_hash; | |
573 | 1985 conf->headers_source = prev->headers_source; |
507 | 1986 } |
1987 | |
649 | 1988 if (conf->headers_set_hash.buckets) { |
509 | 1989 return NGX_CONF_OK; |
1990 } | |
1991 | |
1992 | |
649 | 1993 conf->headers_names = ngx_array_create(cf->pool, 4, sizeof(ngx_hash_key_t)); |
509 | 1994 if (conf->headers_names == NULL) { |
1995 return NGX_CONF_ERROR; | |
1996 } | |
1997 | |
1998 if (conf->headers_source == NULL) { | |
1999 conf->headers_source = ngx_array_create(cf->pool, 4, | |
649 | 2000 sizeof(ngx_keyval_t)); |
509 | 2001 if (conf->headers_source == NULL) { |
2002 return NGX_CONF_ERROR; | |
2003 } | |
2004 } | |
507 | 2005 |
509 | 2006 conf->headers_set_len = ngx_array_create(cf->pool, 64, 1); |
2007 if (conf->headers_set_len == NULL) { | |
2008 return NGX_CONF_ERROR; | |
2009 } | |
2010 | |
2011 conf->headers_set = ngx_array_create(cf->pool, 512, 1); | |
2012 if (conf->headers_set == NULL) { | |
2013 return NGX_CONF_ERROR; | |
2014 } | |
2015 | |
2016 | |
2017 src = conf->headers_source->elts; | |
2018 | |
2019 for (h = ngx_http_proxy_headers; h->key.len; h++) { | |
2020 | |
2021 for (i = 0; i < conf->headers_source->nelts; i++) { | |
2022 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) { | |
2023 goto next; | |
507 | 2024 } |
2025 } | |
2026 | |
509 | 2027 s = ngx_array_push(conf->headers_source); |
2028 if (s == NULL) { | |
507 | 2029 return NGX_CONF_ERROR; |
2030 } | |
2031 | |
509 | 2032 *s = *h; |
507 | 2033 |
517 | 2034 src = conf->headers_source->elts; |
2035 | |
509 | 2036 next: |
507 | 2037 |
509 | 2038 continue; |
2039 } | |
507 | 2040 |
577 | 2041 |
2042 src = conf->headers_source->elts; | |
509 | 2043 for (i = 0; i < conf->headers_source->nelts; i++) { |
507 | 2044 |
649 | 2045 hk = ngx_array_push(conf->headers_names); |
2046 if (hk == NULL) { | |
507 | 2047 return NGX_CONF_ERROR; |
2048 } | |
2049 | |
649 | 2050 hk->key = src[i].key; |
2051 hk->key_hash = ngx_hash_key_lc(src[i].key.data, src[i].key.len); | |
2052 hk->value = (void *) 1; | |
509 | 2053 |
519 | 2054 if (src[i].value.len == 0) { |
2055 continue; | |
2056 } | |
2057 | |
509 | 2058 if (ngx_http_script_variables_count(&src[i].value) == 0) { |
2059 copy = ngx_array_push_n(conf->headers_set_len, | |
2060 sizeof(ngx_http_script_copy_code_t)); | |
2061 if (copy == NULL) { | |
2062 return NGX_CONF_ERROR; | |
2063 } | |
2064 | |
2065 copy->code = (ngx_http_script_code_pt) | |
2066 ngx_http_script_copy_len_code; | |
2067 copy->len = src[i].key.len + sizeof(": ") - 1 | |
2068 + src[i].value.len + sizeof(CRLF) - 1; | |
507 | 2069 |
2070 | |
509 | 2071 size = (sizeof(ngx_http_script_copy_code_t) |
2072 + src[i].key.len + sizeof(": ") - 1 | |
2073 + src[i].value.len + sizeof(CRLF) - 1 | |
2074 + sizeof(uintptr_t) - 1) | |
2075 & ~(sizeof(uintptr_t) - 1); | |
2076 | |
2077 copy = ngx_array_push_n(conf->headers_set, size); | |
2078 if (copy == NULL) { | |
2079 return NGX_CONF_ERROR; | |
2080 } | |
2081 | |
2082 copy->code = ngx_http_script_copy_code; | |
2083 copy->len = src[i].key.len + sizeof(": ") - 1 | |
2084 + src[i].value.len + sizeof(CRLF) - 1; | |
2085 | |
2086 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t); | |
2087 | |
2088 p = ngx_cpymem(p, src[i].key.data, src[i].key.len); | |
2089 *p++ = ':'; *p++ = ' '; | |
2090 p = ngx_cpymem(p, src[i].value.data, src[i].value.len); | |
2091 *p++ = CR; *p = LF; | |
2092 | |
2093 } else { | |
2094 copy = ngx_array_push_n(conf->headers_set_len, | |
2095 sizeof(ngx_http_script_copy_code_t)); | |
2096 if (copy == NULL) { | |
2097 return NGX_CONF_ERROR; | |
2098 } | |
2099 | |
2100 copy->code = (ngx_http_script_code_pt) | |
2101 ngx_http_script_copy_len_code; | |
2102 copy->len = src[i].key.len + sizeof(": ") - 1; | |
507 | 2103 |
2104 | |
509 | 2105 size = (sizeof(ngx_http_script_copy_code_t) |
2106 + src[i].key.len + sizeof(": ") - 1 + sizeof(uintptr_t) - 1) | |
2107 & ~(sizeof(uintptr_t) - 1); | |
2108 | |
2109 copy = ngx_array_push_n(conf->headers_set, size); | |
2110 if (copy == NULL) { | |
2111 return NGX_CONF_ERROR; | |
2112 } | |
2113 | |
2114 copy->code = ngx_http_script_copy_code; | |
2115 copy->len = src[i].key.len + sizeof(": ") - 1; | |
2116 | |
2117 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t); | |
2118 p = ngx_cpymem(p, src[i].key.data, src[i].key.len); | |
2119 *p++ = ':'; *p = ' '; | |
2120 | |
2121 | |
2122 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
2123 | |
2124 sc.cf = cf; | |
2125 sc.source = &src[i].value; | |
573 | 2126 sc.flushes = &conf->flushes; |
509 | 2127 sc.lengths = &conf->headers_set_len; |
2128 sc.values = &conf->headers_set; | |
2129 | |
2130 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
2131 return NGX_CONF_ERROR; | |
2132 } | |
2133 | |
2134 | |
2135 copy = ngx_array_push_n(conf->headers_set_len, | |
2136 sizeof(ngx_http_script_copy_code_t)); | |
2137 if (copy == NULL) { | |
2138 return NGX_CONF_ERROR; | |
2139 } | |
2140 | |
2141 copy->code = (ngx_http_script_code_pt) | |
2142 ngx_http_script_copy_len_code; | |
2143 copy->len = sizeof(CRLF) - 1; | |
2144 | |
2145 | |
2146 size = (sizeof(ngx_http_script_copy_code_t) | |
2147 + sizeof(CRLF) - 1 + sizeof(uintptr_t) - 1) | |
2148 & ~(sizeof(uintptr_t) - 1); | |
2149 | |
2150 copy = ngx_array_push_n(conf->headers_set, size); | |
2151 if (copy == NULL) { | |
2152 return NGX_CONF_ERROR; | |
2153 } | |
2154 | |
2155 copy->code = ngx_http_script_copy_code; | |
2156 copy->len = sizeof(CRLF) - 1; | |
2157 | |
2158 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t); | |
2159 *p++ = CR; *p = LF; | |
507 | 2160 } |
2161 | |
509 | 2162 code = ngx_array_push_n(conf->headers_set_len, sizeof(uintptr_t)); |
2163 if (code == NULL) { | |
507 | 2164 return NGX_CONF_ERROR; |
2165 } | |
2166 | |
509 | 2167 *code = (uintptr_t) NULL; |
2168 | |
2169 code = ngx_array_push_n(conf->headers_set, sizeof(uintptr_t)); | |
2170 if (code == NULL) { | |
2171 return NGX_CONF_ERROR; | |
2172 } | |
2173 | |
2174 *code = (uintptr_t) NULL; | |
507 | 2175 } |
2176 | |
509 | 2177 code = ngx_array_push_n(conf->headers_set_len, sizeof(uintptr_t)); |
2178 if (code == NULL) { | |
2179 return NGX_CONF_ERROR; | |
507 | 2180 } |
2181 | |
509 | 2182 *code = (uintptr_t) NULL; |
507 | 2183 |
2184 | |
649 | 2185 hash.hash = &conf->headers_set_hash; |
2186 hash.key = ngx_hash_key_lc; | |
1180
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
2187 hash.max_size = conf->headers_hash_max_size; |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
2188 hash.bucket_size = conf->headers_hash_bucket_size; |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
2189 hash.name = "proxy_headers_hash"; |
649 | 2190 hash.pool = cf->pool; |
2191 hash.temp_pool = NULL; | |
2192 | |
2193 if (ngx_hash_init(&hash, conf->headers_names->elts, | |
2194 conf->headers_names->nelts) | |
2195 != NGX_OK) | |
2196 { | |
2197 return NGX_CONF_ERROR; | |
2198 } | |
2199 | |
509 | 2200 return NGX_CONF_OK; |
507 | 2201 } |
2202 | |
2203 | |
2204 static char * | |
2205 ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
2206 { | |
509 | 2207 ngx_http_proxy_loc_conf_t *plcf = conf; |
507 | 2208 |
1658 | 2209 size_t add; |
2210 u_short port; | |
2211 ngx_str_t *value, *url; | |
2212 ngx_url_t u; | |
2213 ngx_uint_t n; | |
2214 ngx_http_core_loc_conf_t *clcf; | |
2215 ngx_http_script_compile_t sc; | |
507 | 2216 |
2391
d88e757cc7d8
delete surplus upstream.schema field
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
2217 if (plcf->upstream.upstream || plcf->proxy_lengths) { |
555 | 2218 return "is duplicate"; |
2219 } | |
2220 | |
1658 | 2221 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); |
2222 | |
507 | 2223 value = cf->args->elts; |
2224 | |
2225 url = &value[1]; | |
2226 | |
1658 | 2227 n = ngx_http_script_variables_count(url); |
2228 | |
2229 if (n) { | |
2230 | |
2231 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
2232 | |
2233 sc.cf = cf; | |
2234 sc.source = url; | |
2235 sc.lengths = &plcf->proxy_lengths; | |
2236 sc.values = &plcf->proxy_values; | |
2237 sc.variables = n; | |
2238 sc.complete_lengths = 1; | |
2239 sc.complete_values = 1; | |
1679
ca317d9b5c09
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1671
diff
changeset
|
2240 |
1658 | 2241 if (ngx_http_script_compile(&sc) != NGX_OK) { |
2242 return NGX_CONF_ERROR; | |
2243 } | |
2244 | |
2245 #if (NGX_HTTP_SSL) | |
2246 if (ngx_http_proxy_set_ssl(cf, plcf) != NGX_OK) { | |
2247 return NGX_CONF_ERROR; | |
2248 } | |
2249 #endif | |
2250 | |
2251 clcf->handler = ngx_http_proxy_handler; | |
2252 | |
2253 return NGX_CONF_OK; | |
2254 } | |
2255 | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
969
diff
changeset
|
2256 if (ngx_strncasecmp(url->data, (u_char *) "http://", 7) == 0) { |
577 | 2257 add = 7; |
591 | 2258 port = 80; |
577 | 2259 |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
969
diff
changeset
|
2260 } else if (ngx_strncasecmp(url->data, (u_char *) "https://", 8) == 0) { |
577 | 2261 |
2262 #if (NGX_HTTP_SSL) | |
1658 | 2263 if (ngx_http_proxy_set_ssl(cf, plcf) != NGX_OK) { |
2264 return NGX_CONF_ERROR; | |
2265 } | |
577 | 2266 |
2267 add = 8; | |
591 | 2268 port = 443; |
577 | 2269 #else |
2270 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2271 "https protocol requires SSL support"); | |
2272 return NGX_CONF_ERROR; | |
2273 #endif | |
2274 | |
2275 } else { | |
507 | 2276 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid URL prefix"); |
2277 return NGX_CONF_ERROR; | |
2278 } | |
2279 | |
651 | 2280 ngx_memzero(&u, sizeof(ngx_url_t)); |
2281 | |
2282 u.url.len = url->len - add; | |
2283 u.url.data = url->data + add; | |
906 | 2284 u.default_port = port; |
2285 u.uri_part = 1; | |
884 | 2286 u.no_resolve = 1; |
2287 | |
2288 plcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0); | |
2289 if (plcf->upstream.upstream == NULL) { | |
507 | 2290 return NGX_CONF_ERROR; |
2291 } | |
2292 | |
1658 | 2293 if (ngx_http_proxy_set_vars(cf->pool, &u, &plcf->vars) != NGX_OK) { |
2294 return NGX_CONF_ERROR; | |
906 | 2295 } |
2296 | |
2391
d88e757cc7d8
delete surplus upstream.schema field
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
2297 plcf->vars.schema.len = add; |
d88e757cc7d8
delete surplus upstream.schema field
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
2298 plcf->vars.schema.data = url->data; |
1658 | 2299 plcf->location = clcf->name; |
507 | 2300 |
2301 clcf->handler = ngx_http_proxy_handler; | |
2302 | |
1353 | 2303 if (clcf->named |
507 | 2304 #if (NGX_PCRE) |
1353 | 2305 || clcf->regex |
2306 #endif | |
2307 || clcf->noname) | |
2308 { | |
1658 | 2309 if (plcf->vars.uri.len) { |
573 | 2310 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2311 "\"proxy_pass\" may not have URI part in " | |
843
ebab9490204c
allow proxy_pass inside limit_except
Igor Sysoev <igor@sysoev.ru>
parents:
812
diff
changeset
|
2312 "location given by regular expression, " |
1353 | 2313 "or inside named location, " |
843
ebab9490204c
allow proxy_pass inside limit_except
Igor Sysoev <igor@sysoev.ru>
parents:
812
diff
changeset
|
2314 "or inside the \"if\" statement, " |
ebab9490204c
allow proxy_pass inside limit_except
Igor Sysoev <igor@sysoev.ru>
parents:
812
diff
changeset
|
2315 "or inside the \"limit_except\" block"); |
573 | 2316 return NGX_CONF_ERROR; |
2317 } | |
2318 | |
1658 | 2319 plcf->location.len = 0; |
555 | 2320 } |
2321 | |
1658 | 2322 plcf->url = *url; |
509 | 2323 |
507 | 2324 if (clcf->name.data[clcf->name.len - 1] == '/') { |
2325 clcf->auto_redirect = 1; | |
2326 } | |
2327 | |
2328 return NGX_CONF_OK; | |
2329 } | |
2330 | |
2331 | |
2332 static char * | |
509 | 2333 ngx_http_proxy_redirect(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
507 | 2334 { |
509 | 2335 ngx_http_proxy_loc_conf_t *plcf = conf; |
2336 | |
2337 ngx_str_t *value; | |
2338 ngx_array_t *vars_lengths, *vars_values; | |
2339 ngx_http_script_compile_t sc; | |
2340 ngx_http_proxy_redirect_t *pr; | |
2341 | |
2342 if (plcf->redirect == 0) { | |
2343 return NGX_CONF_OK; | |
2344 } | |
2345 | |
2346 value = cf->args->elts; | |
2347 | |
2348 if (ngx_strcmp(value[1].data, "off") == 0) { | |
2349 plcf->redirect = 0; | |
2350 plcf->redirects = NULL; | |
2351 return NGX_CONF_OK; | |
2352 } | |
2353 | |
2354 if (plcf->redirects == NULL) { | |
2355 plcf->redirects = ngx_array_create(cf->pool, 1, | |
2356 sizeof(ngx_http_proxy_redirect_t)); | |
2357 if (plcf->redirects == NULL) { | |
2358 return NGX_CONF_ERROR; | |
2359 } | |
2360 } | |
2361 | |
2362 pr = ngx_array_push(plcf->redirects); | |
2363 if (pr == NULL) { | |
2364 return NGX_CONF_ERROR; | |
2365 } | |
2366 | |
2367 if (cf->args->nelts == 2 && ngx_strcmp(value[1].data, "default") == 0) { | |
1658 | 2368 if (plcf->url.data == NULL) { |
509 | 2369 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2370 "\"proxy_rewrite_location default\" must go " | |
2371 "after the \"proxy_pass\" directive"); | |
2372 return NGX_CONF_ERROR; | |
2373 } | |
2374 | |
2375 pr->handler = ngx_http_proxy_rewrite_redirect_text; | |
1658 | 2376 pr->redirect = plcf->url; |
2377 | |
2378 if (plcf->vars.uri.len) { | |
2379 pr->replacement.text = plcf->location; | |
653 | 2380 |
2381 } else { | |
2382 pr->replacement.text.len = 0; | |
2383 pr->replacement.text.data = NULL; | |
2384 } | |
509 | 2385 |
2386 return NGX_CONF_OK; | |
2387 } | |
2388 | |
2389 if (ngx_http_script_variables_count(&value[2]) == 0) { | |
2390 pr->handler = ngx_http_proxy_rewrite_redirect_text; | |
2391 pr->redirect = value[1]; | |
2392 pr->replacement.text = value[2]; | |
2393 | |
2394 return NGX_CONF_OK; | |
2395 } | |
2396 | |
2397 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
2398 | |
2399 vars_lengths = NULL; | |
2400 vars_values = NULL; | |
2401 | |
2402 sc.cf = cf; | |
2403 sc.source = &value[2]; | |
2404 sc.lengths = &vars_lengths; | |
2405 sc.values = &vars_values; | |
2406 sc.complete_lengths = 1; | |
2407 sc.complete_values = 1; | |
2408 | |
2409 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
2410 return NGX_CONF_ERROR; | |
2411 } | |
2412 | |
2413 pr->handler = ngx_http_proxy_rewrite_redirect_vars; | |
2414 pr->redirect = value[1]; | |
2415 pr->replacement.vars.lengths = vars_lengths->elts; | |
2416 pr->replacement.vars.values = vars_values->elts; | |
2417 | |
507 | 2418 return NGX_CONF_OK; |
2419 } | |
2420 | |
2421 | |
2422 static char * | |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2423 ngx_http_proxy_store(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2424 { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2425 ngx_http_proxy_loc_conf_t *plcf = conf; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2426 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2427 ngx_str_t *value; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2428 ngx_http_script_compile_t sc; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2429 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2430 if (plcf->upstream.store != NGX_CONF_UNSET || plcf->upstream.store_lengths) |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2431 { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2432 return "is duplicate"; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2433 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2434 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2435 value = cf->args->elts; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2436 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2437 if (ngx_strcmp(value[1].data, "on") == 0) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2438 plcf->upstream.store = 1; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2439 return NGX_CONF_OK; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2440 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2441 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2442 if (ngx_strcmp(value[1].data, "off") == 0) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2443 plcf->upstream.store = 0; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2444 return NGX_CONF_OK; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2445 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2446 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2447 /* include the terminating '\0' into script */ |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2448 value[1].len++; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2449 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2450 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2451 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2452 sc.cf = cf; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2453 sc.source = &value[1]; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2454 sc.lengths = &plcf->upstream.store_lengths; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2455 sc.values = &plcf->upstream.store_values; |
1563
022ec9420f80
style fix: remove double semicolons
Igor Sysoev <igor@sysoev.ru>
parents:
1488
diff
changeset
|
2456 sc.variables = ngx_http_script_variables_count(&value[1]); |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2457 sc.complete_lengths = 1; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2458 sc.complete_values = 1; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2459 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2460 if (ngx_http_script_compile(&sc) != NGX_OK) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2461 return NGX_CONF_ERROR; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2462 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2463 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2464 return NGX_CONF_OK; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2465 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2466 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2467 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2468 static char * |
507 | 2469 ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data) |
2470 { | |
2471 #if (NGX_FREEBSD) | |
2472 ssize_t *np = data; | |
2473 | |
673 | 2474 if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) { |
507 | 2475 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2476 "\"proxy_send_lowat\" must be less than %d " | |
2477 "(sysctl net.inet.tcp.sendspace)", | |
2478 ngx_freebsd_net_inet_tcp_sendspace); | |
2479 | |
2480 return NGX_CONF_ERROR; | |
2481 } | |
2482 | |
2483 #elif !(NGX_HAVE_SO_SNDLOWAT) | |
2484 ssize_t *np = data; | |
2485 | |
2486 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | |
2487 "\"proxy_send_lowat\" is not supported, ignored"); | |
2488 | |
2489 *np = 0; | |
2490 | |
2491 #endif | |
2492 | |
2493 return NGX_CONF_OK; | |
2494 } | |
884 | 2495 |
2496 | |
2497 static char * | |
2498 ngx_http_proxy_upstream_max_fails_unsupported(ngx_conf_t *cf, | |
2499 ngx_command_t *cmd, void *conf) | |
2500 { | |
2501 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2502 "\"proxy_upstream_max_fails\" is not supported, " | |
2503 "use the \"max_fails\" parameter of the \"server\" directive ", | |
2504 "inside the \"upstream\" block"); | |
2505 | |
2506 return NGX_CONF_ERROR; | |
2507 } | |
2508 | |
2509 | |
2510 static char * | |
2511 ngx_http_proxy_upstream_fail_timeout_unsupported(ngx_conf_t *cf, | |
2512 ngx_command_t *cmd, void *conf) | |
2513 { | |
2514 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2515 "\"proxy_upstream_fail_timeout\" is not supported, " | |
2516 "use the \"fail_timeout\" parameter of the \"server\" directive ", | |
2517 "inside the \"upstream\" block"); | |
2518 | |
2519 return NGX_CONF_ERROR; | |
2520 } | |
1658 | 2521 |
2522 | |
2523 #if (NGX_HTTP_SSL) | |
2524 | |
2525 static ngx_int_t | |
2526 ngx_http_proxy_set_ssl(ngx_conf_t *cf, ngx_http_proxy_loc_conf_t *plcf) | |
2527 { | |
2528 ngx_pool_cleanup_t *cln; | |
2529 | |
2530 plcf->upstream.ssl = ngx_pcalloc(cf->pool, sizeof(ngx_ssl_t)); | |
2531 if (plcf->upstream.ssl == NULL) { | |
2532 return NGX_ERROR; | |
2533 } | |
2534 | |
2535 plcf->upstream.ssl->log = cf->log; | |
2536 | |
2537 if (ngx_ssl_create(plcf->upstream.ssl, | |
2538 NGX_SSL_SSLv2|NGX_SSL_SSLv3|NGX_SSL_TLSv1, NULL) | |
2539 != NGX_OK) | |
2540 { | |
2541 return NGX_ERROR; | |
2542 } | |
2543 | |
2544 cln = ngx_pool_cleanup_add(cf->pool, 0); | |
2545 if (cln == NULL) { | |
2546 return NGX_ERROR; | |
2547 } | |
2548 | |
2549 cln->handler = ngx_ssl_cleanup_ctx; | |
2550 cln->data = plcf->upstream.ssl; | |
2551 | |
2552 return NGX_OK; | |
2553 } | |
2554 | |
2555 #endif | |
2556 | |
2557 | |
2558 static ngx_int_t | |
2559 ngx_http_proxy_set_vars(ngx_pool_t *pool, ngx_url_t *u, | |
2560 ngx_http_proxy_vars_t *v) | |
2561 { | |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2184
diff
changeset
|
2562 if (u->family != AF_UNIX) { |
1658 | 2563 if (u->no_port || u->port == u->default_port) { |
2564 v->host_header = u->host; | |
2565 | |
2566 if (u->default_port == 80) { | |
2567 v->port.len = sizeof("80") - 1; | |
2568 v->port.data = (u_char *) "80"; | |
2569 | |
2570 } else { | |
2571 v->port.len = sizeof("443") - 1; | |
2572 v->port.data = (u_char *) "443"; | |
2573 } | |
2574 | |
2575 } else { | |
1671
8075179cae21
ngx_parse_url() saves port text, this allows to use it in proxy host header
Igor Sysoev <igor@sysoev.ru>
parents:
1667
diff
changeset
|
2576 v->host_header.len = u->host.len + 1 + u->port_text.len; |
8075179cae21
ngx_parse_url() saves port text, this allows to use it in proxy host header
Igor Sysoev <igor@sysoev.ru>
parents:
1667
diff
changeset
|
2577 v->host_header.data = u->host.data; |
8075179cae21
ngx_parse_url() saves port text, this allows to use it in proxy host header
Igor Sysoev <igor@sysoev.ru>
parents:
1667
diff
changeset
|
2578 v->port = u->port_text; |
1658 | 2579 } |
2580 | |
2581 } else { | |
2582 v->host_header.len = sizeof("localhost") - 1; | |
2583 v->host_header.data = (u_char *) "localhost"; | |
2584 v->port.len = 0; | |
2585 v->port.data = (u_char *) ""; | |
2586 } | |
2587 | |
2588 v->uri = u->uri; | |
2589 | |
2590 return NGX_OK; | |
2591 } |