首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >是否有替代error_page 497选项从nginx为haproxy?

是否有替代error_page 497选项从nginx为haproxy?
EN

Server Fault用户
提问于 2020-07-02 12:44:02
回答 1查看 1.2K关注 0票数 1

当使用nginx时,我可以只使用nginx特有的497错误代码。

发送到HTTPS端口的497个HTTP请求

并使用此规则重定向到https:

代码语言:javascript
运行
复制
error_page 497 https://$host:$server_port$request_uri;

当使用have时,我所知道的唯一解决方案是使用两个端口,例如端口80和443,但我只有一个端口(8443)。

我尝试了errorloc选项,但是当客户端试图连接到https端口时,我会得到一个errorloc选项无法捕获的ssl手动共享错误。

理想情况下,我将使用以下方法,但这不起作用:

代码语言:javascript
运行
复制
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
EN

回答 1

Server Fault用户

回答已采纳

发布于 2020-07-08 22:05:11

经过一些研究发现,这确实可以通过HAProxy来实现(为https和http提供一个端口,并将所有http请求重定向到https)。

我终于在HAProxy论坛上从鲁克斯托找到了一个解决方案。

The下面的示例来自 鲁克斯托:

代码语言:javascript
运行
复制
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

通过添加

代码语言:javascript
运行
复制
redirect scheme https code 301

就像这样的前端-http部分:

代码语言:javascript
运行
复制
frontend fe-http
    mode http
    bind abns@haproxy-http accept-proxy
    redirect scheme https code 301

所有http请求都将重定向到https。

票数 1
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/1023748

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档