名词解释
HAProxy 配置
关键在于接受前端的 h2 请求,以及转发到后端的 h2c 请求,请看关键配置:
frontend fe_example_test # 下面一行指定了: # 1. 监听当前机器的 443 端口 # 2. 使用 ssl,且证书为 /etc/haproxy/ssl/g4n32u.xyz.pem,协商协议为 ALPN # 3. HTTP 版本为 2,即 h2 bind *:443 ssl crt /etc/haproxy/ssl/g4n32u.xyz.pem alpn h2 mode http # 指定入口是 http 模式 default_backend be_example_test backend be_example_test mode http # 指定转发到后端是 http 模式 # 下面一行指定了: # 1. 后端应用别名:backend_server # 2. 后端应用的地址和端口号 # 3. 转发到后端使用的协议,这里是 h2(即h2c),因为流量已被 HAProxy 解密 server backend_server 127.0.0.1:60002 proto h2
关于 HTTPS 证书
如果你的证书像我一样是用 acme.sh 生成的,那要注意一下 HAProxy 对证书格式的要求和 Nginx 略有区别。对于 Nginx 来说,使用 acme.sh 生成的 fullchain-file 即可,但是对于 HAProxy,你必须将证书和私钥合并起来,也就是将 acme.sh 生成的 cert-file 和 key-file 合并起来,用命令描述上面这句话就是:
acme.sh --installcert -d example.com \ --cert-file /etc/haproxy/ssl/example.com.cer \ --key-file /etc/haproxy/ssl/example.com.key \ --fullchain-file /etc/haproxy/ssl/example.com.fullchain.cer \ --reloadcmd "cat /etc/haproxy/ssl/example.com.cer /etc/haproxy/ssl/example.com.key | tee /etc/haproxy/ssl/example.com.pem && systemctl restart haproxy"
我注意到在目录 ~/.acme.sh/example.com/ 这个目录下,存在 example.com.pem,里面已经包含了证书和密钥合并的结果,但是 acme.sh 并没有提供安装该文件的命令入口。所以只能退而求其次的在 --reloadcmd 命令中拼接。
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/198504.html原文链接:https://javaforall.net
