haproxy ssl证书配置

发布时间 2023-11-16 15:59:33作者: 金笛秀才

通常情况下,web应用程序的ssl证书放置于nginx的服务器,但很多时候前面会加一次负载均衡,使用HAProxy可以实现https的证书安全,从客户浏览器到HAProxy代理服务器之间为ssl加密传输,从HAProxy代理服务器到后端服务器用明文传输。此方式会使得HAProxy服务器压力较大,所以为了考虑性能问题,建议将证书配置与nginx服务器上。。

1、将秘钥和证书内容吸入pem文件

cat test.cn_RSA.key test.cn.crt >test.pem`

2、配置haproxy

listen  web
   bind *.*.*.*:80
   bind *.*.*.*:443 ssl crt /etc/haproxy/test.pem
   redirect scheme https if !{ ssl_fc }
   mode http
   option tcplog
   log global
   http-request set-header X-Forwarded-Proto http if !{ ssl_fc }
   http-request set-header X-Forwarded-Proto https if { ssl_fc }
   server node01  192.168.1.1:80  check inter 3000 fall 2 rise 5
   server node02  192.168.1.2:80  check inter 3000 fall 2 rise 5

3、重新启动haproxy

systemctl restart haproxy