haproxy SSL“失败鲸鱼”维护页面

我们正在使用haproxy的自定义错误页面function来显示“失败鲸鱼”维护页面,同时我们正在部署到我们的网站。

但是,由于haproxy不能显示SSL'd用户的自定义错误页面,我如何将用户redirect到非SSL连接,如果没有后端可用,显示“失败鲸鱼”?

据我了解,你不能在haproxy中redirect客户端,因为它根本不能与SSL连接交互(不能解密请求或用redirectencryption响应)。 为了做到这一点,连接必须去SSL服务器。

我能想到的唯一的办法是用SSL key / cert和失败鲸鱼页面(甚至可以在haproxy机器本身的一些奇怪的端口上运行,使用localhost:4433或类似的东西)build立另一个web服务器,以及haproxy在维护期间将所有SSL连接发送到该服务器。

最后,我在负载均衡器上安装了stunnel,并通过隧道将stream量redirect到80端口。

HTTPs client => haproxy:443 =>(没有后端可用,使用'backup'server 127.0.0.1:4443)=> 127.0.0.1:443(stunnel)=> 127.0.0.1:80(haproxy,带失败页面)

haproxy.conf

 listen SSL-via-shared-ip 1.2.3.2:443 mode tcp option ssl-hello-chk #option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www option httpchk HEAD /test.txt HTTP/1.0 # list of web servers server app1 1.2.3.4:443 check port 80 maxconn 60 server app2 1.2.3.5:443 check port 80 maxconn 60 server failwhale 127.0.0.1:4443 backup maxconn 500 #error pages# ##these are in raw http, not just html ## errorfile 400 /etc/haproxy/errors/400.http errorfile 403 /etc/haproxy/errors/403.http errorfile 408 /etc/haproxy/errors/408.http errorfile 500 /etc/haproxy/errors/500.http errorfile 502 /etc/haproxy/errors/502.http errorfile 503 /etc/haproxy/errors/503.http errorfile 504 /etc/haproxy/errors/504.http 

stunnel.conf

 ; Protocol version (all, SSLv2, SSLv3, TLSv1) sslVersion = all options = NO_SSLv2 ; PID is created inside the chroot jail pid = /var/run/stunnel4/stunnel4.pid ; Some performance tunings socket = l:TCP_NODELAY=1 socket = r:TCP_NODELAY=1 ; Some debugging stuff useful for troubleshooting debug = 7 output = /var/log/stunnel4/stunnel.log ; Certificate/key is needed in server mode and optional in client mode cert = /etc/ssl/certs/stunnel.pem key = /etc/ssl/certs/stunnel.pem ; Some security enhancements for UNIX systems - comment them out on Win32 ;chroot = /var/lib/stunnel4/ setuid = stunnel4 setgid = stunnel4 ; Service-level configuration [failwhale] accept = 4443 connect = 127.0.0.1:80 TIMEOUTclose = 0 

HAProxy可以做到这一点的唯一方法是如果它也终止SSL连接。 在这种设置中,HAProxy服务器将具有SSL证书,并且将通过进一步的SSL(新的连接)或直接的HTTP与服务器池进行通信。

另一个select是为具有SSLfunction的Web服务器提供失败鲸鱼服务,无论传递哪个URI,都将提供相同的失败鲸鱼页面。 这样,你可以保留这台服务器作为“备份”服务器,任何连接的尝试都将获得良好的效果。