Phoenix xie

An Engineer of Plasma physics who has strayed into the education industry.

  • 主页
  • 所有文章

Phoenix xie

An Engineer of Plasma physics who has strayed into the education industry.

  • 主页
  • 所有文章

利用Haproxy实现443端口的复用

2015-10-10

HTTPS和其他的SSL/TLS都想用443端口,让我很烦躁

众所周知HTTPS默认是使用443端口的,但是我又让类似与SSLVPN之类的也用443端口。这可怎么办,只有一个公网IP,不能分别监听。然而SSL/TLS在7层,其他的非SSL/TLS的应用层特征不相同,只能用4层。于是就想到了haproxy,这个可以提供高可用性、负载均衡以及基于TCP和HTTP应用的代理。利用haproxy的4层代理功能实现后端多应用的转发。

haproxy可以根据acl来实现不通特征的转发。haproxy的介绍和其他的不多啰嗦,直接贴配置好了。

  global
  log 127.0.0.1   local3 
  log 127.0.0.1   local3 info
  maxconn 65535
  chroot /usr/share/haproxy
  user nobody
  group nogroup
  daemon
  nbproc 2
defaults  
  log global
  option tcplog  
  option dontlognull
  #option originalto
  maxconn  65535
  timeout connect 500000
  timeout client 500000
  timeout server 500000


frontend tls-ssl  
  mode tcp
  bind :443
  bind :::443
  tcp-request inspect-delay 3s
  tcp-request content accept if { req.ssl_hello_type 1 }
  # ACL configure
  acl 0_www req_ssl_sni -i abc1.def.ghi
  acl 1_ocserv req_ssl_sni -i abc2.def.ghi
  acl 2_ssh_payload payload(0,7) -m bin 5353482d322e30
  # Backend choice
  use_backend nginx if 0_www { req.ssl_hello_type 1 }
  use_backend ocserv if 1_ocserv
  use_backend ocserv if { req.ssl_hello_type 1 }
  use_backend openssh if 2_ssh_payload
  use_backend openssh if !{ req.ssl_hello_type 1 } { req.len 0 }
  use_backend tunnel if !{ req.ssl_hello_type 1 } !{ req.len 0 }
  #
backend nginx  
  #mode tcp
  option ssl-hello-chk
  server webserver 127.0.0.1:4443
backend ocserv  
  #mode tcp
  timeout server 8h
  server sslvpn 127.0.0.1:4500
backend tunnel  
  #mode tcp
  timeout server 2h
  server ss 127.0.0.1:512
backend openssh  
  #mode tcp
  timeout server 3h
  server openssh 127.0.0.1:22

这样一来,就实现了443端口的复用,后端一共又4个不同的服务。配置的重点在acl和sni。检测域名的证书,以此来判断流量该转发到哪。

  • Nginx
  • Linux
  • SSL/TLS
  • 网络基础
给Nginx增加ChaCha20-Poly1305加密套件
利用Linux内核路由器搭建无缝科学上网(二)
© 2022 Phoenix xie
Hexo Theme Yilia by Litten