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

测试:

相关推荐
googleccsdn11 分钟前
ENSP Pro Lab笔记:配置STP/RSTP/MSTP(7)
网络·笔记·网络协议
该用户已不存在2 小时前
免费 SSL 证书缩短至 90 天,你的运维成本还能hold住吗
前端·后端·https
L***B5682 小时前
Nginx代理到https地址忽略证书验证配置
运维·nginx·https
Macbethad3 小时前
DeviceNet主站程序技术方案
网络协议·信息与通信
多多*3 小时前
Threadlocal深度解析 为什么key是弱引用 value是强引用
java·开发语言·网络·jvm·网络协议·tcp/ip·mybatis
盛满暮色 风止何安3 小时前
WAF的安全策略
linux·运维·服务器·网络·网络协议·安全·网络安全
k***85844 小时前
Nginx中$http_host、$host、$proxy_host的区别
运维·nginx·http
伞啊伞5 小时前
nginx https ssl证书
nginx·https·ssl
CodeByV6 小时前
【网络】HTTP协议深度解析:从请求响应到Cookie/Session
网络·网络协议·http
bloglin999996 小时前
gitlab内网配置https配置加载异常
网络协议·https·gitlab