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

测试:

相关推荐
keepquietl1 小时前
UDS on CAN 入门(6):诊断响应要等多久?读懂 P2、P2* 和 S3
网络·网络协议
BIBI20491 天前
HTTPS 证书的核心原理解释
网络安全·https·ssl/tls·入门指南·web 开发
郝学胜-神的一滴1 天前
Effective STL 条款12:对容器线程安全性的现实期望
c语言·开发语言·c++·qt·网络协议·rpc·numpy
FakeOccupational2 天前
fpga系列 HDL : 选择RAM IP(Two Port IP核) 乒乓缓冲(Ping-Pong Buffer)工作流程
网络协议·tcp/ip·fpga开发
爱和冰阔落2 天前
【Linux网络】GET 和 POST 真的只是参数位置不同吗?从 HTTP 请求方法、抓包分析到长连接与路由实战
linux·c++·http·网络编程·get与post
可涵不会debug2 天前
ChatServer 模块学习笔记:HTTP 接入层、多线程与流式响应
笔记·学习·http
laozhang7002 天前
自己动手写一个 WebSocket 调试工具:告别广告与限制
网络·websocket·网络协议
AndreaYYmm3 天前
AF_PACKET 原始套接字抓包实战:手写一个 mini-tcpdump
c语言·网络协议
捷焱GEO3 天前
用本地 HTTP 用例验证旧活动页的退役状态
网络·网络协议·http·seo
AllData公司负责人3 天前
实战二:AllData大模型与AI数据底座-数据传输平台-DBSyncer,搭建 Http 接口同步至 Doris,API 业务数据自动拉取入数仓
大数据·数据库·数据仓库·人工智能·算法·http·doris