gpt4 book ai didi

load-balancing - 使用 301 将 http 重定向到 google 云负载均衡器后面的 http(s)

转载 作者:行者123 更新时间:2023-12-04 02:16:16 25 4
gpt4 key购买 nike

我有一个在谷歌云中运行的服务,基本上是谷歌 http(s) 负载均衡器后面的几台机器。我设置了两个平衡规则,一个用于 http://,一个用于 https://。我想做的是将所有 http://请求重定向到 https://。每个节点上都有一个 apache 运行,所以我进行如下配置:

<VirtualHost *:80>
ServerName my.app.com

Redirect permanent / https://my.app.com
</VirtualHost>


<VirtualHost *:443>
ServerName my.app.com
SSLEngine On
....
</VirtualHost>

如果有人正在访问纯 http,这应该会使 apache 返回 301。这工作正常,直到我移动到 google http 负载平衡器后面,从那时起我得到 400 并且:

Bad Request

Your browser sent a request that this server could not understand. Reason: You're speaking plain HTTP to an SSL-enabled server port. Instead use the HTTPS scheme to access this URL, please.

Apache/2.4.10 (Debian) Server at my.app.com Port 443

看起来谷歌负载均衡器使用了 301 并将纯 http 请求重定向到 https 端点,而不是将 301 转发到客户端。我在 google 负载均衡器设置中没有找到任何关于 3XX 转发的设置。有没有人使这种设置工作?

最佳答案

好吧,我会自己回答,也许以后有人会觉得这有用。

目前无法使用Google HTTP Load balancing实现301转发到客户端。负载均衡器将看到 301,并将您的纯 HTTP 请求发送到 301 点所在的地址 - 这是同一台服务器,但端口为 443。您的服务器需要 HTTPS 数据包,但 HTTP 到达,因此失败。

目前对我们有效的解决方案 - 使用 Haproxy 或 Nginx 作为反向代理,而不是 Google HTTP Load Balancer。

关于load-balancing - 使用 301 将 http 重定向到 google 云负载均衡器后面的 http(s),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33521788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com