Haproxy实现https

haproxy可以实现https的证书安全,从用户到haproxy为https,从haproxy到后端服务器用http通信 ,但是基于性能考虑,生产中证书都是在后端服务器比如nginx上实现。

配置HAProxy支持https协议,支持ssl会话:

bind *:443 ssl crt /PATH/TO/SOME_PEM_FILE

指令 crt 后证书文件为PEM格式,需要同时包含证书和所有私钥:

cat demo.key demo.crt > demo.pem

把80端口的请求重向定443:

bind *:80 redirect scheme https if !{ ssl_fc }

一、实验环境

haproxy:172.25.254.100

RS1:172.25.254.10

RS2:172.25.254.20

web服务:nginx

关闭防火墙和SELinux

systemctl stop firewalld

setenforce 0

二、实现步骤

1、制作证书

haproxy:

root@haproxy \~\]# mkdir -p /etc/haproxy/certs \[root@haproxy \~\]# openssl req -newkey rsa:2048 -nodes -sha256 --keyout /etc/haproxy/certs/ouqisheng.org.key -x509 -days 365 -out /etc/haproxy/certs/ouqisheng.org.crt \[root@haproxy \~\]# cat /etc/haproxy/certs/ouqisheng.org.key /etc/haproxy/certs/ouqisheng.org.crt \> /etc/haproxy/certs/ouqisheng.pem

2、配置haproxy

vim /etc/haproxy/haproxy.cfg

重启服务:

systemctl restart haproxy.service

3、测试结果

添加本地解析:

vim /etc/hosts

测试:

相关推荐
moonless02222 天前
FastAPI框架,这一小篇就能搞懂精髓。
http·fastapi
FPGA_Linuxer3 天前
FPGA 40 DAC线缆和光模块带光纤实现40G UDP差异
网络协议·fpga开发·udp
real 13 天前
传输层协议UDP
网络·网络协议·udp
ftpeak3 天前
从零开始使用 axum-server 构建 HTTP/HTTPS 服务
网络·http·https·rust·web·web app
hsjkdhs3 天前
网络编程之UDP广播与粘包问题
网络·网络协议·udp
00后程序员张3 天前
详细解析苹果iOS应用上架到App Store的完整步骤与指南
android·ios·小程序·https·uni-app·iphone·webview
yzx9910133 天前
接口协议全解析:从HTTP到gRPC,如何选择适合你的通信方案?
网络·人工智能·网络协议·flask·pygame
板鸭〈小号〉3 天前
UDP-Server(3)chat聊天室
网络·网络协议·udp
weixin_456904274 天前
使用HTTPS 服务在浏览器端使用摄像头的方式解析
网络协议·http·https
不会叫的狼4 天前
HTTPS + 域名 + 双向证书认证(下)
https