haproxy SNI 分流入口(部署于 hk-yunmai 云麦香港)
443 端口复用器:按 TLS SNI 把流量分发到 nginx / DERP / xray,实现单 IP 多服务。
访问方式
- 所有 HTTPS 域名均从 443 进入,按 SNI 路由:
- vpn/xray/hk1/octop/oct/newapi/usage.bianquezhiyin.* → nginx(127.0.0.1:10443)
- derp.bianquezhiyin.cn → derper(127.0.0.1:3443)
- SNI=dl.google.com(伪装)→ xray(127.0.0.1:2053)
技术架构
- 栈:HAProxy 2.x(tcp 模式,tcp-request inspect-delay 5s + req_ssl_sni 匹配)
- 配置:/etc/haproxy/haproxy.cfg(frontend https_443 + backend nginx_10443/derp_3443/xray_2053)
- 进程管理:systemd haproxy(-Ws master-worker)
- 端口:443(公网)
- 依赖:nginx(10443)、derper-hk(3443)、xray(2053)
数据
使用方法
- 新增域名:在 use_backend 增加一行 SNI 规则 + nginx 站点
维护方式
- 启停:systemctl restart haproxy
- 校验:haproxy -c -f /etc/haproxy/haproxy.cfg
- 日志:journald -u haproxy(/dev/log local0)
现状与风险
- 运行 16+ 天稳定;default_backend 兜底到 nginx
- 规则简单清晰,风险低
优化建议
- 可维护性:在配置头部维护"域名→后端"注释表
- 安全:timeout client 60s 对长连接(代理)偏短,如代理断流可调大到 300s
- 备份:haproxy.cfg 纳入配置备份