约 110 字 预计阅读 1 分钟
nginx隧道模式使用SNI进行流量分流
通过SNI实现代理
1
2
3
4
5
6
7
8
9
|
stream {
#resolver 114.114.114.114;
server {
listen 443;
ssl_preread on;
proxy_connect_timeout 5s;
proxy_pass $ssl_preread_server_name:$server_port;
}
}
|
通过SNI实现分流
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
map $ssl_preread_server_name $sni_port {
default $server_port;
backend.example.com 8130;
}
map $ssl_preread_server_name $sni_server {
default $$ssl_preread_server_name;
backend.example.com 127.0.0.1;
}
upstream backend {
server 127.0.0.1:3129;
}
upstream backend2 {
server 192.168.0.1:12345;
}
stream {
#resolver 114.114.114.114;
server {
listen 443;
ssl_preread on;
proxy_connect_timeout 5s;
#proxy_pass $ssl_preread_server_name:$server_port;
proxy_pass $sni_server:$sni_port;
}
}
|
参考