Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_proxy_module.c @ 3736:257785918797
$geoip_dma_code and $geoip_area_code
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 03 Aug 2010 14:19:49 +0000 |
parents | e3a6785b5be4 |
children | f4c49c9e4bb5 |
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 | |
645 if (ngx_strncasecmp(proxy.data, (u_char *) "http://", 7) == 0) { | |
646 | |
647 add = 7; | |
648 port = 80; | |
649 | |
650 #if (NGX_HTTP_SSL) | |
651 | |
652 } else if (ngx_strncasecmp(proxy.data, (u_char *) "https://", 8) == 0) { | |
653 | |
654 add = 8; | |
655 port = 443; | |
656 r->upstream->ssl = 1; | |
657 | |
658 #endif | |
659 | |
660 } else { | |
661 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
662 "invalid URL prefix in \"%V\"", &proxy); | |
663 return NGX_ERROR; | |
664 } | |
665 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
666 u = r->upstream; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
667 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
668 u->schema.len = add; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
669 u->schema.data = proxy.data; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
670 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
671 ngx_memzero(&url, sizeof(ngx_url_t)); |
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 url.url.len = proxy.len - add; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
674 url.url.data = proxy.data + add; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
675 url.default_port = port; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
676 url.uri_part = 1; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
677 url.no_resolve = 1; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
678 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
679 if (ngx_parse_url(r->pool, &url) != NGX_OK) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
680 if (url.err) { |
1658 | 681 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
|
682 "%s in upstream \"%V\"", url.err, &url.url); |
1658 | 683 } |
684 | |
685 return NGX_ERROR; | |
686 } | |
687 | |
3323
9421e997c2c4
allow "proxy_pass http://$backend" without URI part
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
688 if (url.uri.len) { |
9421e997c2c4
allow "proxy_pass http://$backend" without URI part
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
689 if (url.uri.data[0] == '?') { |
9421e997c2c4
allow "proxy_pass http://$backend" without URI part
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
690 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
|
691 if (p == NULL) { |
9421e997c2c4
allow "proxy_pass http://$backend" without URI part
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
692 return NGX_ERROR; |
9421e997c2c4
allow "proxy_pass http://$backend" without URI part
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
693 } |
9421e997c2c4
allow "proxy_pass http://$backend" without URI part
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
694 |
9421e997c2c4
allow "proxy_pass http://$backend" without URI part
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
695 *p++ = '/'; |
9421e997c2c4
allow "proxy_pass http://$backend" without URI part
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
696 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
|
697 |
9421e997c2c4
allow "proxy_pass http://$backend" without URI part
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
698 url.uri.len++; |
9421e997c2c4
allow "proxy_pass http://$backend" without URI part
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
699 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
|
700 } |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2268
diff
changeset
|
701 |
3323
9421e997c2c4
allow "proxy_pass http://$backend" without URI part
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
702 } else { |
9421e997c2c4
allow "proxy_pass http://$backend" without URI part
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
703 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
|
704 } |
c3035feb6638
fix case proxy_pass URL is evaluted to http://host?args
Igor Sysoev <igor@sysoev.ru>
parents:
2268
diff
changeset
|
705 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
706 ctx->vars.key_start = u->schema; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
707 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
708 ngx_http_proxy_set_vars(&url, &ctx->vars); |
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 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
|
711 if (u->resolved == NULL) { |
1658 | 712 return NGX_ERROR; |
713 } | |
714 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
715 if (url.addrs && url.addrs[0].sockaddr) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
716 u->resolved->sockaddr = url.addrs[0].sockaddr; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
717 u->resolved->socklen = url.addrs[0].socklen; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
718 u->resolved->naddrs = 1; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
719 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
|
720 |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2391
diff
changeset
|
721 } else { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
722 u->resolved->host = url.host; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
723 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
|
724 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
|
725 } |
1658 | 726 |
727 return NGX_OK; | |
728 } | |
729 | |
730 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
731 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
732 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
733 static ngx_int_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
734 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
|
735 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
736 size_t len, loc_len; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
737 u_char *p; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
738 uintptr_t escape; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
739 ngx_str_t *key; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
740 ngx_http_upstream_t *u; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
741 ngx_http_proxy_ctx_t *ctx; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
742 ngx_http_proxy_loc_conf_t *plcf; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
743 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
744 u = r->upstream; |
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 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
|
747 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
748 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
|
749 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
750 key = ngx_array_push(&r->cache->keys); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
751 if (key == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
752 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
753 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
754 |
2672 | 755 if (plcf->cache_key.value.len) { |
756 | |
757 if (ngx_http_complex_value(r, &plcf->cache_key, key) != NGX_OK) { | |
758 return NGX_ERROR; | |
759 } | |
760 | |
761 return NGX_OK; | |
762 } | |
763 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
764 *key = ctx->vars.key_start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
765 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
766 key = ngx_array_push(&r->cache->keys); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
767 if (key == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
768 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
769 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
770 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
771 if (plcf->proxy_lengths) { |
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 *key = ctx->vars.uri; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
774 u->uri = ctx->vars.uri; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
775 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
776 return NGX_OK; |
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 } 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
|
779 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
780 *key = r->unparsed_uri; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
781 u->uri = r->unparsed_uri; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
782 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
783 return NGX_OK; |
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 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
786 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
|
787 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
788 if (r->quoted_uri || r->internal) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
789 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
|
790 r->uri.len - loc_len, NGX_ESCAPE_URI); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
791 } else { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
792 escape = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
793 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
794 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
795 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
|
796 + sizeof("?") - 1 + r->args.len; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
797 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
798 p = ngx_pnalloc(r->pool, len); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
799 if (p == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
800 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
801 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
802 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
803 key->data = p; |
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 if (r->valid_location) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
806 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
|
807 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
808 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
809 if (escape) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
810 ngx_escape_uri(p, r->uri.data + loc_len, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
811 r->uri.len - loc_len, NGX_ESCAPE_URI); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
812 p += r->uri.len - loc_len + escape; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
813 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
814 } else { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
815 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
|
816 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
817 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
818 if (r->args.len > 0) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
819 *p++ = '?'; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
820 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
|
821 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
822 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
823 key->len = p - key->data; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
824 u->uri = *key; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
825 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
826 return NGX_OK; |
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 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
829 #endif |
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 |
1658 | 832 static ngx_int_t |
507 | 833 ngx_http_proxy_create_request(ngx_http_request_t *r) |
834 { | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
835 size_t len, uri_len, loc_len, body_len; |
509 | 836 uintptr_t escape; |
837 ngx_buf_t *b; | |
649 | 838 ngx_str_t method; |
839 ngx_uint_t i, unparsed_uri; | |
509 | 840 ngx_chain_t *cl, *body; |
841 ngx_list_part_t *part; | |
842 ngx_table_elt_t *header; | |
843 ngx_http_upstream_t *u; | |
1658 | 844 ngx_http_proxy_ctx_t *ctx; |
509 | 845 ngx_http_script_code_pt code; |
846 ngx_http_script_engine_t e, le; | |
847 ngx_http_proxy_loc_conf_t *plcf; | |
848 ngx_http_script_len_code_pt lcode; | |
507 | 849 |
850 u = r->upstream; | |
851 | |
852 plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module); | |
853 | |
561 | 854 if (u->method.len) { |
855 /* HEAD was changed to GET to cache response */ | |
856 method = u->method; | |
857 method.len++; | |
858 | |
859 } else if (plcf->method.len) { | |
860 method = plcf->method; | |
861 | |
507 | 862 } else { |
561 | 863 method = r->method_name; |
864 method.len++; | |
507 | 865 } |
866 | |
1667 | 867 len = method.len + sizeof(ngx_http_proxy_version) - 1 + sizeof(CRLF) - 1; |
868 | |
507 | 869 escape = 0; |
1658 | 870 loc_len = 0; |
871 unparsed_uri = 0; | |
872 | |
873 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
874 | |
875 if (plcf->proxy_lengths) { | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
876 uri_len = ctx->vars.uri.len; |
1658 | 877 |
878 } else if (ctx->vars.uri.len == 0 && r->valid_unparsed_uri && r == r->main) | |
879 { | |
609 | 880 unparsed_uri = 1; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
881 uri_len = r->unparsed_uri.len; |
507 | 882 |
883 } else { | |
1658 | 884 loc_len = (r->valid_location && ctx->vars.uri.len) ? |
885 plcf->location.len : 0; | |
886 | |
3615 | 887 if (r->quoted_uri || r->space_in_uri || r->internal) { |
509 | 888 escape = 2 * ngx_escape_uri(NULL, r->uri.data + loc_len, |
889 r->uri.len - loc_len, NGX_ESCAPE_URI); | |
507 | 890 } |
891 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
892 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
|
893 + sizeof("?") - 1 + r->args.len; |
507 | 894 } |
895 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
896 if (uri_len == 0) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
897 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
|
898 "zero length URI to proxy"); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
899 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
900 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
901 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
902 len += uri_len; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
903 |
1565 | 904 ngx_http_script_flush_no_cacheable_variables(r, plcf->flushes); |
573 | 905 |
577 | 906 if (plcf->body_set_len) { |
907 le.ip = plcf->body_set_len->elts; | |
908 le.request = r; | |
909 le.flushed = 1; | |
910 body_len = 0; | |
911 | |
912 while (*(uintptr_t *) le.ip) { | |
913 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
914 body_len += lcode(&le); | |
915 } | |
916 | |
1658 | 917 ctx->internal_body_length = body_len; |
577 | 918 len += body_len; |
919 } | |
920 | |
509 | 921 le.ip = plcf->headers_set_len->elts; |
922 le.request = r; | |
573 | 923 le.flushed = 1; |
507 | 924 |
509 | 925 while (*(uintptr_t *) le.ip) { |
926 while (*(uintptr_t *) le.ip) { | |
927 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
928 len += lcode(&le); | |
929 } | |
930 le.ip += sizeof(uintptr_t); | |
507 | 931 } |
932 | |
933 | |
509 | 934 if (plcf->upstream.pass_request_headers) { |
935 part = &r->headers_in.headers.part; | |
936 header = part->elts; | |
937 | |
938 for (i = 0; /* void */; i++) { | |
507 | 939 |
509 | 940 if (i >= part->nelts) { |
941 if (part->next == NULL) { | |
942 break; | |
943 } | |
944 | |
945 part = part->next; | |
946 header = part->elts; | |
577 | 947 i = 0; |
507 | 948 } |
949 | |
649 | 950 if (ngx_hash_find(&plcf->headers_set_hash, header[i].hash, |
951 header[i].lowcase_key, header[i].key.len)) | |
509 | 952 { |
953 continue; | |
954 } | |
955 | |
956 len += header[i].key.len + sizeof(": ") - 1 | |
957 + header[i].value.len + sizeof(CRLF) - 1; | |
507 | 958 } |
509 | 959 } |
507 | 960 |
961 | |
962 b = ngx_create_temp_buf(r->pool, len); | |
963 if (b == NULL) { | |
964 return NGX_ERROR; | |
965 } | |
966 | |
967 cl = ngx_alloc_chain_link(r->pool); | |
968 if (cl == NULL) { | |
969 return NGX_ERROR; | |
970 } | |
971 | |
972 cl->buf = b; | |
973 | |
974 | |
975 /* the request line */ | |
976 | |
573 | 977 b->last = ngx_copy(b->last, method.data, method.len); |
507 | 978 |
555 | 979 u->uri.data = b->last; |
980 | |
1658 | 981 if (plcf->proxy_lengths) { |
982 b->last = ngx_copy(b->last, ctx->vars.uri.data, ctx->vars.uri.len); | |
983 | |
984 } else if (unparsed_uri) { | |
573 | 985 b->last = ngx_copy(b->last, r->unparsed_uri.data, r->unparsed_uri.len); |
986 | |
507 | 987 } else { |
555 | 988 if (r->valid_location) { |
1658 | 989 b->last = ngx_copy(b->last, ctx->vars.uri.data, ctx->vars.uri.len); |
555 | 990 } |
551 | 991 |
507 | 992 if (escape) { |
509 | 993 ngx_escape_uri(b->last, r->uri.data + loc_len, |
994 r->uri.len - loc_len, NGX_ESCAPE_URI); | |
995 b->last += r->uri.len - loc_len + escape; | |
507 | 996 |
577 | 997 } else { |
573 | 998 b->last = ngx_copy(b->last, r->uri.data + loc_len, |
999 r->uri.len - loc_len); | |
507 | 1000 } |
1001 | |
1002 if (r->args.len > 0) { | |
1003 *b->last++ = '?'; | |
573 | 1004 b->last = ngx_copy(b->last, r->args.data, r->args.len); |
507 | 1005 } |
1006 } | |
1007 | |
555 | 1008 u->uri.len = b->last - u->uri.data; |
1009 | |
507 | 1010 b->last = ngx_cpymem(b->last, ngx_http_proxy_version, |
1011 sizeof(ngx_http_proxy_version) - 1); | |
1012 | |
577 | 1013 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); |
507 | 1014 |
1015 e.ip = plcf->headers_set->elts; | |
1016 e.pos = b->last; | |
509 | 1017 e.request = r; |
573 | 1018 e.flushed = 1; |
507 | 1019 |
509 | 1020 le.ip = plcf->headers_set_len->elts; |
1021 | |
1022 while (*(uintptr_t *) le.ip) { | |
1023 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
515 | 1024 |
1025 /* skip the header line name length */ | |
1026 (void) lcode(&le); | |
509 | 1027 |
1028 if (*(ngx_http_script_len_code_pt *) le.ip) { | |
1029 | |
1030 for (len = 0; *(uintptr_t *) le.ip; len += lcode(&le)) { | |
1031 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
1032 } | |
1033 | |
1034 e.skip = (len == sizeof(CRLF) - 1) ? 1 : 0; | |
1035 | |
1036 } else { | |
1037 e.skip = 0; | |
1038 } | |
1039 | |
1040 le.ip += sizeof(uintptr_t); | |
1041 | |
1042 while (*(uintptr_t *) e.ip) { | |
1043 code = *(ngx_http_script_code_pt *) e.ip; | |
1044 code((ngx_http_script_engine_t *) &e); | |
577 | 1045 } |
509 | 1046 e.ip += sizeof(uintptr_t); |
507 | 1047 } |
1048 | |
1049 b->last = e.pos; | |
1050 | |
1051 | |
509 | 1052 if (plcf->upstream.pass_request_headers) { |
1053 part = &r->headers_in.headers.part; | |
1054 header = part->elts; | |
577 | 1055 |
509 | 1056 for (i = 0; /* void */; i++) { |
507 | 1057 |
509 | 1058 if (i >= part->nelts) { |
1059 if (part->next == NULL) { | |
1060 break; | |
1061 } | |
1062 | |
1063 part = part->next; | |
1064 header = part->elts; | |
577 | 1065 i = 0; |
507 | 1066 } |
1067 | |
649 | 1068 if (ngx_hash_find(&plcf->headers_set_hash, header[i].hash, |
1069 header[i].lowcase_key, header[i].key.len)) | |
509 | 1070 { |
1071 continue; | |
1072 } | |
507 | 1073 |
573 | 1074 b->last = ngx_copy(b->last, header[i].key.data, header[i].key.len); |
507 | 1075 |
509 | 1076 *b->last++ = ':'; *b->last++ = ' '; |
507 | 1077 |
573 | 1078 b->last = ngx_copy(b->last, header[i].value.data, |
1079 header[i].value.len); | |
507 | 1080 |
509 | 1081 *b->last++ = CR; *b->last++ = LF; |
507 | 1082 |
509 | 1083 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1084 "http proxy header: \"%V: %V\"", | |
1085 &header[i].key, &header[i].value); | |
1086 } | |
507 | 1087 } |
1088 | |
577 | 1089 |
507 | 1090 /* add "\r\n" at the header end */ |
1091 *b->last++ = CR; *b->last++ = LF; | |
1092 | |
577 | 1093 if (plcf->body_set) { |
1094 e.ip = plcf->body_set->elts; | |
1095 e.pos = b->last; | |
1096 | |
1097 while (*(uintptr_t *) e.ip) { | |
1098 code = *(ngx_http_script_code_pt *) e.ip; | |
1099 code((ngx_http_script_engine_t *) &e); | |
1100 } | |
579 | 1101 |
1102 b->last = e.pos; | |
577 | 1103 } |
1104 | |
1774 | 1105 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1106 "http proxy header:\n\"%*s\"", | |
1107 (size_t) (b->last - b->pos), b->pos); | |
507 | 1108 |
577 | 1109 if (plcf->body_set == NULL && plcf->upstream.pass_request_body) { |
509 | 1110 |
1111 body = u->request_bufs; | |
1112 u->request_bufs = cl; | |
1113 | |
1114 while (body) { | |
1115 b = ngx_alloc_buf(r->pool); | |
1116 if (b == NULL) { | |
1117 return NGX_ERROR; | |
1118 } | |
1119 | |
1120 ngx_memcpy(b, body->buf, sizeof(ngx_buf_t)); | |
1121 | |
1122 cl->next = ngx_alloc_chain_link(r->pool); | |
1123 if (cl->next == NULL) { | |
1124 return NGX_ERROR; | |
1125 } | |
1126 | |
1127 cl = cl->next; | |
1128 cl->buf = b; | |
1129 | |
1130 body = body->next; | |
1131 } | |
1132 | |
611 | 1133 b->flush = 1; |
1134 | |
509 | 1135 } else { |
1136 u->request_bufs = cl; | |
1137 } | |
1138 | |
1139 cl->next = NULL; | |
1140 | |
507 | 1141 return NGX_OK; |
1142 } | |
1143 | |
1144 | |
1145 static ngx_int_t | |
1146 ngx_http_proxy_reinit_request(ngx_http_request_t *r) | |
1147 { | |
1658 | 1148 ngx_http_proxy_ctx_t *ctx; |
1149 | |
1150 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
1151 | |
1152 if (ctx == NULL) { | |
509 | 1153 return NGX_OK; |
1154 } | |
1155 | |
3627
9061fdb2ed8c
use ngx_http_parse_status_line()
Igor Sysoev <igor@sysoev.ru>
parents:
3615
diff
changeset
|
1156 ctx->status.code = 0; |
9061fdb2ed8c
use ngx_http_parse_status_line()
Igor Sysoev <igor@sysoev.ru>
parents:
3615
diff
changeset
|
1157 ctx->status.count = 0; |
9061fdb2ed8c
use ngx_http_parse_status_line()
Igor Sysoev <igor@sysoev.ru>
parents:
3615
diff
changeset
|
1158 ctx->status.start = NULL; |
9061fdb2ed8c
use ngx_http_parse_status_line()
Igor Sysoev <igor@sysoev.ru>
parents:
3615
diff
changeset
|
1159 ctx->status.end = NULL; |
509 | 1160 |
1161 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
|
1162 r->state = 0; |
509 | 1163 |
1164 return NGX_OK; | |
1165 } | |
1166 | |
1167 | |
1168 static ngx_int_t | |
1169 ngx_http_proxy_process_status_line(ngx_http_request_t *r) | |
1170 { | |
3628 | 1171 size_t len; |
509 | 1172 ngx_int_t rc; |
1173 ngx_http_upstream_t *u; | |
1658 | 1174 ngx_http_proxy_ctx_t *ctx; |
1175 | |
1176 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
1177 | |
1178 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
|
1179 return NGX_ERROR; |
509 | 1180 } |
1181 | |
3627
9061fdb2ed8c
use ngx_http_parse_status_line()
Igor Sysoev <igor@sysoev.ru>
parents:
3615
diff
changeset
|
1182 u = r->upstream; |
9061fdb2ed8c
use ngx_http_parse_status_line()
Igor Sysoev <igor@sysoev.ru>
parents:
3615
diff
changeset
|
1183 |
9061fdb2ed8c
use ngx_http_parse_status_line()
Igor Sysoev <igor@sysoev.ru>
parents:
3615
diff
changeset
|
1184 rc = ngx_http_parse_status_line(r, &u->buffer, &ctx->status); |
509 | 1185 |
1186 if (rc == NGX_AGAIN) { | |
1187 return rc; | |
1188 } | |
1189 | |
3627
9061fdb2ed8c
use ngx_http_parse_status_line()
Igor Sysoev <igor@sysoev.ru>
parents:
3615
diff
changeset
|
1190 if (rc == NGX_ERROR) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1191 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1192 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1193 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1194 if (r->cache) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1195 r->http_version = NGX_HTTP_VERSION_9; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1196 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1197 } |
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 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1200 |
509 | 1201 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
577 | 1202 "upstream sent no valid HTTP/1.0 header"); |
509 | 1203 |
619 | 1204 #if 0 |
509 | 1205 if (u->accel) { |
1206 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | |
1207 } | |
619 | 1208 #endif |
509 | 1209 |
1210 r->http_version = NGX_HTTP_VERSION_9; | |
1616 | 1211 u->state->status = NGX_HTTP_OK; |
577 | 1212 |
509 | 1213 return NGX_OK; |
1214 } | |
1215 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1216 if (u->state) { |
3627
9061fdb2ed8c
use ngx_http_parse_status_line()
Igor Sysoev <igor@sysoev.ru>
parents:
3615
diff
changeset
|
1217 u->state->status = ctx->status.code; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1218 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1219 |
3627
9061fdb2ed8c
use ngx_http_parse_status_line()
Igor Sysoev <igor@sysoev.ru>
parents:
3615
diff
changeset
|
1220 u->headers_in.status_n = ctx->status.code; |
9061fdb2ed8c
use ngx_http_parse_status_line()
Igor Sysoev <igor@sysoev.ru>
parents:
3615
diff
changeset
|
1221 |
3628 | 1222 len = ctx->status.end - ctx->status.start; |
1223 u->headers_in.status_line.len = len; | |
1224 | |
1225 u->headers_in.status_line.data = ngx_pnalloc(r->pool, len); | |
529 | 1226 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
|
1227 return NGX_ERROR; |
509 | 1228 } |
573 | 1229 |
3628 | 1230 ngx_memcpy(u->headers_in.status_line.data, ctx->status.start, len); |
509 | 1231 |
1232 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1233 "http proxy status %ui \"%V\"", | |
936 | 1234 u->headers_in.status_n, &u->headers_in.status_line); |
509 | 1235 |
1236 u->process_header = ngx_http_proxy_process_header; | |
1237 | |
1238 return ngx_http_proxy_process_header(r); | |
1239 } | |
1240 | |
1241 | |
1242 static ngx_int_t | |
507 | 1243 ngx_http_proxy_process_header(ngx_http_request_t *r) |
1244 { | |
509 | 1245 ngx_int_t rc; |
1246 ngx_table_elt_t *h; | |
1247 ngx_http_upstream_header_t *hh; | |
1248 ngx_http_upstream_main_conf_t *umcf; | |
1249 | |
1250 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); | |
1251 | |
2024 | 1252 for ( ;; ) { |
509 | 1253 |
2256 | 1254 rc = ngx_http_parse_header_line(r, &r->upstream->buffer, 1); |
509 | 1255 |
1256 if (rc == NGX_OK) { | |
1257 | |
1258 /* a header line has been parsed successfully */ | |
507 | 1259 |
509 | 1260 h = ngx_list_push(&r->upstream->headers_in.headers); |
1261 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
|
1262 return NGX_ERROR; |
509 | 1263 } |
1264 | |
1265 h->hash = r->header_hash; | |
1266 | |
1267 h->key.len = r->header_name_end - r->header_name_start; | |
1268 h->value.len = r->header_end - r->header_start; | |
1269 | |
2049 | 1270 h->key.data = ngx_pnalloc(r->pool, |
649 | 1271 h->key.len + 1 + h->value.len + 1 + h->key.len); |
509 | 1272 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
|
1273 return NGX_ERROR; |
509 | 1274 } |
1275 | |
1276 h->value.data = h->key.data + h->key.len + 1; | |
649 | 1277 h->lowcase_key = h->key.data + h->key.len + 1 + h->value.len + 1; |
507 | 1278 |
509 | 1279 ngx_cpystrn(h->key.data, r->header_name_start, h->key.len + 1); |
1280 ngx_cpystrn(h->value.data, r->header_start, h->value.len + 1); | |
1281 | |
649 | 1282 if (h->key.len == r->lowcase_index) { |
1283 ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len); | |
1284 | |
1285 } else { | |
2135 | 1286 ngx_strlow(h->lowcase_key, h->key.data, h->key.len); |
509 | 1287 } |
1288 | |
649 | 1289 hh = ngx_hash_find(&umcf->headers_in_hash, h->hash, |
1290 h->lowcase_key, h->key.len); | |
1291 | |
1292 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
|
1293 return NGX_ERROR; |
649 | 1294 } |
1295 | |
509 | 1296 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1297 "http proxy header: \"%V: %V\"", | |
1298 &h->key, &h->value); | |
1299 | |
1300 continue; | |
1301 } | |
1302 | |
1303 if (rc == NGX_HTTP_PARSE_HEADER_DONE) { | |
1304 | |
1305 /* a whole header has been parsed successfully */ | |
1306 | |
1307 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1308 "http proxy header done"); | |
1309 | |
649 | 1310 /* |
1311 * if no "Server" and "Date" in header line, | |
1312 * then add the special empty headers | |
1313 */ | |
1314 | |
1315 if (r->upstream->headers_in.server == NULL) { | |
1316 h = ngx_list_push(&r->upstream->headers_in.headers); | |
1317 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
|
1318 return NGX_ERROR; |
649 | 1319 } |
1320 | |
1321 h->hash = ngx_hash(ngx_hash(ngx_hash(ngx_hash( | |
1322 ngx_hash('s', 'e'), 'r'), 'v'), 'e'), 'r'); | |
1323 | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3477
diff
changeset
|
1324 ngx_str_set(&h->key, "Server"); |
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3477
diff
changeset
|
1325 ngx_str_null(&h->value); |
649 | 1326 h->lowcase_key = (u_char *) "server"; |
1327 } | |
1328 | |
1329 if (r->upstream->headers_in.date == NULL) { | |
1330 h = ngx_list_push(&r->upstream->headers_in.headers); | |
1331 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
|
1332 return NGX_ERROR; |
649 | 1333 } |
1334 | |
1335 h->hash = ngx_hash(ngx_hash(ngx_hash('d', 'a'), 't'), 'e'); | |
1336 | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3477
diff
changeset
|
1337 ngx_str_set(&h->key, "Date"); |
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3477
diff
changeset
|
1338 ngx_str_null(&h->value); |
649 | 1339 h->lowcase_key = (u_char *) "date"; |
1340 } | |
1341 | |
509 | 1342 return NGX_OK; |
1343 } | |
1344 | |
521 | 1345 if (rc == NGX_AGAIN) { |
1346 return NGX_AGAIN; | |
1347 } | |
1348 | |
509 | 1349 /* there was error while a header line parsing */ |
1350 | |
1351 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
619 | 1352 "upstream sent invalid header"); |
509 | 1353 |
1354 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | |
1355 } | |
507 | 1356 } |
1357 | |
1358 | |
1359 static void | |
1360 ngx_http_proxy_abort_request(ngx_http_request_t *r) | |
1361 { | |
1362 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1363 "abort http proxy request"); | |
577 | 1364 |
507 | 1365 return; |
1366 } | |
1367 | |
1368 | |
1369 static void | |
1370 ngx_http_proxy_finalize_request(ngx_http_request_t *r, ngx_int_t rc) | |
577 | 1371 { |
507 | 1372 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1373 "finalize http proxy request"); | |
1374 | |
1375 return; | |
1376 } | |
1377 | |
1378 | |
573 | 1379 static ngx_int_t |
1380 ngx_http_proxy_host_variable(ngx_http_request_t *r, | |
1381 ngx_http_variable_value_t *v, uintptr_t data) | |
507 | 1382 { |
1658 | 1383 ngx_http_proxy_ctx_t *ctx; |
1384 | |
1385 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
1386 | |
1387 if (ctx == NULL) { | |
1388 v->not_found = 1; | |
1389 return NGX_OK; | |
1390 } | |
1391 | |
1392 v->len = ctx->vars.host_header.len; | |
577 | 1393 v->valid = 1; |
1565 | 1394 v->no_cacheable = 0; |
573 | 1395 v->not_found = 0; |
1658 | 1396 v->data = ctx->vars.host_header.data; |
507 | 1397 |
573 | 1398 return NGX_OK; |
507 | 1399 } |
1400 | |
1401 | |
573 | 1402 static ngx_int_t |
1403 ngx_http_proxy_port_variable(ngx_http_request_t *r, | |
1404 ngx_http_variable_value_t *v, uintptr_t data) | |
507 | 1405 { |
1658 | 1406 ngx_http_proxy_ctx_t *ctx; |
1407 | |
1408 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
1409 | |
1410 if (ctx == NULL) { | |
1411 v->not_found = 1; | |
1412 return NGX_OK; | |
1413 } | |
1414 | |
1415 v->len = ctx->vars.port.len; | |
577 | 1416 v->valid = 1; |
1565 | 1417 v->no_cacheable = 0; |
573 | 1418 v->not_found = 0; |
1658 | 1419 v->data = ctx->vars.port.data; |
509 | 1420 |
573 | 1421 return NGX_OK; |
509 | 1422 } |
1423 | |
1424 | |
573 | 1425 static ngx_int_t |
509 | 1426 ngx_http_proxy_add_x_forwarded_for_variable(ngx_http_request_t *r, |
573 | 1427 ngx_http_variable_value_t *v, uintptr_t data) |
509 | 1428 { |
573 | 1429 u_char *p; |
509 | 1430 |
577 | 1431 v->valid = 1; |
1565 | 1432 v->no_cacheable = 0; |
573 | 1433 v->not_found = 0; |
509 | 1434 |
1435 if (r->headers_in.x_forwarded_for == NULL) { | |
573 | 1436 v->len = r->connection->addr_text.len; |
1437 v->data = r->connection->addr_text.data; | |
1438 return NGX_OK; | |
509 | 1439 } |
1440 | |
573 | 1441 v->len = r->headers_in.x_forwarded_for->value.len |
1442 + sizeof(", ") - 1 + r->connection->addr_text.len; | |
509 | 1443 |
2049 | 1444 p = ngx_pnalloc(r->pool, v->len); |
509 | 1445 if (p == NULL) { |
573 | 1446 return NGX_ERROR; |
509 | 1447 } |
1448 | |
573 | 1449 v->data = p; |
509 | 1450 |
573 | 1451 p = ngx_copy(p, r->headers_in.x_forwarded_for->value.data, |
1452 r->headers_in.x_forwarded_for->value.len); | |
509 | 1453 |
1454 *p++ = ','; *p++ = ' '; | |
1455 | |
1456 ngx_memcpy(p, r->connection->addr_text.data, r->connection->addr_text.len); | |
1457 | |
573 | 1458 return NGX_OK; |
509 | 1459 } |
1460 | |
1461 | |
1462 static ngx_int_t | |
577 | 1463 ngx_http_proxy_internal_body_length_variable(ngx_http_request_t *r, |
1464 ngx_http_variable_value_t *v, uintptr_t data) | |
1465 { | |
1658 | 1466 ngx_http_proxy_ctx_t *ctx; |
1467 | |
1468 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
1469 | |
1470 if (ctx == NULL) { | |
577 | 1471 v->not_found = 1; |
1472 return NGX_OK; | |
1473 } | |
1474 | |
1475 v->valid = 1; | |
1565 | 1476 v->no_cacheable = 0; |
577 | 1477 v->not_found = 0; |
1478 | |
2049 | 1479 v->data = ngx_pnalloc(r->connection->pool, NGX_SIZE_T_LEN); |
577 | 1480 |
1481 if (v->data == NULL) { | |
1482 return NGX_ERROR; | |
1483 } | |
1484 | |
1658 | 1485 v->len = ngx_sprintf(v->data, "%uz", ctx->internal_body_length) - v->data; |
577 | 1486 |
1487 return NGX_OK; | |
1488 } | |
1489 | |
1490 | |
1491 static ngx_int_t | |
509 | 1492 ngx_http_proxy_rewrite_redirect(ngx_http_request_t *r, ngx_table_elt_t *h, |
1493 size_t prefix) | |
1494 { | |
1495 ngx_int_t rc; | |
1496 ngx_uint_t i; | |
1497 ngx_http_proxy_loc_conf_t *plcf; | |
1498 ngx_http_proxy_redirect_t *pr; | |
1499 | |
1500 plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module); | |
1501 | |
1502 pr = plcf->redirects->elts; | |
1503 | |
1504 if (pr == NULL) { | |
1505 return NGX_DECLINED; | |
1506 } | |
1507 | |
1508 for (i = 0; i < plcf->redirects->nelts; i++) { | |
605 | 1509 rc = pr[i].handler(r, h, prefix, &pr[i]); |
509 | 1510 |
1511 if (rc != NGX_DECLINED) { | |
1512 return rc; | |
1513 } | |
1514 } | |
1515 | |
1516 return NGX_DECLINED; | |
1517 } | |
1518 | |
1519 | |
1520 static ngx_int_t | |
1521 ngx_http_proxy_rewrite_redirect_text(ngx_http_request_t *r, ngx_table_elt_t *h, | |
1522 size_t prefix, ngx_http_proxy_redirect_t *pr) | |
1523 { | |
1524 size_t len; | |
1525 u_char *data, *p; | |
1526 | |
1527 if (pr->redirect.len > h->value.len - prefix | |
1528 || ngx_rstrncmp(h->value.data + prefix, pr->redirect.data, | |
1529 pr->redirect.len) != 0) | |
1530 { | |
1531 return NGX_DECLINED; | |
1532 } | |
1533 | |
3605
ef078f482a89
fix rewritten Refresh header length
Igor Sysoev <igor@sysoev.ru>
parents:
3561
diff
changeset
|
1534 len = pr->replacement.text.len + h->value.len - pr->redirect.len; |
507 | 1535 |
2049 | 1536 data = ngx_pnalloc(r->pool, len); |
509 | 1537 if (data == NULL) { |
1538 return NGX_ERROR; | |
1539 } | |
1540 | |
3606 | 1541 p = ngx_copy(data, h->value.data, prefix); |
509 | 1542 |
653 | 1543 if (pr->replacement.text.len) { |
1544 p = ngx_copy(p, pr->replacement.text.data, pr->replacement.text.len); | |
1545 } | |
509 | 1546 |
1547 ngx_memcpy(p, h->value.data + prefix + pr->redirect.len, | |
1548 h->value.len - pr->redirect.len - prefix); | |
1549 | |
1550 h->value.len = len; | |
1551 h->value.data = data; | |
1552 | |
1553 return NGX_OK; | |
1554 } | |
1555 | |
1556 | |
1557 static ngx_int_t | |
1558 ngx_http_proxy_rewrite_redirect_vars(ngx_http_request_t *r, ngx_table_elt_t *h, | |
1559 size_t prefix, ngx_http_proxy_redirect_t *pr) | |
1560 { | |
1561 size_t len; | |
1562 u_char *data, *p; | |
1563 ngx_http_script_code_pt code; | |
1564 ngx_http_script_engine_t e; | |
1565 ngx_http_script_len_code_pt lcode; | |
1566 | |
1567 if (pr->redirect.len > h->value.len - prefix | |
1568 || ngx_rstrncmp(h->value.data + prefix, pr->redirect.data, | |
1569 pr->redirect.len) != 0) | |
1570 { | |
1571 return NGX_DECLINED; | |
1572 } | |
1573 | |
1574 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); | |
1575 | |
1576 e.ip = pr->replacement.vars.lengths; | |
1577 e.request = r; | |
1578 | |
3605
ef078f482a89
fix rewritten Refresh header length
Igor Sysoev <igor@sysoev.ru>
parents:
3561
diff
changeset
|
1579 len = h->value.len - pr->redirect.len; |
723
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1580 |
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1581 while (*(uintptr_t *) e.ip) { |
509 | 1582 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
|
1583 len += lcode(&e); |
509 | 1584 } |
1585 | |
2049 | 1586 data = ngx_pnalloc(r->pool, len); |
509 | 1587 if (data == NULL) { |
1588 return NGX_ERROR; | |
1589 } | |
1590 | |
3606 | 1591 p = ngx_copy(data, h->value.data, prefix); |
509 | 1592 |
1593 e.ip = pr->replacement.vars.values; | |
1594 e.pos = p; | |
1595 | |
1596 while (*(uintptr_t *) e.ip) { | |
1597 code = *(ngx_http_script_code_pt *) e.ip; | |
1598 code(&e); | |
1599 } | |
1600 | |
723
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1601 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
|
1602 h->value.len - pr->redirect.len - prefix); |
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1603 |
509 | 1604 h->value.len = len; |
1605 h->value.data = data; | |
1606 | |
1607 return NGX_OK; | |
1608 } | |
1609 | |
1610 | |
1611 static ngx_int_t | |
1612 ngx_http_proxy_add_variables(ngx_conf_t *cf) | |
1613 { | |
1614 ngx_http_variable_t *var, *v; | |
1615 | |
1616 for (v = ngx_http_proxy_vars; v->name.len; v++) { | |
1617 var = ngx_http_add_variable(cf, &v->name, v->flags); | |
1618 if (var == NULL) { | |
1619 return NGX_ERROR; | |
1620 } | |
1621 | |
637 | 1622 var->get_handler = v->get_handler; |
509 | 1623 var->data = v->data; |
1624 } | |
1625 | |
1626 return NGX_OK; | |
507 | 1627 } |
1628 | |
1629 | |
1630 static void * | |
1631 ngx_http_proxy_create_loc_conf(ngx_conf_t *cf) | |
1632 { | |
1633 ngx_http_proxy_loc_conf_t *conf; | |
1634 | |
1635 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_proxy_loc_conf_t)); | |
1636 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
|
1637 return NULL; |
507 | 1638 } |
1639 | |
1640 /* | |
1641 * set by ngx_pcalloc(): | |
1642 * | |
1643 * conf->upstream.bufs.num = 0; | |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2784
diff
changeset
|
1644 * conf->upstream.ignore_headers = 0; |
507 | 1645 * conf->upstream.next_upstream = 0; |
2875
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2786
diff
changeset
|
1646 * conf->upstream.cache_use_stale = 0; |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2786
diff
changeset
|
1647 * conf->upstream.cache_methods = 0; |
507 | 1648 * conf->upstream.temp_path = NULL; |
649 | 1649 * conf->upstream.hide_headers_hash = { NULL, 0 }; |
509 | 1650 * conf->upstream.uri = { 0, NULL }; |
1651 * conf->upstream.location = NULL; | |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1652 * conf->upstream.store_lengths = NULL; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1653 * conf->upstream.store_values = NULL; |
509 | 1654 * |
561 | 1655 * conf->method = NULL; |
509 | 1656 * conf->headers_source = NULL; |
1657 * conf->headers_set_len = NULL; | |
1658 * conf->headers_set = NULL; | |
1659 * conf->headers_set_hash = NULL; | |
577 | 1660 * conf->body_set_len = NULL; |
1661 * conf->body_set = NULL; | |
1662 * conf->body_source = { 0, NULL }; | |
3470
b982f2dee8cf
fix proxy_redirect name in error message
Igor Sysoev <igor@sysoev.ru>
parents:
3399
diff
changeset
|
1663 * conf->redirects = NULL; |
507 | 1664 */ |
577 | 1665 |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1666 conf->upstream.store = NGX_CONF_UNSET; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1667 conf->upstream.store_access = NGX_CONF_UNSET_UINT; |
581 | 1668 conf->upstream.buffering = NGX_CONF_UNSET; |
629 | 1669 conf->upstream.ignore_client_abort = NGX_CONF_UNSET; |
581 | 1670 |
507 | 1671 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC; |
1672 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC; | |
1673 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC; | |
1674 | |
1675 conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE; | |
581 | 1676 conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE; |
529 | 1677 |
1678 conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE; | |
577 | 1679 conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE; |
529 | 1680 conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE; |
509 | 1681 |
1682 conf->upstream.pass_request_headers = NGX_CONF_UNSET; | |
1683 conf->upstream.pass_request_body = NGX_CONF_UNSET; | |
561 | 1684 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1685 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1686 conf->upstream.cache = NGX_CONF_UNSET_PTR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1687 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
|
1688 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
|
1689 conf->upstream.no_cache = NGX_CONF_UNSET_PTR; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1690 conf->upstream.cache_valid = NGX_CONF_UNSET_PTR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1691 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1692 |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
1693 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
|
1694 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
|
1695 |
657 | 1696 conf->upstream.intercept_errors = NGX_CONF_UNSET; |
2184 | 1697 #if (NGX_HTTP_SSL) |
1698 conf->upstream.ssl_session_reuse = NGX_CONF_UNSET; | |
1699 #endif | |
507 | 1700 |
1701 /* "proxy_cyclic_temp_file" is disabled */ | |
1702 conf->upstream.cyclic_temp_file = 0; | |
1703 | |
509 | 1704 conf->redirect = NGX_CONF_UNSET; |
649 | 1705 conf->upstream.change_buffering = 1; |
507 | 1706 |
1180
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1707 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
|
1708 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
|
1709 |
507 | 1710 return conf; |
1711 } | |
1712 | |
1713 | |
1714 static char * | |
1715 ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | |
1716 { | |
1717 ngx_http_proxy_loc_conf_t *prev = parent; | |
1718 ngx_http_proxy_loc_conf_t *conf = child; | |
1719 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1720 size_t size; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1721 ngx_keyval_t *s; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1722 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
|
1723 ngx_http_core_loc_conf_t *clcf; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1724 ngx_http_proxy_redirect_t *pr; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1725 ngx_http_script_compile_t sc; |
509 | 1726 |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1727 if (conf->upstream.store != 0) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1728 ngx_conf_merge_value(conf->upstream.store, |
2894 | 1729 prev->upstream.store, 0); |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1730 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1731 if (conf->upstream.store_lengths == NULL) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1732 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
|
1733 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
|
1734 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1735 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1736 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1737 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
|
1738 prev->upstream.store_access, 0600); |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1244
diff
changeset
|
1739 |
581 | 1740 ngx_conf_merge_value(conf->upstream.buffering, |
1741 prev->upstream.buffering, 1); | |
1742 | |
629 | 1743 ngx_conf_merge_value(conf->upstream.ignore_client_abort, |
1744 prev->upstream.ignore_client_abort, 0); | |
1745 | |
507 | 1746 ngx_conf_merge_msec_value(conf->upstream.connect_timeout, |
1747 prev->upstream.connect_timeout, 60000); | |
1748 | |
1749 ngx_conf_merge_msec_value(conf->upstream.send_timeout, | |
1750 prev->upstream.send_timeout, 60000); | |
1751 | |
1752 ngx_conf_merge_msec_value(conf->upstream.read_timeout, | |
1753 prev->upstream.read_timeout, 60000); | |
1754 | |
1755 ngx_conf_merge_size_value(conf->upstream.send_lowat, | |
1756 prev->upstream.send_lowat, 0); | |
1757 | |
581 | 1758 ngx_conf_merge_size_value(conf->upstream.buffer_size, |
1759 prev->upstream.buffer_size, | |
507 | 1760 (size_t) ngx_pagesize); |
1761 | |
1762 ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs, | |
1763 8, ngx_pagesize); | |
1764 | |
1765 if (conf->upstream.bufs.num < 2) { | |
577 | 1766 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
507 | 1767 "there must be at least 2 \"proxy_buffers\""); |
1768 return NGX_CONF_ERROR; | |
1769 } | |
577 | 1770 |
507 | 1771 |
581 | 1772 size = conf->upstream.buffer_size; |
577 | 1773 if (size < conf->upstream.bufs.size) { |
507 | 1774 size = conf->upstream.bufs.size; |
1775 } | |
1776 | |
1777 | |
529 | 1778 ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf, |
1779 prev->upstream.busy_buffers_size_conf, | |
507 | 1780 NGX_CONF_UNSET_SIZE); |
1781 | |
529 | 1782 if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) { |
507 | 1783 conf->upstream.busy_buffers_size = 2 * size; |
529 | 1784 } else { |
1785 conf->upstream.busy_buffers_size = | |
1786 conf->upstream.busy_buffers_size_conf; | |
1787 } | |
577 | 1788 |
529 | 1789 if (conf->upstream.busy_buffers_size < size) { |
507 | 1790 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1791 "\"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
|
1792 "maximum of the value of \"proxy_buffer_size\" and " |
507 | 1793 "one of the \"proxy_buffers\""); |
1794 | |
1795 return NGX_CONF_ERROR; | |
529 | 1796 } |
507 | 1797 |
529 | 1798 if (conf->upstream.busy_buffers_size |
1799 > (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size) | |
507 | 1800 { |
1801 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1802 "\"proxy_busy_buffers_size\" must be less than " | |
1803 "the size of all \"proxy_buffers\" minus one buffer"); | |
1804 | |
1805 return NGX_CONF_ERROR; | |
1806 } | |
529 | 1807 |
507 | 1808 |
529 | 1809 ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf, |
1810 prev->upstream.temp_file_write_size_conf, | |
507 | 1811 NGX_CONF_UNSET_SIZE); |
1812 | |
529 | 1813 if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) { |
507 | 1814 conf->upstream.temp_file_write_size = 2 * size; |
529 | 1815 } else { |
1816 conf->upstream.temp_file_write_size = | |
1817 conf->upstream.temp_file_write_size_conf; | |
1818 } | |
577 | 1819 |
529 | 1820 if (conf->upstream.temp_file_write_size < size) { |
507 | 1821 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1822 "\"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
|
1823 "maximum of the value of \"proxy_buffer_size\" and " |
507 | 1824 "one of the \"proxy_buffers\""); |
1825 | |
1826 return NGX_CONF_ERROR; | |
1827 } | |
1828 | |
529 | 1829 ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf, |
1830 prev->upstream.max_temp_file_size_conf, | |
507 | 1831 NGX_CONF_UNSET_SIZE); |
1832 | |
529 | 1833 if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) { |
507 | 1834 conf->upstream.max_temp_file_size = 1024 * 1024 * 1024; |
529 | 1835 } else { |
1836 conf->upstream.max_temp_file_size = | |
1837 conf->upstream.max_temp_file_size_conf; | |
1838 } | |
507 | 1839 |
529 | 1840 if (conf->upstream.max_temp_file_size != 0 |
1841 && conf->upstream.max_temp_file_size < size) | |
507 | 1842 { |
1843 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
561 | 1844 "\"proxy_max_temp_file_size\" must be equal to zero to disable " |
507 | 1845 "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
|
1846 "maximum of the value of \"proxy_buffer_size\" and " |
561 | 1847 "one of the \"proxy_buffers\""); |
507 | 1848 |
1849 return NGX_CONF_ERROR; | |
1850 } | |
1851 | |
529 | 1852 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2784
diff
changeset
|
1853 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
|
1854 prev->upstream.ignore_headers, |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2784
diff
changeset
|
1855 NGX_CONF_BITMASK_SET); |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2784
diff
changeset
|
1856 |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2784
diff
changeset
|
1857 |
507 | 1858 ngx_conf_merge_bitmask_value(conf->upstream.next_upstream, |
1859 prev->upstream.next_upstream, | |
1860 (NGX_CONF_BITMASK_SET | |
1861 |NGX_HTTP_UPSTREAM_FT_ERROR | |
1862 |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); | |
1863 | |
665 | 1864 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) { |
1865 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET | |
1866 |NGX_HTTP_UPSTREAM_FT_OFF; | |
1867 } | |
1868 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1869 if (ngx_conf_merge_path_value(cf, &conf->upstream.temp_path, |
509 | 1870 prev->upstream.temp_path, |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1871 &ngx_http_proxy_temp_path) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1872 != NGX_OK) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1873 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1874 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1875 } |
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 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1878 #if (NGX_HTTP_CACHE) |
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 ngx_conf_merge_ptr_value(conf->upstream.cache, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1881 prev->upstream.cache, NULL); |
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 if (conf->upstream.cache && conf->upstream.cache->data == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1884 ngx_shm_zone_t *shm_zone; |
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 shm_zone = conf->upstream.cache; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1887 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1888 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1889 "\"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
|
1890 &shm_zone->shm.name); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1891 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1892 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1893 } |
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 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
|
1896 prev->upstream.cache_min_uses, 1); |
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_bitmask_value(conf->upstream.cache_use_stale, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1899 prev->upstream.cache_use_stale, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1900 (NGX_CONF_BITMASK_SET |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1901 |NGX_HTTP_UPSTREAM_FT_OFF)); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1902 |
2875
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2786
diff
changeset
|
1903 if (conf->upstream.cache_methods == 0) { |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2786
diff
changeset
|
1904 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
|
1905 } |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2786
diff
changeset
|
1906 |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2786
diff
changeset
|
1907 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
|
1908 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1909 if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_OFF) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1910 conf->upstream.cache_use_stale = NGX_CONF_BITMASK_SET |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1911 |NGX_HTTP_UPSTREAM_FT_OFF; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1912 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1913 |
3699
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3692
diff
changeset
|
1914 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
|
1915 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
|
1916 |
3526
62a4fd1e6e2c
proxy_no_cache and fastcgi_no_cache
Igor Sysoev <igor@sysoev.ru>
parents:
3523
diff
changeset
|
1917 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
|
1918 prev->upstream.no_cache, NULL); |
62a4fd1e6e2c
proxy_no_cache and fastcgi_no_cache
Igor Sysoev <igor@sysoev.ru>
parents:
3523
diff
changeset
|
1919 |
3700
e40453e6931b
add warnings for proxy_no_cache and fastcgi_no_cache
Igor Sysoev <igor@sysoev.ru>
parents:
3699
diff
changeset
|
1920 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
|
1921 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
|
1922 "\"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
|
1923 "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
|
1924 } |
e40453e6931b
add warnings for proxy_no_cache and fastcgi_no_cache
Igor Sysoev <igor@sysoev.ru>
parents:
3699
diff
changeset
|
1925 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1926 ngx_conf_merge_ptr_value(conf->upstream.cache_valid, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1927 prev->upstream.cache_valid, NULL); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1928 |
2672 | 1929 if (conf->cache_key.value.data == NULL) { |
1930 conf->cache_key = prev->cache_key; | |
1931 } | |
1932 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
1933 #endif |
507 | 1934 |
561 | 1935 if (conf->method.len == 0) { |
1936 conf->method = prev->method; | |
1937 | |
1938 } else { | |
1939 conf->method.data[conf->method.len] = ' '; | |
1940 conf->method.len++; | |
509 | 1941 } |
1942 | |
1943 ngx_conf_merge_value(conf->upstream.pass_request_headers, | |
1944 prev->upstream.pass_request_headers, 1); | |
1945 ngx_conf_merge_value(conf->upstream.pass_request_body, | |
1946 prev->upstream.pass_request_body, 1); | |
1947 | |
657 | 1948 ngx_conf_merge_value(conf->upstream.intercept_errors, |
1949 prev->upstream.intercept_errors, 0); | |
509 | 1950 |
2184 | 1951 #if (NGX_HTTP_SSL) |
1952 ngx_conf_merge_value(conf->upstream.ssl_session_reuse, | |
1953 prev->upstream.ssl_session_reuse, 1); | |
1954 #endif | |
1955 | |
509 | 1956 ngx_conf_merge_value(conf->redirect, prev->redirect, 1); |
1957 | |
1958 if (conf->redirect) { | |
507 | 1959 |
509 | 1960 if (conf->redirects == NULL) { |
1961 conf->redirects = prev->redirects; | |
1962 } | |
1963 | |
1658 | 1964 if (conf->redirects == NULL && conf->url.data) { |
509 | 1965 |
1966 conf->redirects = ngx_array_create(cf->pool, 1, | |
1967 sizeof(ngx_http_proxy_redirect_t)); | |
1968 if (conf->redirects == NULL) { | |
1969 return NGX_CONF_ERROR; | |
1970 } | |
1971 | |
1972 pr = ngx_array_push(conf->redirects); | |
1973 if (pr == NULL) { | |
1974 return NGX_CONF_ERROR; | |
1975 } | |
1976 | |
1977 pr->handler = ngx_http_proxy_rewrite_redirect_text; | |
1658 | 1978 pr->redirect = conf->url; |
1979 | |
1980 if (conf->vars.uri.len) { | |
1981 pr->replacement.text = conf->location; | |
653 | 1982 |
1983 } else { | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3477
diff
changeset
|
1984 ngx_str_null(&pr->replacement.text); |
653 | 1985 } |
509 | 1986 } |
1987 } | |
1988 | |
2753
9ba1bee1b1e4
merge SSL context inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
1989 #if (NGX_HTTP_SSL) |
9ba1bee1b1e4
merge SSL context inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
1990 if (conf->upstream.ssl == NULL) { |
9ba1bee1b1e4
merge SSL context inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
1991 conf->upstream.ssl = prev->upstream.ssl; |
9ba1bee1b1e4
merge SSL context inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
1992 } |
9ba1bee1b1e4
merge SSL context inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
1993 #endif |
9ba1bee1b1e4
merge SSL context inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
1994 |
1180
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1995 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
|
1996 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
|
1997 |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1998 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
|
1999 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
|
2000 |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
2001 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
|
2002 ngx_cacheline_size); |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
2003 |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
2004 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
|
2005 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
|
2006 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
|
2007 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
2008 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
|
2009 &prev->upstream, ngx_http_proxy_hide_headers, &hash) |
649 | 2010 != NGX_OK) |
2011 { | |
2012 return NGX_CONF_ERROR; | |
2013 } | |
2014 | |
884 | 2015 if (conf->upstream.upstream == NULL) { |
2016 conf->upstream.upstream = prev->upstream.upstream; | |
1658 | 2017 conf->vars = prev->vars; |
507 | 2018 } |
2019 | |
3734
e3a6785b5be4
*) make code consistent to fastcgi, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3733
diff
changeset
|
2020 if (conf->proxy_lengths == NULL) { |
e3a6785b5be4
*) make code consistent to fastcgi, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3733
diff
changeset
|
2021 conf->proxy_lengths = prev->proxy_lengths; |
e3a6785b5be4
*) make code consistent to fastcgi, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3733
diff
changeset
|
2022 conf->proxy_values = prev->proxy_values; |
e3a6785b5be4
*) make code consistent to fastcgi, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3733
diff
changeset
|
2023 } |
e3a6785b5be4
*) make code consistent to fastcgi, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3733
diff
changeset
|
2024 |
3731
72cc5b789021
inherit proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass inside
Igor Sysoev <igor@sysoev.ru>
parents:
3729
diff
changeset
|
2025 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
|
2026 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
|
2027 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
|
2028 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
|
2029 conf->location = prev->location; |
72cc5b789021
inherit proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass inside
Igor Sysoev <igor@sysoev.ru>
parents:
3729
diff
changeset
|
2030 } |
72cc5b789021
inherit proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass inside
Igor Sysoev <igor@sysoev.ru>
parents:
3729
diff
changeset
|
2031 } |
577 | 2032 |
2033 if (conf->body_source.data == NULL) { | |
2034 conf->body_source = prev->body_source; | |
2035 conf->body_set_len = prev->body_set_len; | |
2036 conf->body_set = prev->body_set; | |
2037 } | |
2038 | |
579 | 2039 if (conf->body_source.data && conf->body_set_len == NULL) { |
577 | 2040 |
2041 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
2042 | |
2043 sc.cf = cf; | |
2044 sc.source = &conf->body_source; | |
2045 sc.flushes = &conf->flushes; | |
2046 sc.lengths = &conf->body_set_len; | |
2047 sc.values = &conf->body_set; | |
2048 sc.complete_lengths = 1; | |
2049 sc.complete_values = 1; | |
2050 | |
2051 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
2052 return NGX_CONF_ERROR; | |
2053 } | |
2054 | |
2055 if (conf->headers_source == NULL) { | |
2056 conf->headers_source = ngx_array_create(cf->pool, 4, | |
649 | 2057 sizeof(ngx_keyval_t)); |
577 | 2058 if (conf->headers_source == NULL) { |
2059 return NGX_CONF_ERROR; | |
2060 } | |
2061 } | |
2062 | |
2063 s = ngx_array_push(conf->headers_source); | |
2064 if (s == NULL) { | |
2065 return NGX_CONF_ERROR; | |
2066 } | |
2067 | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3477
diff
changeset
|
2068 ngx_str_set(&s->key, "Content-Length"); |
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3477
diff
changeset
|
2069 ngx_str_set(&s->value, "$proxy_internal_body_length"); |
577 | 2070 } |
2071 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2072 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
|
2073 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2074 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2075 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2076 return NGX_CONF_OK; |
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 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2080 static ngx_int_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2081 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
|
2082 ngx_http_proxy_loc_conf_t *prev) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2083 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2084 u_char *p; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2085 size_t size; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2086 uintptr_t *code; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2087 ngx_uint_t i; |
3561
20708cffd6dc
use local headers_names array instead of stored in configuration
Igor Sysoev <igor@sysoev.ru>
parents:
3526
diff
changeset
|
2088 ngx_array_t headers_names; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2089 ngx_keyval_t *src, *s, *h; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2090 ngx_hash_key_t *hk; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2091 ngx_hash_init_t hash; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2092 ngx_http_script_compile_t sc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2093 ngx_http_script_copy_code_t *copy; |
577 | 2094 |
509 | 2095 if (conf->headers_source == NULL) { |
573 | 2096 conf->flushes = prev->flushes; |
507 | 2097 conf->headers_set_len = prev->headers_set_len; |
2098 conf->headers_set = prev->headers_set; | |
2099 conf->headers_set_hash = prev->headers_set_hash; | |
573 | 2100 conf->headers_source = prev->headers_source; |
507 | 2101 } |
2102 | |
2929
37b7cd336fdf
inherit proxy_set_header, proxy_hide_header, and fastcgi_hide_header
Igor Sysoev <igor@sysoev.ru>
parents:
2927
diff
changeset
|
2103 if (conf->headers_set_hash.buckets |
2949
fe484c0be7c0
fix building --without-http-cache, broken in r2930
Igor Sysoev <igor@sysoev.ru>
parents:
2929
diff
changeset
|
2104 #if (NGX_HTTP_CACHE) |
fe484c0be7c0
fix building --without-http-cache, broken in r2930
Igor Sysoev <igor@sysoev.ru>
parents:
2929
diff
changeset
|
2105 && ((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
|
2106 #endif |
fe484c0be7c0
fix building --without-http-cache, broken in r2930
Igor Sysoev <igor@sysoev.ru>
parents:
2929
diff
changeset
|
2107 ) |
2929
37b7cd336fdf
inherit proxy_set_header, proxy_hide_header, and fastcgi_hide_header
Igor Sysoev <igor@sysoev.ru>
parents:
2927
diff
changeset
|
2108 { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2109 return NGX_OK; |
509 | 2110 } |
2111 | |
2112 | |
3561
20708cffd6dc
use local headers_names array instead of stored in configuration
Igor Sysoev <igor@sysoev.ru>
parents:
3526
diff
changeset
|
2113 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
|
2114 != NGX_OK) |
20708cffd6dc
use local headers_names array instead of stored in configuration
Igor Sysoev <igor@sysoev.ru>
parents:
3526
diff
changeset
|
2115 { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2116 return NGX_ERROR; |
509 | 2117 } |
2118 | |
2119 if (conf->headers_source == NULL) { | |
2120 conf->headers_source = ngx_array_create(cf->pool, 4, | |
649 | 2121 sizeof(ngx_keyval_t)); |
509 | 2122 if (conf->headers_source == NULL) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2123 return NGX_ERROR; |
509 | 2124 } |
2125 } | |
507 | 2126 |
509 | 2127 conf->headers_set_len = ngx_array_create(cf->pool, 64, 1); |
2128 if (conf->headers_set_len == NULL) { | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2129 return NGX_ERROR; |
509 | 2130 } |
2131 | |
2132 conf->headers_set = ngx_array_create(cf->pool, 512, 1); | |
2133 if (conf->headers_set == NULL) { | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2134 return NGX_ERROR; |
509 | 2135 } |
2136 | |
2137 | |
2138 src = conf->headers_source->elts; | |
2139 | |
2705
d040c3786239
do not pass if-... headers for cacheable responses
Igor Sysoev <igor@sysoev.ru>
parents:
2672
diff
changeset
|
2140 #if (NGX_HTTP_CACHE) |
d040c3786239
do not pass if-... headers for cacheable responses
Igor Sysoev <igor@sysoev.ru>
parents:
2672
diff
changeset
|
2141 |
d040c3786239
do not pass if-... headers for cacheable responses
Igor Sysoev <igor@sysoev.ru>
parents:
2672
diff
changeset
|
2142 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
|
2143 ngx_http_proxy_headers; |
d040c3786239
do not pass if-... headers for cacheable responses
Igor Sysoev <igor@sysoev.ru>
parents:
2672
diff
changeset
|
2144 #else |
d040c3786239
do not pass if-... headers for cacheable responses
Igor Sysoev <igor@sysoev.ru>
parents:
2672
diff
changeset
|
2145 |
d040c3786239
do not pass if-... headers for cacheable responses
Igor Sysoev <igor@sysoev.ru>
parents:
2672
diff
changeset
|
2146 h = ngx_http_proxy_headers; |
d040c3786239
do not pass if-... headers for cacheable responses
Igor Sysoev <igor@sysoev.ru>
parents:
2672
diff
changeset
|
2147 |
d040c3786239
do not pass if-... headers for cacheable responses
Igor Sysoev <igor@sysoev.ru>
parents:
2672
diff
changeset
|
2148 #endif |
d040c3786239
do not pass if-... headers for cacheable responses
Igor Sysoev <igor@sysoev.ru>
parents:
2672
diff
changeset
|
2149 |
d040c3786239
do not pass if-... headers for cacheable responses
Igor Sysoev <igor@sysoev.ru>
parents:
2672
diff
changeset
|
2150 while (h->key.len) { |
509 | 2151 |
2152 for (i = 0; i < conf->headers_source->nelts; i++) { | |
2153 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) { | |
2154 goto next; | |
507 | 2155 } |
2156 } | |
2157 | |
509 | 2158 s = ngx_array_push(conf->headers_source); |
2159 if (s == NULL) { | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2160 return NGX_ERROR; |
507 | 2161 } |
2162 | |
509 | 2163 *s = *h; |
507 | 2164 |
517 | 2165 src = conf->headers_source->elts; |
2166 | |
509 | 2167 next: |
507 | 2168 |
2705
d040c3786239
do not pass if-... headers for cacheable responses
Igor Sysoev <igor@sysoev.ru>
parents:
2672
diff
changeset
|
2169 h++; |
509 | 2170 } |
507 | 2171 |
577 | 2172 |
2173 src = conf->headers_source->elts; | |
509 | 2174 for (i = 0; i < conf->headers_source->nelts; i++) { |
507 | 2175 |
3561
20708cffd6dc
use local headers_names array instead of stored in configuration
Igor Sysoev <igor@sysoev.ru>
parents:
3526
diff
changeset
|
2176 hk = ngx_array_push(&headers_names); |
649 | 2177 if (hk == NULL) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2178 return NGX_ERROR; |
507 | 2179 } |
2180 | |
649 | 2181 hk->key = src[i].key; |
2182 hk->key_hash = ngx_hash_key_lc(src[i].key.data, src[i].key.len); | |
2183 hk->value = (void *) 1; | |
509 | 2184 |
519 | 2185 if (src[i].value.len == 0) { |
2186 continue; | |
2187 } | |
2188 | |
509 | 2189 if (ngx_http_script_variables_count(&src[i].value) == 0) { |
2190 copy = ngx_array_push_n(conf->headers_set_len, | |
2191 sizeof(ngx_http_script_copy_code_t)); | |
2192 if (copy == NULL) { | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2193 return NGX_ERROR; |
509 | 2194 } |
2195 | |
2196 copy->code = (ngx_http_script_code_pt) | |
2197 ngx_http_script_copy_len_code; | |
2198 copy->len = src[i].key.len + sizeof(": ") - 1 | |
2199 + src[i].value.len + sizeof(CRLF) - 1; | |
507 | 2200 |
2201 | |
509 | 2202 size = (sizeof(ngx_http_script_copy_code_t) |
2203 + src[i].key.len + sizeof(": ") - 1 | |
2204 + src[i].value.len + sizeof(CRLF) - 1 | |
2205 + sizeof(uintptr_t) - 1) | |
2206 & ~(sizeof(uintptr_t) - 1); | |
2207 | |
2208 copy = ngx_array_push_n(conf->headers_set, size); | |
2209 if (copy == NULL) { | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2210 return NGX_ERROR; |
509 | 2211 } |
2212 | |
2213 copy->code = ngx_http_script_copy_code; | |
2214 copy->len = src[i].key.len + sizeof(": ") - 1 | |
2215 + src[i].value.len + sizeof(CRLF) - 1; | |
2216 | |
2217 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t); | |
2218 | |
2219 p = ngx_cpymem(p, src[i].key.data, src[i].key.len); | |
2220 *p++ = ':'; *p++ = ' '; | |
2221 p = ngx_cpymem(p, src[i].value.data, src[i].value.len); | |
2222 *p++ = CR; *p = LF; | |
2223 | |
2224 } else { | |
2225 copy = ngx_array_push_n(conf->headers_set_len, | |
2226 sizeof(ngx_http_script_copy_code_t)); | |
2227 if (copy == NULL) { | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2228 return NGX_ERROR; |
509 | 2229 } |
2230 | |
2231 copy->code = (ngx_http_script_code_pt) | |
2232 ngx_http_script_copy_len_code; | |
2233 copy->len = src[i].key.len + sizeof(": ") - 1; | |
507 | 2234 |
2235 | |
509 | 2236 size = (sizeof(ngx_http_script_copy_code_t) |
2237 + src[i].key.len + sizeof(": ") - 1 + sizeof(uintptr_t) - 1) | |
2238 & ~(sizeof(uintptr_t) - 1); | |
2239 | |
2240 copy = ngx_array_push_n(conf->headers_set, size); | |
2241 if (copy == NULL) { | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2242 return NGX_ERROR; |
509 | 2243 } |
2244 | |
2245 copy->code = ngx_http_script_copy_code; | |
2246 copy->len = src[i].key.len + sizeof(": ") - 1; | |
2247 | |
2248 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t); | |
2249 p = ngx_cpymem(p, src[i].key.data, src[i].key.len); | |
2250 *p++ = ':'; *p = ' '; | |
2251 | |
2252 | |
2253 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
2254 | |
2255 sc.cf = cf; | |
2256 sc.source = &src[i].value; | |
573 | 2257 sc.flushes = &conf->flushes; |
509 | 2258 sc.lengths = &conf->headers_set_len; |
2259 sc.values = &conf->headers_set; | |
2260 | |
2261 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2262 return NGX_ERROR; |
509 | 2263 } |
2264 | |
2265 | |
2266 copy = ngx_array_push_n(conf->headers_set_len, | |
2267 sizeof(ngx_http_script_copy_code_t)); | |
2268 if (copy == NULL) { | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2269 return NGX_ERROR; |
509 | 2270 } |
2271 | |
2272 copy->code = (ngx_http_script_code_pt) | |
2273 ngx_http_script_copy_len_code; | |
2274 copy->len = sizeof(CRLF) - 1; | |
2275 | |
2276 | |
2277 size = (sizeof(ngx_http_script_copy_code_t) | |
2278 + sizeof(CRLF) - 1 + sizeof(uintptr_t) - 1) | |
2279 & ~(sizeof(uintptr_t) - 1); | |
2280 | |
2281 copy = ngx_array_push_n(conf->headers_set, size); | |
2282 if (copy == NULL) { | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2283 return NGX_ERROR; |
509 | 2284 } |
2285 | |
2286 copy->code = ngx_http_script_copy_code; | |
2287 copy->len = sizeof(CRLF) - 1; | |
2288 | |
2289 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t); | |
2290 *p++ = CR; *p = LF; | |
507 | 2291 } |
2292 | |
509 | 2293 code = ngx_array_push_n(conf->headers_set_len, sizeof(uintptr_t)); |
2294 if (code == NULL) { | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2295 return NGX_ERROR; |
507 | 2296 } |
2297 | |
509 | 2298 *code = (uintptr_t) NULL; |
2299 | |
2300 code = ngx_array_push_n(conf->headers_set, sizeof(uintptr_t)); | |
2301 if (code == NULL) { | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2302 return NGX_ERROR; |
509 | 2303 } |
2304 | |
2305 *code = (uintptr_t) NULL; | |
507 | 2306 } |
2307 | |
509 | 2308 code = ngx_array_push_n(conf->headers_set_len, sizeof(uintptr_t)); |
2309 if (code == NULL) { | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2310 return NGX_ERROR; |
507 | 2311 } |
2312 | |
509 | 2313 *code = (uintptr_t) NULL; |
507 | 2314 |
2315 | |
649 | 2316 hash.hash = &conf->headers_set_hash; |
2317 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
|
2318 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
|
2319 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
|
2320 hash.name = "proxy_headers_hash"; |
649 | 2321 hash.pool = cf->pool; |
2322 hash.temp_pool = NULL; | |
2323 | |
3561
20708cffd6dc
use local headers_names array instead of stored in configuration
Igor Sysoev <igor@sysoev.ru>
parents:
3526
diff
changeset
|
2324 return ngx_hash_init(&hash, headers_names.elts, headers_names.nelts); |
507 | 2325 } |
2326 | |
2327 | |
2328 static char * | |
2329 ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
2330 { | |
509 | 2331 ngx_http_proxy_loc_conf_t *plcf = conf; |
507 | 2332 |
1658 | 2333 size_t add; |
2334 u_short port; | |
2335 ngx_str_t *value, *url; | |
2336 ngx_url_t u; | |
2337 ngx_uint_t n; | |
2338 ngx_http_core_loc_conf_t *clcf; | |
2339 ngx_http_script_compile_t sc; | |
507 | 2340 |
2391
d88e757cc7d8
delete surplus upstream.schema field
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
2341 if (plcf->upstream.upstream || plcf->proxy_lengths) { |
555 | 2342 return "is duplicate"; |
2343 } | |
2344 | |
1658 | 2345 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); |
2346 | |
2989
dff9764eaca2
do auto redirect for proxy_pass/fastcgi_pass with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2949
diff
changeset
|
2347 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
|
2348 |
dff9764eaca2
do auto redirect for proxy_pass/fastcgi_pass with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2949
diff
changeset
|
2349 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
|
2350 clcf->auto_redirect = 1; |
dff9764eaca2
do auto redirect for proxy_pass/fastcgi_pass with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2949
diff
changeset
|
2351 } |
dff9764eaca2
do auto redirect for proxy_pass/fastcgi_pass with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2949
diff
changeset
|
2352 |
507 | 2353 value = cf->args->elts; |
2354 | |
2355 url = &value[1]; | |
2356 | |
1658 | 2357 n = ngx_http_script_variables_count(url); |
2358 | |
2359 if (n) { | |
2360 | |
2361 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
2362 | |
2363 sc.cf = cf; | |
2364 sc.source = url; | |
2365 sc.lengths = &plcf->proxy_lengths; | |
2366 sc.values = &plcf->proxy_values; | |
2367 sc.variables = n; | |
2368 sc.complete_lengths = 1; | |
2369 sc.complete_values = 1; | |
1679
ca317d9b5c09
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1671
diff
changeset
|
2370 |
1658 | 2371 if (ngx_http_script_compile(&sc) != NGX_OK) { |
2372 return NGX_CONF_ERROR; | |
2373 } | |
2374 | |
2375 #if (NGX_HTTP_SSL) | |
2376 if (ngx_http_proxy_set_ssl(cf, plcf) != NGX_OK) { | |
2377 return NGX_CONF_ERROR; | |
2378 } | |
2379 #endif | |
2380 | |
2381 return NGX_CONF_OK; | |
2382 } | |
2383 | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
969
diff
changeset
|
2384 if (ngx_strncasecmp(url->data, (u_char *) "http://", 7) == 0) { |
577 | 2385 add = 7; |
591 | 2386 port = 80; |
577 | 2387 |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
969
diff
changeset
|
2388 } else if (ngx_strncasecmp(url->data, (u_char *) "https://", 8) == 0) { |
577 | 2389 |
2390 #if (NGX_HTTP_SSL) | |
1658 | 2391 if (ngx_http_proxy_set_ssl(cf, plcf) != NGX_OK) { |
2392 return NGX_CONF_ERROR; | |
2393 } | |
577 | 2394 |
2395 add = 8; | |
591 | 2396 port = 443; |
577 | 2397 #else |
2398 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2399 "https protocol requires SSL support"); | |
2400 return NGX_CONF_ERROR; | |
2401 #endif | |
2402 | |
2403 } else { | |
507 | 2404 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid URL prefix"); |
2405 return NGX_CONF_ERROR; | |
2406 } | |
2407 | |
651 | 2408 ngx_memzero(&u, sizeof(ngx_url_t)); |
2409 | |
2410 u.url.len = url->len - add; | |
2411 u.url.data = url->data + add; | |
906 | 2412 u.default_port = port; |
2413 u.uri_part = 1; | |
884 | 2414 u.no_resolve = 1; |
2415 | |
2416 plcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0); | |
2417 if (plcf->upstream.upstream == NULL) { | |
507 | 2418 return NGX_CONF_ERROR; |
2419 } | |
2420 | |
2391
d88e757cc7d8
delete surplus upstream.schema field
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
2421 plcf->vars.schema.len = add; |
d88e757cc7d8
delete surplus upstream.schema field
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
2422 plcf->vars.schema.data = url->data; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2423 plcf->vars.key_start = plcf->vars.schema; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2424 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2425 ngx_http_proxy_set_vars(&u, &plcf->vars); |
507 | 2426 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2427 plcf->location = clcf->name; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2428 |
1353 | 2429 if (clcf->named |
507 | 2430 #if (NGX_PCRE) |
1353 | 2431 || clcf->regex |
2432 #endif | |
2433 || clcf->noname) | |
2434 { | |
1658 | 2435 if (plcf->vars.uri.len) { |
573 | 2436 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2437 "\"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
|
2438 "location given by regular expression, " |
1353 | 2439 "or inside named location, " |
843
ebab9490204c
allow proxy_pass inside limit_except
Igor Sysoev <igor@sysoev.ru>
parents:
812
diff
changeset
|
2440 "or inside the \"if\" statement, " |
ebab9490204c
allow proxy_pass inside limit_except
Igor Sysoev <igor@sysoev.ru>
parents:
812
diff
changeset
|
2441 "or inside the \"limit_except\" block"); |
573 | 2442 return NGX_CONF_ERROR; |
2443 } | |
2444 | |
1658 | 2445 plcf->location.len = 0; |
555 | 2446 } |
2447 | |
1658 | 2448 plcf->url = *url; |
509 | 2449 |
507 | 2450 return NGX_CONF_OK; |
2451 } | |
2452 | |
2453 | |
2454 static char * | |
509 | 2455 ngx_http_proxy_redirect(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
507 | 2456 { |
509 | 2457 ngx_http_proxy_loc_conf_t *plcf = conf; |
2458 | |
2459 ngx_str_t *value; | |
2460 ngx_array_t *vars_lengths, *vars_values; | |
2461 ngx_http_script_compile_t sc; | |
2462 ngx_http_proxy_redirect_t *pr; | |
2463 | |
2464 if (plcf->redirect == 0) { | |
2465 return NGX_CONF_OK; | |
2466 } | |
2467 | |
2468 value = cf->args->elts; | |
2469 | |
2784
c2230102df6f
*) check a proxy_redirect single parameter
Igor Sysoev <igor@sysoev.ru>
parents:
2753
diff
changeset
|
2470 if (cf->args->nelts == 2) { |
c2230102df6f
*) check a proxy_redirect single parameter
Igor Sysoev <igor@sysoev.ru>
parents:
2753
diff
changeset
|
2471 if (ngx_strcmp(value[1].data, "off") == 0) { |
c2230102df6f
*) check a proxy_redirect single parameter
Igor Sysoev <igor@sysoev.ru>
parents:
2753
diff
changeset
|
2472 plcf->redirect = 0; |
c2230102df6f
*) check a proxy_redirect single parameter
Igor Sysoev <igor@sysoev.ru>
parents:
2753
diff
changeset
|
2473 plcf->redirects = NULL; |
c2230102df6f
*) check a proxy_redirect single parameter
Igor Sysoev <igor@sysoev.ru>
parents:
2753
diff
changeset
|
2474 return NGX_CONF_OK; |
c2230102df6f
*) check a proxy_redirect single parameter
Igor Sysoev <igor@sysoev.ru>
parents:
2753
diff
changeset
|
2475 } |
c2230102df6f
*) check a proxy_redirect single parameter
Igor Sysoev <igor@sysoev.ru>
parents:
2753
diff
changeset
|
2476 |
c2230102df6f
*) check a proxy_redirect single parameter
Igor Sysoev <igor@sysoev.ru>
parents:
2753
diff
changeset
|
2477 if (ngx_strcmp(value[1].data, "false") == 0) { |
c2230102df6f
*) check a proxy_redirect single parameter
Igor Sysoev <igor@sysoev.ru>
parents:
2753
diff
changeset
|
2478 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
|
2479 "invalid parameter \"false\", use \"off\" instead"); |
c2230102df6f
*) check a proxy_redirect single parameter
Igor Sysoev <igor@sysoev.ru>
parents:
2753
diff
changeset
|
2480 plcf->redirect = 0; |
c2230102df6f
*) check a proxy_redirect single parameter
Igor Sysoev <igor@sysoev.ru>
parents:
2753
diff
changeset
|
2481 plcf->redirects = NULL; |
c2230102df6f
*) check a proxy_redirect single parameter
Igor Sysoev <igor@sysoev.ru>
parents:
2753
diff
changeset
|
2482 return NGX_CONF_OK; |
c2230102df6f
*) check a proxy_redirect single parameter
Igor Sysoev <igor@sysoev.ru>
parents:
2753
diff
changeset
|
2483 } |
c2230102df6f
*) check a proxy_redirect single parameter
Igor Sysoev <igor@sysoev.ru>
parents:
2753
diff
changeset
|
2484 |
c2230102df6f
*) check a proxy_redirect single parameter
Igor Sysoev <igor@sysoev.ru>
parents:
2753
diff
changeset
|
2485 if (ngx_strcmp(value[1].data, "default") != 0) { |
c2230102df6f
*) check a proxy_redirect single parameter
Igor Sysoev <igor@sysoev.ru>
parents:
2753
diff
changeset
|
2486 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
|
2487 "invalid parameter \"%V\"", &value[1]); |
c2230102df6f
*) check a proxy_redirect single parameter
Igor Sysoev <igor@sysoev.ru>
parents:
2753
diff
changeset
|
2488 return NGX_CONF_ERROR; |
c2230102df6f
*) check a proxy_redirect single parameter
Igor Sysoev <igor@sysoev.ru>
parents:
2753
diff
changeset
|
2489 } |
509 | 2490 } |
2491 | |
2492 if (plcf->redirects == NULL) { | |
2493 plcf->redirects = ngx_array_create(cf->pool, 1, | |
2494 sizeof(ngx_http_proxy_redirect_t)); | |
2495 if (plcf->redirects == NULL) { | |
2496 return NGX_CONF_ERROR; | |
2497 } | |
2498 } | |
2499 | |
2500 pr = ngx_array_push(plcf->redirects); | |
2501 if (pr == NULL) { | |
2502 return NGX_CONF_ERROR; | |
2503 } | |
2504 | |
2784
c2230102df6f
*) check a proxy_redirect single parameter
Igor Sysoev <igor@sysoev.ru>
parents:
2753
diff
changeset
|
2505 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
|
2506 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
|
2507 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
|
2508 "\"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
|
2509 "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
|
2510 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
|
2511 } |
d8c56e7851b8
"proxy_redirect default" may not be used if a proxy_pass uses variables
Igor Sysoev <igor@sysoev.ru>
parents:
3470
diff
changeset
|
2512 |
1658 | 2513 if (plcf->url.data == NULL) { |
509 | 2514 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
|
2515 "\"proxy_redirect default\" must go " |
509 | 2516 "after the \"proxy_pass\" directive"); |
2517 return NGX_CONF_ERROR; | |
2518 } | |
2519 | |
2520 pr->handler = ngx_http_proxy_rewrite_redirect_text; | |
1658 | 2521 pr->redirect = plcf->url; |
2522 | |
2523 if (plcf->vars.uri.len) { | |
2524 pr->replacement.text = plcf->location; | |
653 | 2525 |
2526 } else { | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3477
diff
changeset
|
2527 ngx_str_null(&pr->replacement.text); |
653 | 2528 } |
509 | 2529 |
2530 return NGX_CONF_OK; | |
2531 } | |
2532 | |
2533 if (ngx_http_script_variables_count(&value[2]) == 0) { | |
2534 pr->handler = ngx_http_proxy_rewrite_redirect_text; | |
2535 pr->redirect = value[1]; | |
2536 pr->replacement.text = value[2]; | |
2537 | |
2538 return NGX_CONF_OK; | |
2539 } | |
2540 | |
2541 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
2542 | |
2543 vars_lengths = NULL; | |
2544 vars_values = NULL; | |
2545 | |
2546 sc.cf = cf; | |
2547 sc.source = &value[2]; | |
2548 sc.lengths = &vars_lengths; | |
2549 sc.values = &vars_values; | |
2550 sc.complete_lengths = 1; | |
2551 sc.complete_values = 1; | |
2552 | |
2553 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
2554 return NGX_CONF_ERROR; | |
2555 } | |
2556 | |
2557 pr->handler = ngx_http_proxy_rewrite_redirect_vars; | |
2558 pr->redirect = value[1]; | |
2559 pr->replacement.vars.lengths = vars_lengths->elts; | |
2560 pr->replacement.vars.values = vars_values->elts; | |
2561 | |
507 | 2562 return NGX_CONF_OK; |
2563 } | |
2564 | |
2565 | |
2566 static char * | |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2567 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
|
2568 { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2569 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
|
2570 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2571 ngx_str_t *value; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2572 ngx_http_script_compile_t sc; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2573 |
2894 | 2574 if (plcf->upstream.store != NGX_CONF_UNSET |
2575 || plcf->upstream.store_lengths) | |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2576 { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2577 return "is duplicate"; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2578 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2579 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2580 value = cf->args->elts; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2581 |
2895
d65e58a8d3a4
report about proxy/fastcgi_store and proxy/fastcgi_cache incompatibility
Igor Sysoev <igor@sysoev.ru>
parents:
2894
diff
changeset
|
2582 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
|
2583 plcf->upstream.store = 0; |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2584 return NGX_CONF_OK; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2585 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2586 |
2895
d65e58a8d3a4
report about proxy/fastcgi_store and proxy/fastcgi_cache incompatibility
Igor Sysoev <igor@sysoev.ru>
parents:
2894
diff
changeset
|
2587 #if (NGX_HTTP_CACHE) |
d65e58a8d3a4
report about proxy/fastcgi_store and proxy/fastcgi_cache incompatibility
Igor Sysoev <igor@sysoev.ru>
parents:
2894
diff
changeset
|
2588 |
d65e58a8d3a4
report about proxy/fastcgi_store and proxy/fastcgi_cache incompatibility
Igor Sysoev <igor@sysoev.ru>
parents:
2894
diff
changeset
|
2589 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
|
2590 && plcf->upstream.cache != NULL) |
d65e58a8d3a4
report about proxy/fastcgi_store and proxy/fastcgi_cache incompatibility
Igor Sysoev <igor@sysoev.ru>
parents:
2894
diff
changeset
|
2591 { |
d65e58a8d3a4
report about proxy/fastcgi_store and proxy/fastcgi_cache incompatibility
Igor Sysoev <igor@sysoev.ru>
parents:
2894
diff
changeset
|
2592 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
|
2593 } |
d65e58a8d3a4
report about proxy/fastcgi_store and proxy/fastcgi_cache incompatibility
Igor Sysoev <igor@sysoev.ru>
parents:
2894
diff
changeset
|
2594 |
d65e58a8d3a4
report about proxy/fastcgi_store and proxy/fastcgi_cache incompatibility
Igor Sysoev <igor@sysoev.ru>
parents:
2894
diff
changeset
|
2595 #endif |
d65e58a8d3a4
report about proxy/fastcgi_store and proxy/fastcgi_cache incompatibility
Igor Sysoev <igor@sysoev.ru>
parents:
2894
diff
changeset
|
2596 |
d65e58a8d3a4
report about proxy/fastcgi_store and proxy/fastcgi_cache incompatibility
Igor Sysoev <igor@sysoev.ru>
parents:
2894
diff
changeset
|
2597 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
|
2598 plcf->upstream.store = 1; |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2599 return NGX_CONF_OK; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2600 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2601 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2602 /* include the terminating '\0' into script */ |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2603 value[1].len++; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2604 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2605 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
|
2606 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2607 sc.cf = cf; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2608 sc.source = &value[1]; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2609 sc.lengths = &plcf->upstream.store_lengths; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2610 sc.values = &plcf->upstream.store_values; |
1563
022ec9420f80
style fix: remove double semicolons
Igor Sysoev <igor@sysoev.ru>
parents:
1488
diff
changeset
|
2611 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
|
2612 sc.complete_lengths = 1; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2613 sc.complete_values = 1; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2614 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2615 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
|
2616 return NGX_CONF_ERROR; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2617 } |
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 NGX_CONF_OK; |
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 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2623 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2624 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2625 static char * |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2626 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
|
2627 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2628 ngx_http_proxy_loc_conf_t *plcf = conf; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2629 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2630 ngx_str_t *value; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2631 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2632 value = cf->args->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2633 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2634 if (plcf->upstream.cache != NGX_CONF_UNSET_PTR) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2635 return "is duplicate"; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2636 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2637 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2638 if (ngx_strcmp(value[1].data, "off") == 0) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2639 plcf->upstream.cache = NULL; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2640 return NGX_CONF_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2641 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2642 |
2895
d65e58a8d3a4
report about proxy/fastcgi_store and proxy/fastcgi_cache incompatibility
Igor Sysoev <igor@sysoev.ru>
parents:
2894
diff
changeset
|
2643 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
|
2644 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
|
2645 } |
d65e58a8d3a4
report about proxy/fastcgi_store and proxy/fastcgi_cache incompatibility
Igor Sysoev <igor@sysoev.ru>
parents:
2894
diff
changeset
|
2646 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2647 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
|
2648 &ngx_http_proxy_module); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2649 if (plcf->upstream.cache == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2650 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2651 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2652 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2653 return NGX_CONF_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2654 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2655 |
2672 | 2656 |
2657 static char * | |
2658 ngx_http_proxy_cache_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
2659 { | |
2660 ngx_http_proxy_loc_conf_t *plcf = conf; | |
2661 | |
2662 ngx_str_t *value; | |
2663 ngx_http_compile_complex_value_t ccv; | |
2664 | |
2665 value = cf->args->elts; | |
2666 | |
2667 if (plcf->cache_key.value.len) { | |
2668 return "is duplicate"; | |
2669 } | |
2670 | |
2671 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); | |
2672 | |
2673 ccv.cf = cf; | |
2674 ccv.value = &value[1]; | |
2675 ccv.complex_value = &plcf->cache_key; | |
2676 | |
2677 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { | |
2678 return NGX_CONF_ERROR; | |
2679 } | |
2680 | |
2681 return NGX_CONF_OK; | |
2682 } | |
2683 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2684 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2685 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2686 |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2687 static char * |
507 | 2688 ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data) |
2689 { | |
2690 #if (NGX_FREEBSD) | |
2691 ssize_t *np = data; | |
2692 | |
673 | 2693 if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) { |
507 | 2694 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2695 "\"proxy_send_lowat\" must be less than %d " | |
2696 "(sysctl net.inet.tcp.sendspace)", | |
2697 ngx_freebsd_net_inet_tcp_sendspace); | |
2698 | |
2699 return NGX_CONF_ERROR; | |
2700 } | |
2701 | |
2702 #elif !(NGX_HAVE_SO_SNDLOWAT) | |
2703 ssize_t *np = data; | |
2704 | |
2705 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | |
2706 "\"proxy_send_lowat\" is not supported, ignored"); | |
2707 | |
2708 *np = 0; | |
2709 | |
2710 #endif | |
2711 | |
2712 return NGX_CONF_OK; | |
2713 } | |
884 | 2714 |
2715 | |
1658 | 2716 #if (NGX_HTTP_SSL) |
2717 | |
2718 static ngx_int_t | |
2719 ngx_http_proxy_set_ssl(ngx_conf_t *cf, ngx_http_proxy_loc_conf_t *plcf) | |
2720 { | |
2721 ngx_pool_cleanup_t *cln; | |
2722 | |
2723 plcf->upstream.ssl = ngx_pcalloc(cf->pool, sizeof(ngx_ssl_t)); | |
2724 if (plcf->upstream.ssl == NULL) { | |
2725 return NGX_ERROR; | |
2726 } | |
2727 | |
2728 plcf->upstream.ssl->log = cf->log; | |
2729 | |
2730 if (ngx_ssl_create(plcf->upstream.ssl, | |
2731 NGX_SSL_SSLv2|NGX_SSL_SSLv3|NGX_SSL_TLSv1, NULL) | |
2732 != NGX_OK) | |
2733 { | |
2734 return NGX_ERROR; | |
2735 } | |
2736 | |
2737 cln = ngx_pool_cleanup_add(cf->pool, 0); | |
2738 if (cln == NULL) { | |
2739 return NGX_ERROR; | |
2740 } | |
2741 | |
2742 cln->handler = ngx_ssl_cleanup_ctx; | |
2743 cln->data = plcf->upstream.ssl; | |
2744 | |
2745 return NGX_OK; | |
2746 } | |
2747 | |
2748 #endif | |
2749 | |
2750 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2751 static void |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2752 ngx_http_proxy_set_vars(ngx_url_t *u, ngx_http_proxy_vars_t *v) |
1658 | 2753 { |
2203
8e5bf1bc87e2
*) refactor ngx_parse_inet_url()
Igor Sysoev <igor@sysoev.ru>
parents:
2184
diff
changeset
|
2754 if (u->family != AF_UNIX) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2755 |
1658 | 2756 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
|
2757 |
1658 | 2758 v->host_header = u->host; |
2759 | |
2760 if (u->default_port == 80) { | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3477
diff
changeset
|
2761 ngx_str_set(&v->port, "80"); |
1658 | 2762 |
2763 } else { | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3477
diff
changeset
|
2764 ngx_str_set(&v->port, "443"); |
1658 | 2765 } |
2766 | |
2767 } 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
|
2768 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
|
2769 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
|
2770 v->port = u->port_text; |
1658 | 2771 } |
2772 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2773 v->key_start.len += v->host_header.len; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2774 |
1658 | 2775 } else { |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3477
diff
changeset
|
2776 ngx_str_set(&v->host_header, "localhost"); |
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3477
diff
changeset
|
2777 ngx_str_null(&v->port); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2430
diff
changeset
|
2778 v->key_start.len += sizeof("unix:") - 1 + u->host.len + 1; |
1658 | 2779 } |
2780 | |
2781 v->uri = u->uri; | |
2782 } |