使用HAProxy和Nginx使用SSL进行发布

我正在使用多个HAProxy负载平衡器,Nginx Web服务器和MySQL服务器构build一个高度可用的站点。 该网站需要能够承受负载平衡器或networking服务器节点下线,而不会中断访问者的服务。 目前,我有两个运行HAProxy的盒子,它们使用keepalived共享一个虚拟IP,然后转发给运行Nginx的两个Web服务器,然后使用MySQL复制绑定到两个MySQL盒子,并使用心跳共享一个虚拟IP。 除了HAProxy上的SSLstream量外,一切正常。 我正在运行版本1.5 dev12与编译的openssl支持。当我尝试通过https导航到haproxy的虚拟IP,我得到的消息:纯HTTP请求被发送到HTTPS端口。 这里是我的haproxy.cfg到目前为止,主要是从其他post组装:

global log 127.0.0.1 local0 log 127.0.0.1 local1 notice # log 127.0.0.1 local0 user haproxy group haproxy daemon maxconn 20000 defaults log global option dontlognull balance leastconn clitimeout 60000 srvtimeout 60000 contimeout 5000 retries 3 option redispatch listen front bind :80 bind :443 ssl crt /etc/pki/tls/certs/cert.pem mode http option http-server-close option forwardfor reqadd X-Forwarded-Proto:\ https if { is_ssl } reqadd X-Proto:\ SSL if { is_ssl } server web01 192.168.25.34 check inter 1s server web02 192.168.25.32 check inter 1s stats enable stats uri /stats stats realm HAProxy\ Statistics stats auth admin:********* 

任何想法为什么SSLstream量没有正确传递? 另外,你会推荐的其他更改? 我仍然需要configuration日志logging,所以不要担心该部分。 在此先感谢您的帮助。

用ssl,你必须使用前端/后端,而不是听。 原因是通过监听,一个端口上的haproxy连接到同一端口上的服务器。 因此,443上的SSL请求被haproxy解密,然后被发送到443端口上的Web服务器,该端口期待SSL连接。 (这就是你如何得到这个错误。)使用前端/后端,你可以告诉haproxy在前端的一个端口上接受连接,但要完成到后端不同端口的连接。

或者,您可以重新configuration您的Web服务器接受端口443上的http请求(而不是https请求)。就个人而言,我不会那样做,因为这是非标准的,而您希望负载平衡器做SSL卸载接受连接443并在端口80上完成。