後來改由 firebase deploy 了,原因出在於 google loadbalancer 無法自動將 http 導到 https 的緣故,必須要自己設定後端的 web server 丟出 301 redirect。

原本的架構,是在 google loadbalancer 後端 service 指定為 cloud stoage,並且把 80 port and 443 port 設定到同一個 ip,所以這會造成使用者透過 http 進來的話,並不會自動導到 https,只能在 hexo 的 theme 裡面去加入類似像下方 script 去做 client 端的 redirect:

1
2
3
4
5
6
<!-- redirect to https via client -->
<script type="text/javascript">
var host = "yoursite.com";
if ((host == window.location.host) && (window.location.protocol != "https:"))
window.location.protocol = "https";
</script>

但是這樣做不對,因為 google bot 來爬網頁的話,如果他爬 http 的話,就會因為你的 website 不提供 SSL 而分數較低,除非你的 web server 有丟出 301 status code 讓 google bot 導到 https。

所以要怎麼處理 static page 的 SSL 呢?有幾個方式

  1. 自己架 web server,不放在 cloud storage 上
  2. 放在 cloud storage 上,改由 cloudflare 幫你做 DNS 的 SSL
  3. 像我一樣,放棄 cloud storage 的 deploy 方式,改由 firebase hosting

firbase 的 hosting 可以幫你 renew SSL,而且還可以自動幫你處理 CDN,非常的適合像是 hexo 這種 static blog。所以最後就改由 firebase deploy 啦~