我需要用两个不同的SSL证书来configurationHAProxy
现在我从serverfault( 在Haproxy中configuration多个SSL证书 )的post中学习了如何使用2个证书,但是服务器继续使用两个域中提到的第一个证书。
configuration:
frontend apache-https bind 192.168.56.150:443 ssl crt /certs/crt1.pem crt /certs/cert2.pem reqadd X-Forwarded-Proto:\ https default_backend apache-http backend apache-http redirect scheme https if { hdr(Host) -i www.example.com } !{ ssl_fc } redirect scheme https if { hdr(Host) -i api.example.com } !{ ssl_fc } ...
如何根据URL告诉HAProxy使用哪个证书?
完整configuration:
global log /dev/log local0 log /dev/log local1 notice chroot /var/lib/haproxy stats socket /run/haproxy/admin.sock mode 660 level admin stats timeout 30s user haproxy group haproxy daemon # Default SSL material locations ca-base /etc/ssl/certs crt-base /etc/ssl/private ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS ssl-default-bind-options no-sslv3 tune.ssl.default-dh-param 2048 // better with 2048 but more processor intensive defaults log global mode http option tcplog option dontlognull timeout connect 5000 timeout client 50000 timeout server 50000 frontend apache-http bind 0.0.0.0:80 mode http option http-server-close # needed for forwardfor option forwardfor # forward IP Address of client reqadd X-Forwarded-Proto:\ http default_backend apache-http stats enable frontend apache-https bind 0.0.0.0:443 ssl crt cer1.pem cert2.pem reqadd X-Forwarded-Proto:\ https default_backend apache-http backend apache-http redirect scheme https if { hdr(Host) -i db.example.com } !{ ssl_fc } redirect scheme https if { hdr(Host) -i api2.example.com } !{ ssl_fc } balance roundrobin cookie SERVERID insert indirect nocache server www-1 10.0.0.101:80 cookie S1 check server www-2 10.0.0.102:80 cookie S2 check server www-3 10.0.0.103:80 cookie S3 check
确保您正在运行HAProxy 1.6或更高版本
这个问题有点老,但是我遇到了与OP类似的configuration问题。
HAProxy 1.5接受bind选项上的多重crt语法; 但是,它在响应时只使用第一个证书。
HAProxy 1.6似乎根据呼叫者的请求回应证书。 这似乎并不需要在configuration中有任何特殊的sni ACL。
下面是一个适用于1.6的示例,但在对1.5版place2.com请求进行响应时无法使用cert2.pem :
frontend http-in bind *:80 bind *:443 ssl crt cert1.pem crt cert2.pem mode http acl common_dst hdr(Host) -m str place1.com place2.com use_backend be_common if common_dst backend be_common # nothing special here.
您如何testinghaproxy提供的证书? 如果您使用的是openssl s_client ,请注意,它需要额外的参数( -servername api.domain.com )才能发送haproxy所需的SNI信息来决定要提供哪个证书。