当使用nginx时,我可以只使用nginx特有的497错误代码。
发送到HTTPS端口的497个HTTP请求
并使用此规则重定向到https:
error_page 497 https://$host:$server_port$request_uri;
当使用have时,我所知道的唯一解决方案是使用两个端口,例如端口80和443,但我只有一个端口(8443)。
我尝试了errorloc
选项,但是当客户端试图连接到https端口时,我会得到一个errorloc
选项无法捕获的ssl手动共享错误。
理想情况下,我将使用以下方法,但这不起作用:
frontend http-in
bind :8443 ssl crt /usr/local/etc/haproxy/ssl/fullchain.pem alpn h2,http/1.1
redirect scheme https code 301 if !{ ssl_fc }
maxconn 50
default_backend backend-server
发布于 2020-07-08 22:05:11
经过一些研究发现,这确实可以通过HAProxy来实现(为https和http提供一个端口,并将所有http请求重定向到https)。
我终于在HAProxy论坛上从鲁克斯托找到了一个解决方案。
The下面的示例来自 鲁克斯托:
frontend port801_combined
mode tcp
bind :801
tcp-request inspect-delay 2s
tcp-request content accept if HTTP
tcp-request content accept if { req.ssl_hello_type 1 }
use_backend recir_http if HTTP
default_backend recir_https
backend recir_http
mode tcp
server loopback-for-http abns@haproxy-http send-proxy-v2
backend recir_https
mode tcp
server loopback-for-https abns@haproxy-https send-proxy-v2
frontend fe-https
mode http
bind abns@haproxy-https accept-proxy ssl crt /etc/ssl/private/unified-cert-file.pem
# whatever you need todo for HTTPS traffic
frontend fe-http
mode http
bind abns@haproxy-http accept-proxy
# whatever you need todo for HTTP traffic
通过添加
redirect scheme https code 301
就像这样的前端-http部分:
frontend fe-http
mode http
bind abns@haproxy-http accept-proxy
redirect scheme https code 301
所有http请求都将重定向到https。
https://serverfault.com/questions/1023748
复制相似问题