Mercurial > hg > nginx-quic
annotate src/stream/ngx_stream_proxy_module.c @ 6376:0e0e2e522fa2
HTTP/2: fixed padding handling in HEADERS frame with CONTINUATION.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Tue, 02 Feb 2016 16:33:55 +0300 |
parents | 4b4aee40c508 |
children | 4eb1b5c6d9c6 |
rev | line source |
---|---|
6115 | 1 |
2 /* | |
3 * Copyright (C) Roman Arutyunyan | |
4 * Copyright (C) Nginx, Inc. | |
5 */ | |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_stream.h> | |
11 | |
12 | |
13 typedef void (*ngx_stream_proxy_handler_pt)(ngx_stream_session_t *s); | |
14 | |
15 | |
16 typedef struct { | |
17 ngx_msec_t connect_timeout; | |
18 ngx_msec_t timeout; | |
19 ngx_msec_t next_upstream_timeout; | |
6215
8ee6a08ea3eb
Stream: added proxy_buffer_size to set the size of data buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
6208
diff
changeset
|
20 size_t buffer_size; |
6208
7a14a0d754ad
Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents:
6204
diff
changeset
|
21 size_t upload_rate; |
7a14a0d754ad
Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents:
6204
diff
changeset
|
22 size_t download_rate; |
6115 | 23 ngx_uint_t next_upstream_tries; |
24 ngx_flag_t next_upstream; | |
6184
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
25 ngx_flag_t proxy_protocol; |
6183
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
26 ngx_addr_t *local; |
6115 | 27 |
28 #if (NGX_STREAM_SSL) | |
29 ngx_flag_t ssl_enable; | |
30 ngx_flag_t ssl_session_reuse; | |
31 ngx_uint_t ssl_protocols; | |
32 ngx_str_t ssl_ciphers; | |
33 ngx_str_t ssl_name; | |
34 ngx_flag_t ssl_server_name; | |
35 | |
36 ngx_flag_t ssl_verify; | |
37 ngx_uint_t ssl_verify_depth; | |
38 ngx_str_t ssl_trusted_certificate; | |
39 ngx_str_t ssl_crl; | |
40 ngx_str_t ssl_certificate; | |
41 ngx_str_t ssl_certificate_key; | |
42 ngx_array_t *ssl_passwords; | |
43 | |
44 ngx_ssl_t *ssl; | |
45 #endif | |
46 | |
47 ngx_stream_upstream_srv_conf_t *upstream; | |
48 } ngx_stream_proxy_srv_conf_t; | |
49 | |
50 | |
51 static void ngx_stream_proxy_handler(ngx_stream_session_t *s); | |
52 static void ngx_stream_proxy_connect(ngx_stream_session_t *s); | |
53 static void ngx_stream_proxy_init_upstream(ngx_stream_session_t *s); | |
54 static void ngx_stream_proxy_upstream_handler(ngx_event_t *ev); | |
55 static void ngx_stream_proxy_downstream_handler(ngx_event_t *ev); | |
6200
abee77018d3a
Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents:
6184
diff
changeset
|
56 static void ngx_stream_proxy_process_connection(ngx_event_t *ev, |
abee77018d3a
Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents:
6184
diff
changeset
|
57 ngx_uint_t from_upstream); |
6115 | 58 static void ngx_stream_proxy_connect_handler(ngx_event_t *ev); |
59 static ngx_int_t ngx_stream_proxy_test_connect(ngx_connection_t *c); | |
60 static ngx_int_t ngx_stream_proxy_process(ngx_stream_session_t *s, | |
61 ngx_uint_t from_upstream, ngx_uint_t do_write); | |
62 static void ngx_stream_proxy_next_upstream(ngx_stream_session_t *s); | |
63 static void ngx_stream_proxy_finalize(ngx_stream_session_t *s, ngx_int_t rc); | |
64 static u_char *ngx_stream_proxy_log_error(ngx_log_t *log, u_char *buf, | |
65 size_t len); | |
66 | |
67 static void *ngx_stream_proxy_create_srv_conf(ngx_conf_t *cf); | |
68 static char *ngx_stream_proxy_merge_srv_conf(ngx_conf_t *cf, void *parent, | |
69 void *child); | |
70 static char *ngx_stream_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, | |
71 void *conf); | |
6183
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
72 static char *ngx_stream_proxy_bind(ngx_conf_t *cf, ngx_command_t *cmd, |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
73 void *conf); |
6184
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
74 static ngx_int_t ngx_stream_proxy_send_proxy_protocol(ngx_stream_session_t *s); |
6115 | 75 |
76 #if (NGX_STREAM_SSL) | |
77 | |
78 static char *ngx_stream_proxy_ssl_password_file(ngx_conf_t *cf, | |
79 ngx_command_t *cmd, void *conf); | |
80 static void ngx_stream_proxy_ssl_init_connection(ngx_stream_session_t *s); | |
81 static void ngx_stream_proxy_ssl_handshake(ngx_connection_t *pc); | |
82 static ngx_int_t ngx_stream_proxy_ssl_name(ngx_stream_session_t *s); | |
83 static ngx_int_t ngx_stream_proxy_set_ssl(ngx_conf_t *cf, | |
84 ngx_stream_proxy_srv_conf_t *pscf); | |
85 | |
86 | |
87 static ngx_conf_bitmask_t ngx_stream_proxy_ssl_protocols[] = { | |
88 { ngx_string("SSLv2"), NGX_SSL_SSLv2 }, | |
89 { ngx_string("SSLv3"), NGX_SSL_SSLv3 }, | |
90 { ngx_string("TLSv1"), NGX_SSL_TLSv1 }, | |
91 { ngx_string("TLSv1.1"), NGX_SSL_TLSv1_1 }, | |
92 { ngx_string("TLSv1.2"), NGX_SSL_TLSv1_2 }, | |
93 { ngx_null_string, 0 } | |
94 }; | |
95 | |
96 #endif | |
97 | |
98 | |
6217
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
99 static ngx_conf_deprecated_t ngx_conf_deprecated_proxy_downstream_buffer = { |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
100 ngx_conf_deprecated, "proxy_downstream_buffer", "proxy_buffer_size" |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
101 }; |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
102 |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
103 static ngx_conf_deprecated_t ngx_conf_deprecated_proxy_upstream_buffer = { |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
104 ngx_conf_deprecated, "proxy_upstream_buffer", "proxy_buffer_size" |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
105 }; |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
106 |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
107 |
6115 | 108 static ngx_command_t ngx_stream_proxy_commands[] = { |
109 | |
110 { ngx_string("proxy_pass"), | |
111 NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | |
112 ngx_stream_proxy_pass, | |
113 NGX_STREAM_SRV_CONF_OFFSET, | |
114 0, | |
115 NULL }, | |
116 | |
6183
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
117 { ngx_string("proxy_bind"), |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
118 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
119 ngx_stream_proxy_bind, |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
120 NGX_STREAM_SRV_CONF_OFFSET, |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
121 0, |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
122 NULL }, |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
123 |
6115 | 124 { ngx_string("proxy_connect_timeout"), |
125 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | |
126 ngx_conf_set_msec_slot, | |
127 NGX_STREAM_SRV_CONF_OFFSET, | |
128 offsetof(ngx_stream_proxy_srv_conf_t, connect_timeout), | |
129 NULL }, | |
130 | |
131 { ngx_string("proxy_timeout"), | |
132 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | |
133 ngx_conf_set_msec_slot, | |
134 NGX_STREAM_SRV_CONF_OFFSET, | |
135 offsetof(ngx_stream_proxy_srv_conf_t, timeout), | |
136 NULL }, | |
137 | |
6215
8ee6a08ea3eb
Stream: added proxy_buffer_size to set the size of data buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
6208
diff
changeset
|
138 { ngx_string("proxy_buffer_size"), |
6115 | 139 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, |
140 ngx_conf_set_size_slot, | |
141 NGX_STREAM_SRV_CONF_OFFSET, | |
6215
8ee6a08ea3eb
Stream: added proxy_buffer_size to set the size of data buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
6208
diff
changeset
|
142 offsetof(ngx_stream_proxy_srv_conf_t, buffer_size), |
6115 | 143 NULL }, |
144 | |
6217
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
145 { ngx_string("proxy_downstream_buffer"), |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
146 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
147 ngx_conf_set_size_slot, |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
148 NGX_STREAM_SRV_CONF_OFFSET, |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
149 offsetof(ngx_stream_proxy_srv_conf_t, buffer_size), |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
150 &ngx_conf_deprecated_proxy_downstream_buffer }, |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
151 |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
152 { ngx_string("proxy_upstream_buffer"), |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
153 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
154 ngx_conf_set_size_slot, |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
155 NGX_STREAM_SRV_CONF_OFFSET, |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
156 offsetof(ngx_stream_proxy_srv_conf_t, buffer_size), |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
157 &ngx_conf_deprecated_proxy_upstream_buffer }, |
b544f8e0d921
Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
6216
diff
changeset
|
158 |
6208
7a14a0d754ad
Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents:
6204
diff
changeset
|
159 { ngx_string("proxy_upload_rate"), |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
160 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
161 ngx_conf_set_size_slot, |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
162 NGX_STREAM_SRV_CONF_OFFSET, |
6208
7a14a0d754ad
Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents:
6204
diff
changeset
|
163 offsetof(ngx_stream_proxy_srv_conf_t, upload_rate), |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
164 NULL }, |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
165 |
6208
7a14a0d754ad
Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents:
6204
diff
changeset
|
166 { ngx_string("proxy_download_rate"), |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
167 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
168 ngx_conf_set_size_slot, |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
169 NGX_STREAM_SRV_CONF_OFFSET, |
6208
7a14a0d754ad
Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents:
6204
diff
changeset
|
170 offsetof(ngx_stream_proxy_srv_conf_t, download_rate), |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
171 NULL }, |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
172 |
6115 | 173 { ngx_string("proxy_next_upstream"), |
174 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, | |
175 ngx_conf_set_flag_slot, | |
176 NGX_STREAM_SRV_CONF_OFFSET, | |
177 offsetof(ngx_stream_proxy_srv_conf_t, next_upstream), | |
178 NULL }, | |
179 | |
180 { ngx_string("proxy_next_upstream_tries"), | |
181 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | |
182 ngx_conf_set_num_slot, | |
183 NGX_STREAM_SRV_CONF_OFFSET, | |
184 offsetof(ngx_stream_proxy_srv_conf_t, next_upstream_tries), | |
185 NULL }, | |
186 | |
187 { ngx_string("proxy_next_upstream_timeout"), | |
188 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | |
189 ngx_conf_set_msec_slot, | |
190 NGX_STREAM_SRV_CONF_OFFSET, | |
191 offsetof(ngx_stream_proxy_srv_conf_t, next_upstream_timeout), | |
192 NULL }, | |
193 | |
6184
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
194 { ngx_string("proxy_protocol"), |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
195 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
196 ngx_conf_set_flag_slot, |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
197 NGX_STREAM_SRV_CONF_OFFSET, |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
198 offsetof(ngx_stream_proxy_srv_conf_t, proxy_protocol), |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
199 NULL }, |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
200 |
6115 | 201 #if (NGX_STREAM_SSL) |
202 | |
203 { ngx_string("proxy_ssl"), | |
204 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, | |
205 ngx_conf_set_flag_slot, | |
206 NGX_STREAM_SRV_CONF_OFFSET, | |
207 offsetof(ngx_stream_proxy_srv_conf_t, ssl_enable), | |
208 NULL }, | |
209 | |
210 { ngx_string("proxy_ssl_session_reuse"), | |
211 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, | |
212 ngx_conf_set_flag_slot, | |
213 NGX_STREAM_SRV_CONF_OFFSET, | |
214 offsetof(ngx_stream_proxy_srv_conf_t, ssl_session_reuse), | |
215 NULL }, | |
216 | |
217 { ngx_string("proxy_ssl_protocols"), | |
218 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_1MORE, | |
219 ngx_conf_set_bitmask_slot, | |
220 NGX_STREAM_SRV_CONF_OFFSET, | |
221 offsetof(ngx_stream_proxy_srv_conf_t, ssl_protocols), | |
222 &ngx_stream_proxy_ssl_protocols }, | |
223 | |
224 { ngx_string("proxy_ssl_ciphers"), | |
225 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | |
226 ngx_conf_set_str_slot, | |
227 NGX_STREAM_SRV_CONF_OFFSET, | |
228 offsetof(ngx_stream_proxy_srv_conf_t, ssl_ciphers), | |
229 NULL }, | |
230 | |
231 { ngx_string("proxy_ssl_name"), | |
232 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | |
233 ngx_conf_set_str_slot, | |
234 NGX_STREAM_SRV_CONF_OFFSET, | |
235 offsetof(ngx_stream_proxy_srv_conf_t, ssl_name), | |
236 NULL }, | |
237 | |
238 { ngx_string("proxy_ssl_server_name"), | |
239 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, | |
240 ngx_conf_set_flag_slot, | |
241 NGX_STREAM_SRV_CONF_OFFSET, | |
242 offsetof(ngx_stream_proxy_srv_conf_t, ssl_server_name), | |
243 NULL }, | |
244 | |
245 { ngx_string("proxy_ssl_verify"), | |
246 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, | |
247 ngx_conf_set_flag_slot, | |
248 NGX_STREAM_SRV_CONF_OFFSET, | |
249 offsetof(ngx_stream_proxy_srv_conf_t, ssl_verify), | |
250 NULL }, | |
251 | |
252 { ngx_string("proxy_ssl_verify_depth"), | |
253 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | |
254 ngx_conf_set_num_slot, | |
255 NGX_STREAM_SRV_CONF_OFFSET, | |
256 offsetof(ngx_stream_proxy_srv_conf_t, ssl_verify_depth), | |
257 NULL }, | |
258 | |
259 { ngx_string("proxy_ssl_trusted_certificate"), | |
260 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | |
261 ngx_conf_set_str_slot, | |
262 NGX_STREAM_SRV_CONF_OFFSET, | |
263 offsetof(ngx_stream_proxy_srv_conf_t, ssl_trusted_certificate), | |
264 NULL }, | |
265 | |
266 { ngx_string("proxy_ssl_crl"), | |
267 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | |
268 ngx_conf_set_str_slot, | |
269 NGX_STREAM_SRV_CONF_OFFSET, | |
270 offsetof(ngx_stream_proxy_srv_conf_t, ssl_crl), | |
271 NULL }, | |
272 | |
273 { ngx_string("proxy_ssl_certificate"), | |
274 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | |
275 ngx_conf_set_str_slot, | |
276 NGX_STREAM_SRV_CONF_OFFSET, | |
277 offsetof(ngx_stream_proxy_srv_conf_t, ssl_certificate), | |
278 NULL }, | |
279 | |
280 { ngx_string("proxy_ssl_certificate_key"), | |
281 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | |
282 ngx_conf_set_str_slot, | |
283 NGX_STREAM_SRV_CONF_OFFSET, | |
284 offsetof(ngx_stream_proxy_srv_conf_t, ssl_certificate_key), | |
285 NULL }, | |
286 | |
287 { ngx_string("proxy_ssl_password_file"), | |
288 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | |
289 ngx_stream_proxy_ssl_password_file, | |
290 NGX_STREAM_SRV_CONF_OFFSET, | |
291 0, | |
292 NULL }, | |
293 | |
294 #endif | |
295 | |
296 ngx_null_command | |
297 }; | |
298 | |
299 | |
300 static ngx_stream_module_t ngx_stream_proxy_module_ctx = { | |
6174
68c106e6fa0a
Stream: added postconfiguration method to stream modules.
Vladimir Homutov <vl@nginx.com>
parents:
6157
diff
changeset
|
301 NULL, /* postconfiguration */ |
68c106e6fa0a
Stream: added postconfiguration method to stream modules.
Vladimir Homutov <vl@nginx.com>
parents:
6157
diff
changeset
|
302 |
6115 | 303 NULL, /* create main configuration */ |
304 NULL, /* init main configuration */ | |
305 | |
306 ngx_stream_proxy_create_srv_conf, /* create server configuration */ | |
307 ngx_stream_proxy_merge_srv_conf /* merge server configuration */ | |
308 }; | |
309 | |
310 | |
311 ngx_module_t ngx_stream_proxy_module = { | |
312 NGX_MODULE_V1, | |
313 &ngx_stream_proxy_module_ctx, /* module context */ | |
314 ngx_stream_proxy_commands, /* module directives */ | |
315 NGX_STREAM_MODULE, /* module type */ | |
316 NULL, /* init master */ | |
317 NULL, /* init module */ | |
318 NULL, /* init process */ | |
319 NULL, /* init thread */ | |
320 NULL, /* exit thread */ | |
321 NULL, /* exit process */ | |
322 NULL, /* exit master */ | |
323 NGX_MODULE_V1_PADDING | |
324 }; | |
325 | |
326 | |
327 static void | |
328 ngx_stream_proxy_handler(ngx_stream_session_t *s) | |
329 { | |
330 u_char *p; | |
331 ngx_connection_t *c; | |
332 ngx_stream_upstream_t *u; | |
333 ngx_stream_proxy_srv_conf_t *pscf; | |
334 ngx_stream_upstream_srv_conf_t *uscf; | |
335 | |
336 c = s->connection; | |
337 | |
338 pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); | |
339 | |
340 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, | |
341 "proxy connection handler"); | |
342 | |
343 u = ngx_pcalloc(c->pool, sizeof(ngx_stream_upstream_t)); | |
344 if (u == NULL) { | |
345 ngx_stream_proxy_finalize(s, NGX_ERROR); | |
346 return; | |
347 } | |
348 | |
349 s->upstream = u; | |
350 | |
351 s->log_handler = ngx_stream_proxy_log_error; | |
352 | |
353 u->peer.log = c->log; | |
354 u->peer.log_error = NGX_ERROR_ERR; | |
355 | |
6183
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
356 u->peer.local = pscf->local; |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
357 |
6115 | 358 uscf = pscf->upstream; |
359 | |
360 if (uscf->peer.init(s, uscf) != NGX_OK) { | |
361 ngx_stream_proxy_finalize(s, NGX_ERROR); | |
362 return; | |
363 } | |
364 | |
365 u->peer.start_time = ngx_current_msec; | |
366 | |
367 if (pscf->next_upstream_tries | |
368 && u->peer.tries > pscf->next_upstream_tries) | |
369 { | |
370 u->peer.tries = pscf->next_upstream_tries; | |
371 } | |
372 | |
6184
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
373 u->proxy_protocol = pscf->proxy_protocol; |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
374 u->start_sec = ngx_time(); |
6184
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
375 |
6215
8ee6a08ea3eb
Stream: added proxy_buffer_size to set the size of data buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
6208
diff
changeset
|
376 p = ngx_pnalloc(c->pool, pscf->buffer_size); |
6115 | 377 if (p == NULL) { |
378 ngx_stream_proxy_finalize(s, NGX_ERROR); | |
379 return; | |
380 } | |
381 | |
382 u->downstream_buf.start = p; | |
6215
8ee6a08ea3eb
Stream: added proxy_buffer_size to set the size of data buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
6208
diff
changeset
|
383 u->downstream_buf.end = p + pscf->buffer_size; |
6115 | 384 u->downstream_buf.pos = p; |
385 u->downstream_buf.last = p; | |
386 | |
387 c->write->handler = ngx_stream_proxy_downstream_handler; | |
388 c->read->handler = ngx_stream_proxy_downstream_handler; | |
389 | |
6184
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
390 if (u->proxy_protocol |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
391 #if (NGX_STREAM_SSL) |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
392 && pscf->ssl == NULL |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
393 #endif |
6216 | 394 && pscf->buffer_size >= NGX_PROXY_PROTOCOL_MAX_HEADER) |
6184
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
395 { |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
396 /* optimization for a typical case */ |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
397 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
398 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
399 "stream proxy send PROXY protocol header"); |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
400 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
401 p = ngx_proxy_protocol_write(c, u->downstream_buf.last, |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
402 u->downstream_buf.end); |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
403 if (p == NULL) { |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
404 ngx_stream_proxy_finalize(s, NGX_ERROR); |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
405 return; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
406 } |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
407 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
408 u->downstream_buf.last = p; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
409 u->proxy_protocol = 0; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
410 } |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
411 |
6115 | 412 if (ngx_stream_proxy_process(s, 0, 0) != NGX_OK) { |
413 return; | |
414 } | |
415 | |
416 ngx_stream_proxy_connect(s); | |
417 } | |
418 | |
419 | |
420 static void | |
421 ngx_stream_proxy_connect(ngx_stream_session_t *s) | |
422 { | |
423 ngx_int_t rc; | |
424 ngx_connection_t *c, *pc; | |
425 ngx_stream_upstream_t *u; | |
426 ngx_stream_proxy_srv_conf_t *pscf; | |
427 | |
428 c = s->connection; | |
429 | |
430 c->log->action = "connecting to upstream"; | |
431 | |
432 u = s->upstream; | |
433 | |
434 rc = ngx_event_connect_peer(&u->peer); | |
435 | |
436 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, "proxy connect: %i", rc); | |
437 | |
438 pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); | |
439 | |
440 if (rc == NGX_ERROR) { | |
441 ngx_stream_proxy_finalize(s, NGX_ERROR); | |
442 return; | |
443 } | |
444 | |
445 if (rc == NGX_BUSY) { | |
446 ngx_log_error(NGX_LOG_ERR, c->log, 0, "no live upstreams"); | |
447 ngx_stream_proxy_finalize(s, NGX_DECLINED); | |
448 return; | |
449 } | |
450 | |
451 if (rc == NGX_DECLINED) { | |
452 ngx_stream_proxy_next_upstream(s); | |
453 return; | |
454 } | |
455 | |
456 /* rc == NGX_OK || rc == NGX_AGAIN || rc == NGX_DONE */ | |
457 | |
458 pc = u->peer.connection; | |
459 | |
460 pc->data = s; | |
461 pc->log = c->log; | |
462 pc->pool = c->pool; | |
463 pc->read->log = c->log; | |
464 pc->write->log = c->log; | |
465 | |
466 if (rc != NGX_AGAIN) { | |
467 ngx_stream_proxy_init_upstream(s); | |
468 return; | |
469 } | |
470 | |
471 pc->read->handler = ngx_stream_proxy_connect_handler; | |
472 pc->write->handler = ngx_stream_proxy_connect_handler; | |
473 | |
474 ngx_add_timer(pc->write, pscf->connect_timeout); | |
475 } | |
476 | |
477 | |
478 static void | |
479 ngx_stream_proxy_init_upstream(ngx_stream_session_t *s) | |
480 { | |
6222 | 481 int tcp_nodelay; |
6115 | 482 u_char *p; |
483 ngx_connection_t *c, *pc; | |
484 ngx_log_handler_pt handler; | |
485 ngx_stream_upstream_t *u; | |
6221
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
486 ngx_stream_core_srv_conf_t *cscf; |
6115 | 487 ngx_stream_proxy_srv_conf_t *pscf; |
488 | |
6184
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
489 u = s->upstream; |
6221
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
490 pc = u->peer.connection; |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
491 |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
492 cscf = ngx_stream_get_module_srv_conf(s, ngx_stream_core_module); |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
493 |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
494 if (cscf->tcp_nodelay && pc->tcp_nodelay == NGX_TCP_NODELAY_UNSET) { |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
495 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, pc->log, 0, "tcp_nodelay"); |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
496 |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
497 tcp_nodelay = 1; |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
498 |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
499 if (setsockopt(pc->fd, IPPROTO_TCP, TCP_NODELAY, |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
500 (const void *) &tcp_nodelay, sizeof(int)) == -1) |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
501 { |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
502 ngx_connection_error(pc, ngx_socket_errno, |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
503 "setsockopt(TCP_NODELAY) failed"); |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
504 ngx_stream_proxy_next_upstream(s); |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
505 return; |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
506 } |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
507 |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
508 pc->tcp_nodelay = NGX_TCP_NODELAY_SET; |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6217
diff
changeset
|
509 } |
6115 | 510 |
6184
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
511 if (u->proxy_protocol) { |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
512 if (ngx_stream_proxy_send_proxy_protocol(s) != NGX_OK) { |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
513 return; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
514 } |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
515 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
516 u->proxy_protocol = 0; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
517 } |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
518 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
519 pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); |
6115 | 520 |
521 #if (NGX_STREAM_SSL) | |
522 if (pscf->ssl && pc->ssl == NULL) { | |
523 ngx_stream_proxy_ssl_init_connection(s); | |
524 return; | |
525 } | |
526 #endif | |
527 | |
528 c = s->connection; | |
529 | |
530 if (c->log->log_level >= NGX_LOG_INFO) { | |
6230
2a621245f4cf
Win32: MSVC 2015 compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6222
diff
changeset
|
531 ngx_str_t str; |
6115 | 532 u_char addr[NGX_SOCKADDR_STRLEN]; |
533 | |
6230
2a621245f4cf
Win32: MSVC 2015 compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6222
diff
changeset
|
534 str.len = NGX_SOCKADDR_STRLEN; |
2a621245f4cf
Win32: MSVC 2015 compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6222
diff
changeset
|
535 str.data = addr; |
6115 | 536 |
6230
2a621245f4cf
Win32: MSVC 2015 compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6222
diff
changeset
|
537 if (ngx_connection_local_sockaddr(pc, &str, 1) == NGX_OK) { |
6115 | 538 handler = c->log->handler; |
539 c->log->handler = NULL; | |
540 | |
541 ngx_log_error(NGX_LOG_INFO, c->log, 0, "proxy %V connected to %V", | |
6230
2a621245f4cf
Win32: MSVC 2015 compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6222
diff
changeset
|
542 &str, u->peer.name); |
6115 | 543 |
544 c->log->handler = handler; | |
545 } | |
546 } | |
547 | |
548 c->log->action = "proxying connection"; | |
549 | |
6215
8ee6a08ea3eb
Stream: added proxy_buffer_size to set the size of data buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
6208
diff
changeset
|
550 p = ngx_pnalloc(c->pool, pscf->buffer_size); |
6115 | 551 if (p == NULL) { |
552 ngx_stream_proxy_finalize(s, NGX_ERROR); | |
553 return; | |
554 } | |
555 | |
556 u->upstream_buf.start = p; | |
6215
8ee6a08ea3eb
Stream: added proxy_buffer_size to set the size of data buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
6208
diff
changeset
|
557 u->upstream_buf.end = p + pscf->buffer_size; |
6115 | 558 u->upstream_buf.pos = p; |
559 u->upstream_buf.last = p; | |
560 | |
6202
6345822f0abb
Stream: upstream "connected" flag.
Roman Arutyunyan <arut@nginx.com>
parents:
6201
diff
changeset
|
561 u->connected = 1; |
6345822f0abb
Stream: upstream "connected" flag.
Roman Arutyunyan <arut@nginx.com>
parents:
6201
diff
changeset
|
562 |
6115 | 563 pc->read->handler = ngx_stream_proxy_upstream_handler; |
564 pc->write->handler = ngx_stream_proxy_upstream_handler; | |
565 | |
566 if (ngx_stream_proxy_process(s, 1, 0) != NGX_OK) { | |
567 return; | |
568 } | |
569 | |
570 ngx_stream_proxy_process(s, 0, 1); | |
571 } | |
572 | |
573 | |
6184
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
574 static ngx_int_t |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
575 ngx_stream_proxy_send_proxy_protocol(ngx_stream_session_t *s) |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
576 { |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
577 u_char *p; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
578 ssize_t n, size; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
579 ngx_connection_t *c, *pc; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
580 ngx_stream_upstream_t *u; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
581 ngx_stream_proxy_srv_conf_t *pscf; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
582 u_char buf[NGX_PROXY_PROTOCOL_MAX_HEADER]; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
583 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
584 c = s->connection; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
585 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
586 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
587 "stream proxy send PROXY protocol header"); |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
588 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
589 p = ngx_proxy_protocol_write(c, buf, buf + NGX_PROXY_PROTOCOL_MAX_HEADER); |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
590 if (p == NULL) { |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
591 ngx_stream_proxy_finalize(s, NGX_ERROR); |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
592 return NGX_ERROR; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
593 } |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
594 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
595 u = s->upstream; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
596 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
597 pc = u->peer.connection; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
598 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
599 size = p - buf; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
600 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
601 n = pc->send(pc, buf, size); |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
602 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
603 if (n == NGX_AGAIN) { |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
604 if (ngx_handle_write_event(pc->write, 0) != NGX_OK) { |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
605 ngx_stream_proxy_finalize(s, NGX_ERROR); |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
606 return NGX_ERROR; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
607 } |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
608 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
609 pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
610 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
611 ngx_add_timer(pc->write, pscf->timeout); |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
612 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
613 pc->write->handler = ngx_stream_proxy_connect_handler; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
614 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
615 return NGX_AGAIN; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
616 } |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
617 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
618 if (n == NGX_ERROR) { |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
619 ngx_stream_proxy_finalize(s, NGX_DECLINED); |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
620 return NGX_ERROR; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
621 } |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
622 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
623 if (n != size) { |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
624 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
625 /* |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
626 * PROXY protocol specification: |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
627 * The sender must always ensure that the header |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
628 * is sent at once, so that the transport layer |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
629 * maintains atomicity along the path to the receiver. |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
630 */ |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
631 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
632 ngx_log_error(NGX_LOG_ERR, c->log, 0, |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
633 "could not send PROXY protocol header at once"); |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
634 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
635 ngx_stream_proxy_finalize(s, NGX_DECLINED); |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
636 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
637 return NGX_ERROR; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
638 } |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
639 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
640 return NGX_OK; |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
641 } |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
642 |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
643 |
6115 | 644 #if (NGX_STREAM_SSL) |
645 | |
646 static char * | |
647 ngx_stream_proxy_ssl_password_file(ngx_conf_t *cf, ngx_command_t *cmd, | |
648 void *conf) | |
649 { | |
650 ngx_stream_proxy_srv_conf_t *pscf = conf; | |
651 | |
652 ngx_str_t *value; | |
653 | |
654 if (pscf->ssl_passwords != NGX_CONF_UNSET_PTR) { | |
655 return "is duplicate"; | |
656 } | |
657 | |
658 value = cf->args->elts; | |
659 | |
660 pscf->ssl_passwords = ngx_ssl_read_password_file(cf, &value[1]); | |
661 | |
662 if (pscf->ssl_passwords == NULL) { | |
663 return NGX_CONF_ERROR; | |
664 } | |
665 | |
666 return NGX_CONF_OK; | |
667 } | |
668 | |
669 | |
670 static void | |
671 ngx_stream_proxy_ssl_init_connection(ngx_stream_session_t *s) | |
672 { | |
673 ngx_int_t rc; | |
674 ngx_connection_t *pc; | |
675 ngx_stream_upstream_t *u; | |
676 ngx_stream_proxy_srv_conf_t *pscf; | |
677 | |
678 u = s->upstream; | |
679 | |
680 pc = u->peer.connection; | |
681 | |
682 pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); | |
683 | |
684 if (ngx_ssl_create_connection(pscf->ssl, pc, NGX_SSL_BUFFER|NGX_SSL_CLIENT) | |
685 != NGX_OK) | |
686 { | |
687 ngx_stream_proxy_finalize(s, NGX_ERROR); | |
688 return; | |
689 } | |
690 | |
691 if (pscf->ssl_server_name || pscf->ssl_verify) { | |
692 if (ngx_stream_proxy_ssl_name(s) != NGX_OK) { | |
693 ngx_stream_proxy_finalize(s, NGX_ERROR); | |
694 return; | |
695 } | |
696 } | |
697 | |
698 if (pscf->ssl_session_reuse) { | |
699 if (u->peer.set_session(&u->peer, u->peer.data) != NGX_OK) { | |
700 ngx_stream_proxy_finalize(s, NGX_ERROR); | |
701 return; | |
702 } | |
703 } | |
704 | |
705 s->connection->log->action = "SSL handshaking to upstream"; | |
706 | |
707 rc = ngx_ssl_handshake(pc); | |
708 | |
709 if (rc == NGX_AGAIN) { | |
710 | |
711 if (!pc->write->timer_set) { | |
712 ngx_add_timer(pc->write, pscf->connect_timeout); | |
713 } | |
714 | |
715 pc->ssl->handler = ngx_stream_proxy_ssl_handshake; | |
716 return; | |
717 } | |
718 | |
719 ngx_stream_proxy_ssl_handshake(pc); | |
720 } | |
721 | |
722 | |
723 static void | |
724 ngx_stream_proxy_ssl_handshake(ngx_connection_t *pc) | |
725 { | |
726 long rc; | |
727 ngx_stream_session_t *s; | |
728 ngx_stream_upstream_t *u; | |
729 ngx_stream_proxy_srv_conf_t *pscf; | |
730 | |
731 s = pc->data; | |
732 | |
733 pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); | |
734 | |
735 if (pc->ssl->handshaked) { | |
736 | |
737 if (pscf->ssl_verify) { | |
738 rc = SSL_get_verify_result(pc->ssl->connection); | |
739 | |
740 if (rc != X509_V_OK) { | |
741 ngx_log_error(NGX_LOG_ERR, pc->log, 0, | |
742 "upstream SSL certificate verify error: (%l:%s)", | |
743 rc, X509_verify_cert_error_string(rc)); | |
744 goto failed; | |
745 } | |
746 | |
747 u = s->upstream; | |
748 | |
749 if (ngx_ssl_check_host(pc, &u->ssl_name) != NGX_OK) { | |
750 ngx_log_error(NGX_LOG_ERR, pc->log, 0, | |
751 "upstream SSL certificate does not match \"%V\"", | |
752 &u->ssl_name); | |
753 goto failed; | |
754 } | |
755 } | |
756 | |
757 if (pscf->ssl_session_reuse) { | |
758 u = s->upstream; | |
759 u->peer.save_session(&u->peer, u->peer.data); | |
760 } | |
761 | |
6258
4b4aee40c508
Stream: delete proxy connection timer after SSL handshake.
Ruslan Ermilov <ru@nginx.com>
parents:
6230
diff
changeset
|
762 if (pc->write->timer_set) { |
4b4aee40c508
Stream: delete proxy connection timer after SSL handshake.
Ruslan Ermilov <ru@nginx.com>
parents:
6230
diff
changeset
|
763 ngx_del_timer(pc->write); |
4b4aee40c508
Stream: delete proxy connection timer after SSL handshake.
Ruslan Ermilov <ru@nginx.com>
parents:
6230
diff
changeset
|
764 } |
4b4aee40c508
Stream: delete proxy connection timer after SSL handshake.
Ruslan Ermilov <ru@nginx.com>
parents:
6230
diff
changeset
|
765 |
6115 | 766 ngx_stream_proxy_init_upstream(s); |
767 | |
768 return; | |
769 } | |
770 | |
771 failed: | |
772 | |
773 ngx_stream_proxy_next_upstream(s); | |
774 } | |
775 | |
776 | |
777 static ngx_int_t | |
778 ngx_stream_proxy_ssl_name(ngx_stream_session_t *s) | |
779 { | |
780 u_char *p, *last; | |
781 ngx_str_t name; | |
782 ngx_stream_upstream_t *u; | |
783 ngx_stream_proxy_srv_conf_t *pscf; | |
784 | |
785 pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); | |
786 | |
787 u = s->upstream; | |
788 | |
789 name = pscf->ssl_name; | |
790 | |
791 if (name.len == 0) { | |
792 name = pscf->upstream->host; | |
793 } | |
794 | |
795 if (name.len == 0) { | |
796 goto done; | |
797 } | |
798 | |
799 /* | |
800 * ssl name here may contain port, strip it for compatibility | |
801 * with the http module | |
802 */ | |
803 | |
804 p = name.data; | |
805 last = name.data + name.len; | |
806 | |
807 if (*p == '[') { | |
808 p = ngx_strlchr(p, last, ']'); | |
809 | |
810 if (p == NULL) { | |
811 p = name.data; | |
812 } | |
813 } | |
814 | |
815 p = ngx_strlchr(p, last, ':'); | |
816 | |
817 if (p != NULL) { | |
818 name.len = p - name.data; | |
819 } | |
820 | |
821 if (!pscf->ssl_server_name) { | |
822 goto done; | |
823 } | |
824 | |
825 #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME | |
826 | |
827 /* as per RFC 6066, literal IPv4 and IPv6 addresses are not permitted */ | |
828 | |
829 if (name.len == 0 || *name.data == '[') { | |
830 goto done; | |
831 } | |
832 | |
833 if (ngx_inet_addr(name.data, name.len) != INADDR_NONE) { | |
834 goto done; | |
835 } | |
836 | |
837 /* | |
838 * SSL_set_tlsext_host_name() needs a null-terminated string, | |
839 * hence we explicitly null-terminate name here | |
840 */ | |
841 | |
842 p = ngx_pnalloc(s->connection->pool, name.len + 1); | |
843 if (p == NULL) { | |
844 return NGX_ERROR; | |
845 } | |
846 | |
847 (void) ngx_cpystrn(p, name.data, name.len + 1); | |
848 | |
849 name.data = p; | |
850 | |
851 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, | |
852 "upstream SSL server name: \"%s\"", name.data); | |
853 | |
854 if (SSL_set_tlsext_host_name(u->peer.connection->ssl->connection, name.data) | |
855 == 0) | |
856 { | |
857 ngx_ssl_error(NGX_LOG_ERR, s->connection->log, 0, | |
858 "SSL_set_tlsext_host_name(\"%s\") failed", name.data); | |
859 return NGX_ERROR; | |
860 } | |
861 | |
862 #endif | |
863 | |
864 done: | |
865 | |
866 u->ssl_name = name; | |
867 | |
868 return NGX_OK; | |
869 } | |
870 | |
871 #endif | |
872 | |
873 | |
874 static void | |
875 ngx_stream_proxy_downstream_handler(ngx_event_t *ev) | |
876 { | |
6200
abee77018d3a
Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents:
6184
diff
changeset
|
877 ngx_stream_proxy_process_connection(ev, ev->write); |
abee77018d3a
Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents:
6184
diff
changeset
|
878 } |
abee77018d3a
Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents:
6184
diff
changeset
|
879 |
abee77018d3a
Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents:
6184
diff
changeset
|
880 |
abee77018d3a
Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents:
6184
diff
changeset
|
881 static void |
abee77018d3a
Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents:
6184
diff
changeset
|
882 ngx_stream_proxy_upstream_handler(ngx_event_t *ev) |
abee77018d3a
Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents:
6184
diff
changeset
|
883 { |
abee77018d3a
Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents:
6184
diff
changeset
|
884 ngx_stream_proxy_process_connection(ev, !ev->write); |
abee77018d3a
Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents:
6184
diff
changeset
|
885 } |
abee77018d3a
Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents:
6184
diff
changeset
|
886 |
abee77018d3a
Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents:
6184
diff
changeset
|
887 |
abee77018d3a
Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents:
6184
diff
changeset
|
888 static void |
abee77018d3a
Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents:
6184
diff
changeset
|
889 ngx_stream_proxy_process_connection(ngx_event_t *ev, ngx_uint_t from_upstream) |
abee77018d3a
Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents:
6184
diff
changeset
|
890 { |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
891 ngx_connection_t *c, *pc; |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
892 ngx_stream_session_t *s; |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
893 ngx_stream_upstream_t *u; |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
894 ngx_stream_proxy_srv_conf_t *pscf; |
6115 | 895 |
896 c = ev->data; | |
897 s = c->data; | |
6200
abee77018d3a
Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents:
6184
diff
changeset
|
898 u = s->upstream; |
6115 | 899 |
900 if (ev->timedout) { | |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
901 |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
902 if (ev->delayed) { |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
903 |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
904 ev->timedout = 0; |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
905 ev->delayed = 0; |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
906 |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
907 if (!ev->ready) { |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
908 if (ngx_handle_read_event(ev, 0) != NGX_OK) { |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
909 ngx_stream_proxy_finalize(s, NGX_ERROR); |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
910 return; |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
911 } |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
912 |
6202
6345822f0abb
Stream: upstream "connected" flag.
Roman Arutyunyan <arut@nginx.com>
parents:
6201
diff
changeset
|
913 if (u->connected) { |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
914 pc = u->peer.connection; |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
915 |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
916 if (!c->read->delayed && !pc->read->delayed) { |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
917 pscf = ngx_stream_get_module_srv_conf(s, |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
918 ngx_stream_proxy_module); |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
919 ngx_add_timer(c->write, pscf->timeout); |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
920 } |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
921 } |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
922 |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
923 return; |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
924 } |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
925 |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
926 } else { |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
927 ngx_connection_error(c, NGX_ETIMEDOUT, "connection timed out"); |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
928 ngx_stream_proxy_finalize(s, NGX_DECLINED); |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
929 return; |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
930 } |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
931 |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
932 } else if (ev->delayed) { |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
933 |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
934 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
935 "stream connection delayed"); |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
936 |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
937 if (ngx_handle_read_event(ev, 0) != NGX_OK) { |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
938 ngx_stream_proxy_finalize(s, NGX_ERROR); |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
939 } |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
940 |
6115 | 941 return; |
942 } | |
943 | |
6202
6345822f0abb
Stream: upstream "connected" flag.
Roman Arutyunyan <arut@nginx.com>
parents:
6201
diff
changeset
|
944 if (from_upstream && !u->connected) { |
6200
abee77018d3a
Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents:
6184
diff
changeset
|
945 return; |
6115 | 946 } |
947 | |
6200
abee77018d3a
Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents:
6184
diff
changeset
|
948 ngx_stream_proxy_process(s, from_upstream, ev->write); |
6115 | 949 } |
950 | |
951 | |
952 static void | |
953 ngx_stream_proxy_connect_handler(ngx_event_t *ev) | |
954 { | |
955 ngx_connection_t *c; | |
956 ngx_stream_session_t *s; | |
957 | |
958 c = ev->data; | |
959 s = c->data; | |
960 | |
961 if (ev->timedout) { | |
962 ngx_log_error(NGX_LOG_ERR, c->log, NGX_ETIMEDOUT, "upstream timed out"); | |
963 ngx_stream_proxy_next_upstream(s); | |
964 return; | |
965 } | |
966 | |
967 ngx_del_timer(c->write); | |
968 | |
969 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, | |
970 "stream proxy connect upstream"); | |
971 | |
972 if (ngx_stream_proxy_test_connect(c) != NGX_OK) { | |
973 ngx_stream_proxy_next_upstream(s); | |
974 return; | |
975 } | |
976 | |
977 ngx_stream_proxy_init_upstream(s); | |
978 } | |
979 | |
980 | |
981 static ngx_int_t | |
982 ngx_stream_proxy_test_connect(ngx_connection_t *c) | |
983 { | |
984 int err; | |
985 socklen_t len; | |
986 | |
987 #if (NGX_HAVE_KQUEUE) | |
988 | |
989 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { | |
990 err = c->write->kq_errno ? c->write->kq_errno : c->read->kq_errno; | |
991 | |
992 if (err) { | |
993 (void) ngx_connection_error(c, err, | |
994 "kevent() reported that connect() failed"); | |
995 return NGX_ERROR; | |
996 } | |
997 | |
998 } else | |
999 #endif | |
1000 { | |
1001 err = 0; | |
1002 len = sizeof(int); | |
1003 | |
1004 /* | |
1005 * BSDs and Linux return 0 and set a pending error in err | |
1006 * Solaris returns -1 and sets errno | |
1007 */ | |
1008 | |
1009 if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len) | |
1010 == -1) | |
1011 { | |
1012 err = ngx_socket_errno; | |
1013 } | |
1014 | |
1015 if (err) { | |
1016 (void) ngx_connection_error(c, err, "connect() failed"); | |
1017 return NGX_ERROR; | |
1018 } | |
1019 } | |
1020 | |
1021 return NGX_OK; | |
1022 } | |
1023 | |
1024 | |
1025 static ngx_int_t | |
1026 ngx_stream_proxy_process(ngx_stream_session_t *s, ngx_uint_t from_upstream, | |
1027 ngx_uint_t do_write) | |
1028 { | |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1029 off_t *received, limit; |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1030 size_t size, limit_rate; |
6115 | 1031 ssize_t n; |
1032 ngx_buf_t *b; | |
6124
f1f222db290b
Stream: prevent repeated event notifications after eof.
Roman Arutyunyan <arut@nginx.com>
parents:
6115
diff
changeset
|
1033 ngx_uint_t flags; |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1034 ngx_msec_t delay; |
6115 | 1035 ngx_connection_t *c, *pc, *src, *dst; |
1036 ngx_log_handler_pt handler; | |
1037 ngx_stream_upstream_t *u; | |
1038 ngx_stream_proxy_srv_conf_t *pscf; | |
1039 | |
1040 u = s->upstream; | |
1041 | |
1042 c = s->connection; | |
6202
6345822f0abb
Stream: upstream "connected" flag.
Roman Arutyunyan <arut@nginx.com>
parents:
6201
diff
changeset
|
1043 pc = u->connected ? u->peer.connection : NULL; |
6115 | 1044 |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1045 pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1046 |
6115 | 1047 if (from_upstream) { |
1048 src = pc; | |
1049 dst = c; | |
1050 b = &u->upstream_buf; | |
6208
7a14a0d754ad
Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents:
6204
diff
changeset
|
1051 limit_rate = pscf->download_rate; |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1052 received = &u->received; |
6115 | 1053 |
1054 } else { | |
1055 src = c; | |
1056 dst = pc; | |
1057 b = &u->downstream_buf; | |
6208
7a14a0d754ad
Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents:
6204
diff
changeset
|
1058 limit_rate = pscf->upload_rate; |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1059 received = &s->received; |
6115 | 1060 } |
1061 | |
1062 for ( ;; ) { | |
1063 | |
1064 if (do_write) { | |
1065 | |
1066 size = b->last - b->pos; | |
1067 | |
1068 if (size && dst && dst->write->ready) { | |
1069 | |
1070 n = dst->send(dst, b->pos, size); | |
1071 | |
1072 if (n == NGX_ERROR) { | |
1073 ngx_stream_proxy_finalize(s, NGX_DECLINED); | |
1074 return NGX_ERROR; | |
1075 } | |
1076 | |
1077 if (n > 0) { | |
1078 b->pos += n; | |
1079 | |
1080 if (b->pos == b->last) { | |
1081 b->pos = b->start; | |
1082 b->last = b->start; | |
1083 } | |
1084 } | |
1085 } | |
1086 } | |
1087 | |
1088 size = b->end - b->last; | |
1089 | |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1090 if (size && src->read->ready && !src->read->delayed) { |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1091 |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1092 if (limit_rate) { |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1093 limit = (off_t) limit_rate * (ngx_time() - u->start_sec + 1) |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1094 - *received; |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1095 |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1096 if (limit <= 0) { |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1097 src->read->delayed = 1; |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1098 delay = (ngx_msec_t) (- limit * 1000 / limit_rate + 1); |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1099 ngx_add_timer(src->read, delay); |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1100 break; |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1101 } |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1102 |
6204
114d1f8cdcab
Stream: fixed possible integer overflow in rate limiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6203
diff
changeset
|
1103 if ((off_t) size > limit) { |
6203
fdfdcad62875
Stream: fixed MSVC compilation warning.
Roman Arutyunyan <arut@nginx.com>
parents:
6202
diff
changeset
|
1104 size = (size_t) limit; |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1105 } |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1106 } |
6115 | 1107 |
1108 n = src->recv(src, b->last, size); | |
1109 | |
1110 if (n == NGX_AGAIN || n == 0) { | |
1111 break; | |
1112 } | |
1113 | |
1114 if (n > 0) { | |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1115 if (limit_rate) { |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1116 delay = (ngx_msec_t) (n * 1000 / limit_rate); |
6115 | 1117 |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1118 if (delay > 0) { |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1119 src->read->delayed = 1; |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1120 ngx_add_timer(src->read, delay); |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1121 } |
6115 | 1122 } |
1123 | |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1124 *received += n; |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1125 b->last += n; |
6115 | 1126 do_write = 1; |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1127 |
6115 | 1128 continue; |
1129 } | |
1130 | |
1131 if (n == NGX_ERROR) { | |
1132 src->read->eof = 1; | |
1133 } | |
1134 } | |
1135 | |
1136 break; | |
1137 } | |
1138 | |
1139 if (src->read->eof && (b->pos == b->last || (dst && dst->read->eof))) { | |
1140 handler = c->log->handler; | |
1141 c->log->handler = NULL; | |
1142 | |
1143 ngx_log_error(NGX_LOG_INFO, c->log, 0, | |
1144 "%s disconnected" | |
1145 ", bytes from/to client:%O/%O" | |
1146 ", bytes from/to upstream:%O/%O", | |
1147 from_upstream ? "upstream" : "client", | |
1148 s->received, c->sent, u->received, pc ? pc->sent : 0); | |
1149 | |
1150 c->log->handler = handler; | |
1151 | |
1152 ngx_stream_proxy_finalize(s, NGX_OK); | |
1153 return NGX_DONE; | |
1154 } | |
1155 | |
6124
f1f222db290b
Stream: prevent repeated event notifications after eof.
Roman Arutyunyan <arut@nginx.com>
parents:
6115
diff
changeset
|
1156 flags = src->read->eof ? NGX_CLOSE_EVENT : 0; |
f1f222db290b
Stream: prevent repeated event notifications after eof.
Roman Arutyunyan <arut@nginx.com>
parents:
6115
diff
changeset
|
1157 |
f1f222db290b
Stream: prevent repeated event notifications after eof.
Roman Arutyunyan <arut@nginx.com>
parents:
6115
diff
changeset
|
1158 if (ngx_handle_read_event(src->read, flags) != NGX_OK) { |
6115 | 1159 ngx_stream_proxy_finalize(s, NGX_ERROR); |
1160 return NGX_ERROR; | |
1161 } | |
1162 | |
1163 if (dst) { | |
1164 if (ngx_handle_write_event(dst->write, 0) != NGX_OK) { | |
1165 ngx_stream_proxy_finalize(s, NGX_ERROR); | |
1166 return NGX_ERROR; | |
1167 } | |
1168 | |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1169 if (!c->read->delayed && !pc->read->delayed) { |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1170 ngx_add_timer(c->write, pscf->timeout); |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1171 |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1172 } else if (c->write->timer_set) { |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1173 ngx_del_timer(c->write); |
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1174 } |
6115 | 1175 } |
1176 | |
1177 return NGX_OK; | |
1178 } | |
1179 | |
1180 | |
1181 static void | |
1182 ngx_stream_proxy_next_upstream(ngx_stream_session_t *s) | |
1183 { | |
1184 ngx_msec_t timeout; | |
1185 ngx_connection_t *pc; | |
1186 ngx_stream_upstream_t *u; | |
1187 ngx_stream_proxy_srv_conf_t *pscf; | |
1188 | |
1189 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, | |
1190 "stream proxy next upstream"); | |
1191 | |
1192 u = s->upstream; | |
1193 | |
1194 if (u->peer.sockaddr) { | |
1195 u->peer.free(&u->peer, u->peer.data, NGX_PEER_FAILED); | |
1196 u->peer.sockaddr = NULL; | |
1197 } | |
1198 | |
1199 pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); | |
1200 | |
1201 timeout = pscf->next_upstream_timeout; | |
1202 | |
1203 if (u->peer.tries == 0 | |
1204 || !pscf->next_upstream | |
1205 || (timeout && ngx_current_msec - u->peer.start_time >= timeout)) | |
1206 { | |
1207 ngx_stream_proxy_finalize(s, NGX_DECLINED); | |
1208 return; | |
1209 } | |
1210 | |
1211 pc = u->peer.connection; | |
1212 | |
1213 if (pc) { | |
1214 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, | |
1215 "close proxy upstream connection: %d", pc->fd); | |
1216 | |
1217 #if (NGX_STREAM_SSL) | |
1218 if (pc->ssl) { | |
1219 pc->ssl->no_wait_shutdown = 1; | |
1220 pc->ssl->no_send_shutdown = 1; | |
1221 | |
1222 (void) ngx_ssl_shutdown(pc); | |
1223 } | |
1224 #endif | |
1225 | |
1226 ngx_close_connection(pc); | |
1227 u->peer.connection = NULL; | |
1228 } | |
1229 | |
1230 ngx_stream_proxy_connect(s); | |
1231 } | |
1232 | |
1233 | |
1234 static void | |
1235 ngx_stream_proxy_finalize(ngx_stream_session_t *s, ngx_int_t rc) | |
1236 { | |
1237 ngx_connection_t *pc; | |
1238 ngx_stream_upstream_t *u; | |
1239 | |
1240 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, | |
1241 "finalize stream proxy: %i", rc); | |
1242 | |
1243 u = s->upstream; | |
1244 | |
1245 if (u == NULL) { | |
1246 goto noupstream; | |
1247 } | |
1248 | |
1249 if (u->peer.free && u->peer.sockaddr) { | |
1250 u->peer.free(&u->peer, u->peer.data, 0); | |
1251 u->peer.sockaddr = NULL; | |
1252 } | |
1253 | |
1254 pc = u->peer.connection; | |
1255 | |
1256 if (pc) { | |
1257 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, | |
1258 "close stream proxy upstream connection: %d", pc->fd); | |
1259 | |
1260 #if (NGX_STREAM_SSL) | |
1261 if (pc->ssl) { | |
1262 pc->ssl->no_wait_shutdown = 1; | |
1263 (void) ngx_ssl_shutdown(pc); | |
1264 } | |
1265 #endif | |
1266 | |
1267 ngx_close_connection(pc); | |
1268 u->peer.connection = NULL; | |
1269 } | |
1270 | |
1271 noupstream: | |
1272 | |
1273 ngx_stream_close_connection(s->connection); | |
1274 } | |
1275 | |
1276 | |
1277 static u_char * | |
1278 ngx_stream_proxy_log_error(ngx_log_t *log, u_char *buf, size_t len) | |
1279 { | |
1280 u_char *p; | |
1281 ngx_connection_t *pc; | |
1282 ngx_stream_session_t *s; | |
1283 ngx_stream_upstream_t *u; | |
1284 | |
1285 s = log->data; | |
1286 | |
1287 u = s->upstream; | |
1288 | |
1289 p = buf; | |
1290 | |
1291 if (u->peer.name) { | |
1292 p = ngx_snprintf(p, len, ", upstream: \"%V\"", u->peer.name); | |
1293 len -= p - buf; | |
1294 } | |
1295 | |
1296 pc = u->peer.connection; | |
1297 | |
1298 p = ngx_snprintf(p, len, | |
1299 ", bytes from/to client:%O/%O" | |
1300 ", bytes from/to upstream:%O/%O", | |
1301 s->received, s->connection->sent, | |
1302 u->received, pc ? pc->sent : 0); | |
1303 | |
1304 return p; | |
1305 } | |
1306 | |
1307 | |
1308 static void * | |
1309 ngx_stream_proxy_create_srv_conf(ngx_conf_t *cf) | |
1310 { | |
1311 ngx_stream_proxy_srv_conf_t *conf; | |
1312 | |
1313 conf = ngx_pcalloc(cf->pool, sizeof(ngx_stream_proxy_srv_conf_t)); | |
1314 if (conf == NULL) { | |
1315 return NULL; | |
1316 } | |
1317 | |
1318 /* | |
1319 * set by ngx_pcalloc(): | |
1320 * | |
1321 * conf->ssl_protocols = 0; | |
1322 * conf->ssl_ciphers = { 0, NULL }; | |
1323 * conf->ssl_name = { 0, NULL }; | |
1324 * conf->ssl_trusted_certificate = { 0, NULL }; | |
1325 * conf->ssl_crl = { 0, NULL }; | |
1326 * conf->ssl_certificate = { 0, NULL }; | |
1327 * conf->ssl_certificate_key = { 0, NULL }; | |
1328 * | |
1329 * conf->ssl = NULL; | |
1330 * conf->upstream = NULL; | |
1331 */ | |
1332 | |
1333 conf->connect_timeout = NGX_CONF_UNSET_MSEC; | |
1334 conf->timeout = NGX_CONF_UNSET_MSEC; | |
1335 conf->next_upstream_timeout = NGX_CONF_UNSET_MSEC; | |
6215
8ee6a08ea3eb
Stream: added proxy_buffer_size to set the size of data buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
6208
diff
changeset
|
1336 conf->buffer_size = NGX_CONF_UNSET_SIZE; |
6208
7a14a0d754ad
Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents:
6204
diff
changeset
|
1337 conf->upload_rate = NGX_CONF_UNSET_SIZE; |
7a14a0d754ad
Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents:
6204
diff
changeset
|
1338 conf->download_rate = NGX_CONF_UNSET_SIZE; |
6115 | 1339 conf->next_upstream_tries = NGX_CONF_UNSET_UINT; |
1340 conf->next_upstream = NGX_CONF_UNSET; | |
6184
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
1341 conf->proxy_protocol = NGX_CONF_UNSET; |
6183
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1342 conf->local = NGX_CONF_UNSET_PTR; |
6115 | 1343 |
1344 #if (NGX_STREAM_SSL) | |
1345 conf->ssl_enable = NGX_CONF_UNSET; | |
1346 conf->ssl_session_reuse = NGX_CONF_UNSET; | |
1347 conf->ssl_server_name = NGX_CONF_UNSET; | |
1348 conf->ssl_verify = NGX_CONF_UNSET; | |
1349 conf->ssl_verify_depth = NGX_CONF_UNSET_UINT; | |
1350 conf->ssl_passwords = NGX_CONF_UNSET_PTR; | |
1351 #endif | |
1352 | |
1353 return conf; | |
1354 } | |
1355 | |
1356 | |
1357 static char * | |
1358 ngx_stream_proxy_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) | |
1359 { | |
1360 ngx_stream_proxy_srv_conf_t *prev = parent; | |
1361 ngx_stream_proxy_srv_conf_t *conf = child; | |
1362 | |
1363 ngx_conf_merge_msec_value(conf->connect_timeout, | |
1364 prev->connect_timeout, 60000); | |
1365 | |
1366 ngx_conf_merge_msec_value(conf->timeout, | |
1367 prev->timeout, 10 * 60000); | |
1368 | |
1369 ngx_conf_merge_msec_value(conf->next_upstream_timeout, | |
1370 prev->next_upstream_timeout, 0); | |
1371 | |
6215
8ee6a08ea3eb
Stream: added proxy_buffer_size to set the size of data buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
6208
diff
changeset
|
1372 ngx_conf_merge_size_value(conf->buffer_size, |
8ee6a08ea3eb
Stream: added proxy_buffer_size to set the size of data buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
6208
diff
changeset
|
1373 prev->buffer_size, 16384); |
6115 | 1374 |
6208
7a14a0d754ad
Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents:
6204
diff
changeset
|
1375 ngx_conf_merge_size_value(conf->upload_rate, |
7a14a0d754ad
Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents:
6204
diff
changeset
|
1376 prev->upload_rate, 0); |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1377 |
6208
7a14a0d754ad
Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents:
6204
diff
changeset
|
1378 ngx_conf_merge_size_value(conf->download_rate, |
7a14a0d754ad
Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents:
6204
diff
changeset
|
1379 prev->download_rate, 0); |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6200
diff
changeset
|
1380 |
6115 | 1381 ngx_conf_merge_uint_value(conf->next_upstream_tries, |
1382 prev->next_upstream_tries, 0); | |
1383 | |
1384 ngx_conf_merge_value(conf->next_upstream, prev->next_upstream, 1); | |
1385 | |
6184
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
1386 ngx_conf_merge_value(conf->proxy_protocol, prev->proxy_protocol, 0); |
fa663739e115
Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents:
6183
diff
changeset
|
1387 |
6183
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1388 ngx_conf_merge_ptr_value(conf->local, prev->local, NULL); |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1389 |
6115 | 1390 #if (NGX_STREAM_SSL) |
1391 | |
1392 ngx_conf_merge_value(conf->ssl_enable, prev->ssl_enable, 0); | |
1393 | |
1394 ngx_conf_merge_value(conf->ssl_session_reuse, | |
1395 prev->ssl_session_reuse, 1); | |
1396 | |
1397 ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols, | |
6157
b2899e7d0ef8
Disabled SSLv3 by default (ticket #653).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6124
diff
changeset
|
1398 (NGX_CONF_BITMASK_SET|NGX_SSL_TLSv1 |
b2899e7d0ef8
Disabled SSLv3 by default (ticket #653).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6124
diff
changeset
|
1399 |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2)); |
6115 | 1400 |
1401 ngx_conf_merge_str_value(conf->ssl_ciphers, prev->ssl_ciphers, "DEFAULT"); | |
1402 | |
1403 ngx_conf_merge_str_value(conf->ssl_name, prev->ssl_name, ""); | |
1404 | |
1405 ngx_conf_merge_value(conf->ssl_server_name, prev->ssl_server_name, 0); | |
1406 | |
1407 ngx_conf_merge_value(conf->ssl_verify, prev->ssl_verify, 0); | |
1408 | |
1409 ngx_conf_merge_uint_value(conf->ssl_verify_depth, | |
1410 prev->ssl_verify_depth, 1); | |
1411 | |
1412 ngx_conf_merge_str_value(conf->ssl_trusted_certificate, | |
1413 prev->ssl_trusted_certificate, ""); | |
1414 | |
1415 ngx_conf_merge_str_value(conf->ssl_crl, prev->ssl_crl, ""); | |
1416 | |
1417 ngx_conf_merge_str_value(conf->ssl_certificate, | |
1418 prev->ssl_certificate, ""); | |
1419 | |
1420 ngx_conf_merge_str_value(conf->ssl_certificate_key, | |
1421 prev->ssl_certificate_key, ""); | |
1422 | |
1423 ngx_conf_merge_ptr_value(conf->ssl_passwords, prev->ssl_passwords, NULL); | |
1424 | |
1425 if (conf->ssl_enable && ngx_stream_proxy_set_ssl(cf, conf) != NGX_OK) { | |
1426 return NGX_CONF_ERROR; | |
1427 } | |
1428 | |
1429 #endif | |
1430 | |
1431 return NGX_CONF_OK; | |
1432 } | |
1433 | |
1434 | |
1435 #if (NGX_STREAM_SSL) | |
1436 | |
1437 static ngx_int_t | |
1438 ngx_stream_proxy_set_ssl(ngx_conf_t *cf, ngx_stream_proxy_srv_conf_t *pscf) | |
1439 { | |
1440 ngx_pool_cleanup_t *cln; | |
1441 | |
1442 pscf->ssl = ngx_pcalloc(cf->pool, sizeof(ngx_ssl_t)); | |
1443 if (pscf->ssl == NULL) { | |
1444 return NGX_ERROR; | |
1445 } | |
1446 | |
1447 pscf->ssl->log = cf->log; | |
1448 | |
1449 if (ngx_ssl_create(pscf->ssl, pscf->ssl_protocols, NULL) != NGX_OK) { | |
1450 return NGX_ERROR; | |
1451 } | |
1452 | |
1453 cln = ngx_pool_cleanup_add(cf->pool, 0); | |
1454 if (cln == NULL) { | |
1455 return NGX_ERROR; | |
1456 } | |
1457 | |
1458 cln->handler = ngx_ssl_cleanup_ctx; | |
1459 cln->data = pscf->ssl; | |
1460 | |
1461 if (pscf->ssl_certificate.len) { | |
1462 | |
1463 if (pscf->ssl_certificate_key.len == 0) { | |
1464 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
1465 "no \"proxy_ssl_certificate_key\" is defined " | |
1466 "for certificate \"%V\"", &pscf->ssl_certificate); | |
1467 return NGX_ERROR; | |
1468 } | |
1469 | |
1470 if (ngx_ssl_certificate(cf, pscf->ssl, &pscf->ssl_certificate, | |
1471 &pscf->ssl_certificate_key, pscf->ssl_passwords) | |
1472 != NGX_OK) | |
1473 { | |
1474 return NGX_ERROR; | |
1475 } | |
1476 } | |
1477 | |
1478 if (SSL_CTX_set_cipher_list(pscf->ssl->ctx, | |
1479 (const char *) pscf->ssl_ciphers.data) | |
1480 == 0) | |
1481 { | |
1482 ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0, | |
1483 "SSL_CTX_set_cipher_list(\"%V\") failed", | |
1484 &pscf->ssl_ciphers); | |
1485 return NGX_ERROR; | |
1486 } | |
1487 | |
1488 if (pscf->ssl_verify) { | |
1489 if (pscf->ssl_trusted_certificate.len == 0) { | |
1490 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
1491 "no proxy_ssl_trusted_certificate for proxy_ssl_verify"); | |
1492 return NGX_ERROR; | |
1493 } | |
1494 | |
1495 if (ngx_ssl_trusted_certificate(cf, pscf->ssl, | |
1496 &pscf->ssl_trusted_certificate, | |
1497 pscf->ssl_verify_depth) | |
1498 != NGX_OK) | |
1499 { | |
1500 return NGX_ERROR; | |
1501 } | |
1502 | |
1503 if (ngx_ssl_crl(cf, pscf->ssl, &pscf->ssl_crl) != NGX_OK) { | |
1504 return NGX_ERROR; | |
1505 } | |
1506 } | |
1507 | |
1508 return NGX_OK; | |
1509 } | |
1510 | |
1511 #endif | |
1512 | |
1513 | |
1514 static char * | |
1515 ngx_stream_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1516 { | |
1517 ngx_stream_proxy_srv_conf_t *pscf = conf; | |
1518 | |
1519 ngx_url_t u; | |
1520 ngx_str_t *value, *url; | |
1521 ngx_stream_core_srv_conf_t *cscf; | |
1522 | |
1523 if (pscf->upstream) { | |
1524 return "is duplicate"; | |
1525 } | |
1526 | |
1527 cscf = ngx_stream_conf_get_module_srv_conf(cf, ngx_stream_core_module); | |
1528 | |
1529 cscf->handler = ngx_stream_proxy_handler; | |
1530 | |
1531 value = cf->args->elts; | |
1532 | |
1533 url = &value[1]; | |
1534 | |
1535 ngx_memzero(&u, sizeof(ngx_url_t)); | |
1536 | |
1537 u.url = *url; | |
1538 u.no_resolve = 1; | |
1539 | |
1540 pscf->upstream = ngx_stream_upstream_add(cf, &u, 0); | |
1541 if (pscf->upstream == NULL) { | |
1542 return NGX_CONF_ERROR; | |
1543 } | |
1544 | |
1545 return NGX_CONF_OK; | |
1546 } | |
6183
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1547 |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1548 |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1549 static char * |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1550 ngx_stream_proxy_bind(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1551 { |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1552 ngx_stream_proxy_srv_conf_t *pscf = conf; |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1553 |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1554 ngx_int_t rc; |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1555 ngx_str_t *value; |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1556 |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1557 if (pscf->local != NGX_CONF_UNSET_PTR) { |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1558 return "is duplicate"; |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1559 } |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1560 |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1561 value = cf->args->elts; |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1562 |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1563 if (ngx_strcmp(value[1].data, "off") == 0) { |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1564 pscf->local = NULL; |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1565 return NGX_CONF_OK; |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1566 } |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1567 |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1568 pscf->local = ngx_palloc(cf->pool, sizeof(ngx_addr_t)); |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1569 if (pscf->local == NULL) { |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1570 return NGX_CONF_ERROR; |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1571 } |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1572 |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1573 rc = ngx_parse_addr(cf->pool, pscf->local, value[1].data, value[1].len); |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1574 |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1575 switch (rc) { |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1576 case NGX_OK: |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1577 pscf->local->name = value[1]; |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1578 return NGX_CONF_OK; |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1579 |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1580 case NGX_DECLINED: |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1581 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1582 "invalid address \"%V\"", &value[1]); |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1583 /* fall through */ |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1584 |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1585 default: |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1586 return NGX_CONF_ERROR; |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1587 } |
4dcffe43a7ea
Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
1588 } |