HAProxy HTTPS 重定向配置教程
对于 HAProxy,可以通过以下配置实现 HTTPS 的重定向:
frontend https-in
bind *:443 ssl crt /etc/haproxy/certs/mydomain.pem
reqadd X-Forwarded-Proto: \ https
redirect scheme https if !{ ssl_fc }
其中,bind *:443 ssl 表示绑定 443 端口并启用 SSL,crt /etc/haproxy/certs/mydomain.pem 表示使用证书文件进行 SSL 加密。
reqadd X-Forwarded-Proto: \ https 表示添加一个自定义的请求头,用于标识请求使用的协议是 HTTPS。
redirect scheme https if !{ ssl_fc } 表示如果当前请求不是 HTTPS 协议,则进行重定向,将请求协议修改为 HTTPS。
这样就可以实现对 HTTP 请求的自动重定向到 HTTPS 了。
原文地址: https://www.cveoy.top/t/topic/ncoT 著作权归作者所有。请勿转载和采集!