惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
博客园 - 聂微东
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - Franky
MyScale Blog
MyScale Blog
A
About on SuperTechFans
博客园_首页
B
Blog RSS Feed
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Vercel News
Vercel News
C
Check Point Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 【当耐特】
M
MIT News - Artificial intelligence
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
I
InfoQ
罗磊的独立博客

Hunsh's Blog

生成个人的 Github PR List 如何选择合适的加密手段 如何优雅导入 k8s.io/kubernetes Make Go mod and Git to use specify .netrc 多架构镜像的体积优化 使用 buildkit 进行多架构构建并提取产物 如何修改镜像 layer(以 sourcemap-less grafana 为例) acme.sh 自动化 Google CA 申请证书 微信小程序嵌入任意公众号文章 k8s && bazel 项目从 go1.20 升级 go1.21 go serve http and https on same port typecho 迁移到 hexo 实现 hexo 文章和资源在同一目录下 golang mitm 遇到的问题 流式数据专用的 mine-type Golang 正向代理对于 Host 的处理 (RFC 7230) 分享 MacOS 的一些系统fix脚本(dns、sleep) prometheus rate/increase/delta/sum等函数不符合预期或出现小数的原理 [油猴脚本] USTB Everywhere 为校外访问添加访问任意网站的能力
Nginx SNI Proxy
2025-04-22 · via Hunsh's Blog

由于互联网相关上相关资料较为零散,本文进行一个常用场景的使用总结

Prepare

ubuntu 可以直接 apt install -y nginx,ALinux 的 yum 上的 nginx 不带有 stream_module,需要自行编译,编译时需要携带 --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module

如果 nginx 为自行编译,nginx.conf head 需要加上

1
load_module /usr/lib/nginx/modules/ngx_stream_module.so;

Usage

any domain(不限制域名,转发所有 request,通常作用为限制网络条件下的网关)

1
2
3
4
5
6
7
8
9
stream {
resolver 127.0.0.1;

server {
listen 443;
proxy_pass $ssl_preread_server_name:443;
ssl_preread on;
}
}

specific domains(限制特定域名)

1
2
3
4
5
6
7
8
9
10
11
12
13
stream {
# ip 处也可填写域名
map $ssl_preread_server_name $target_backend {
example.domain.com ip:443;
}
resolver 127.0.0.1;

server {
listen 443;
proxy_pass $target_backend;
ssl_preread on;
}
}

regexp

1
2
3
4
5
6
7
8
9
10
11
12
13
stream {
# ip 处也可填写域名
map $ssl_preread_server_name $target_backend {
~(.*).domain.com $1.other.com:443;
}
resolver 127.0.0.1;

server {
listen 443;
proxy_pass $target_backend;
ssl_preread on;
}
}