我的haproxy实例提供2个域(主要是为了避免主站点上的XSS)。
规则看起来像这样
bind :443 ssl crt /etc/ssl/haproxy.pem acl is_static hdr_end(Host) -i example.com acl is_api hdr_end(Host) -i api.example.com acl is_files hdr_end(Host) -i example.io redirect scheme https if !{ ssl_fc } is_static is_api
现在,SSL使用/etc/ssl/haproxy.pem作为默authentication书,这是example.com的证书,而不是example.io 。
我如何指定多个域名的证书?
您可以将所有证书连接到文件haproxy1.pem和haproxy2.pem或者您可以指定一个包含所有pem文件的目录。
cat cert1.pem key1.pem > haproxy1.pem cat cert2.pem key2.pem > haproxy2.pem
根据haproxy文档
然后在configuration中使用这样的东西:
defaults log 127.0.0.1 local0 option tcplog frontend ft_test mode http bind 0.0.0.0:443 ssl crt /certs/haproxy1.pem crt /certs/haproxy2.pem use_backend bk_cert1 if { ssl_fc_sni my.example.com } # content switching based on SNI use_backend bk_cert2 if { ssl_fc_sni my.example.org } # content switching based on SNI backend bk_cert1 mode http server srv1 <ip-address2>:80 backend bk_cert2 mode http server srv2 <ip-address3>:80
了解更多关于SNI的信息
请记住,SSL支持处于haproxy的开发阶段,而且它显然有相当的性能影响。
还有其他解决scheme在这个线程中讨论: https : //stackoverflow.com/questions/10684484/haproxy-with-multiple-https-sites
希望这可以帮助。