Cloud中将http重定向到https

Cloud中将http重定向到https

本文介绍了在Google Cloud中将http重定向到https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一个负载平衡器,该负载平衡器接受来自用户的https连接。然后使用http连接将计算引擎连接到负载均衡器。

I have setup a load balancer which accepts https connections from users. The compute engines are then connected to load balancer using http connection.

我已经在根文件夹中写入了以下.htaccess文件:

I have written the following .htaccess file in the root folder:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

现在,问题是,计算引擎始终通过http连接链接(到负载平衡器)而不是https。

Now, the problem is, the compute engine is always connected via http link (to the load balancer) and not https.

因此,即使url以https开头,.htaccess文件始终认为连接是http而不是https。因此,即使URL是https,它也会陷入无限循环尝试将用户发送到https。

Thus, the .htaccess file always consider the connection to be http and not https even if the url starts with https. So, it goes in an infinite loop trying to send the user to https even when the url is https.

在这种情况下,应该执行些什么将http重定向到https。

What should be done to redirect http to https in this case.

谢谢。

推荐答案

您应检查X-Forwarded- Proto HTTP标头。由负载均衡器设置,其值为http或https。

You should check the X-Forwarded-Proto http header. It is set by the load balancer and will have the value http or https.

这篇关于在Google Cloud中将http重定向到https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 20:01