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