使用GCP负载平衡器将静态网站重定向HTTP到HTTPS [英] Static Website Redirect HTTP to HTTPS with GCP Load Balancer with

查看:86
本文介绍了使用GCP负载平衡器将静态网站重定向HTTP到HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将我的网站从 http重定向到https ,我在Google Cloud Storage Bucket中的静态网站指向http&启用了https.

I need to redirect my website from http to https, I have my static website in Google Cloud Storage Bucket pointed to Load Balance with http & https enabled.

示例:

http://ex.com => https://ex.com
http://www.ex.com =>

http://ex.com = > https://ex.com
http://www.ex.com = > https://www.ex.com

https://ex.com

The https://ex.com, https://www.ex.com both work just fine, however, I just need the http redirect so that I can reach Secure Service

由于我拥有一个静态网站,所以我希望只能在负载平衡"中处理此问题,有人可以帮助我解决这个问题.

Since I am having a static website I hope I can only handle this in Load Balance, Can some one help me with this.

推荐答案

目前,这无法通过Google HTTP负载均衡器功能实现. 此处.

At this time, this is not possible via a Google HTTP Load Balancer feature. There is a feature request here.

您可以将JavaScript添加到页面中.但是,这不能保证HTTPS重定向.通常,只需将其添加到主页和几个关键页面即可获得大部分HTTPS流量.

You could add JavaScript to your pages. However, this will not guarantee HTTPS redirection. Usually, just adding this to the home page and a few key pages will get most of your traffic to HTTPS.

<script type="text/javascript">
  if (location.protocol != 'https:')
  {
   location.href = 'https:' + window.location.href.substring(window.location.protocol.length);
  }
</script>

这篇关于使用GCP负载平衡器将静态网站重定向HTTP到HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆