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