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

测试:

相关推荐
liulilittle5 小时前
TCP BBR 拥塞控制模块编译
网络·网络协议·tcp/ip
wangl_926 小时前
Modbus RTU 与 Modbus TCP 深入指南-功能码与数据模型
网络·网络协议·tcp/ip·tcp·modbus·rtu
wangl_927 小时前
Modbus RTU 与 Modbus TCP 深入指南-性能分析与优化
网络·网络协议·tcp/ip·tcp·modbus·rtu
源远流长jerry9 小时前
Linux 网络收包机制:从网卡到 Socket 的完整路径
linux·运维·服务器·网络·网络协议·tcp/ip
上海云盾安全满满9 小时前
选择接入高防IP后,源机是否还要带有防护
网络·网络协议·tcp/ip
treesforest11 小时前
IP地理位置精准查询:从城市级到街道级的定位技术深度解析
大数据·网络·网络协议·tcp/ip·安全·网络安全·ip
江南十四行11 小时前
网络编程基础:TCP/IP与Socket编程详解
网络·python·http
哼?~12 小时前
再谈UDP协议
网络·网络协议·udp
IPHWT 零软网络12 小时前
OM200G-A融合通信IP-PBX:国产化架构下的高可靠政企通信解决方案
网络协议·tcp/ip·架构
路溪非溪13 小时前
BLE MESH基础知识总结
网络·网络协议·智能路由器·射频工程