HAProxy 没有将 http 重定向到 https (ssl)

HAProxy not redirecting http to https (ssl)

我正在使用 HAProxy 进行负载平衡,并且只希望我的站点支持 https。因此,我想将端口 80 上的所有请求重定向到端口 443。

我该怎么做?

编辑:我们想重定向到 https 上的相同 url,保留查询参数。因此,http://foo.com/bar would redirect to https://foo.com/bar

 frontend httpfront
    mode http
    bind *:80
    redirect scheme https code 301 if !{ ssl_fc }

您需要为 443 端口配置前端。

前端(80 端口)-> 前端(443 端口)-> 后端

检查我的例子:

frontend httpfront
    mode http
    bind *:80
    redirect scheme https code 301 if !{ ssl_fc }

frontend httpsfront
    mode tcp
    bind *:443
    default_backend app

backend app
    mode tcp
    balance roundrobin
    server server01 10.10.10.11:443 check
    server server02 10.10.10.12:443 check