11
11

More than 5 years have passed since last update.

GitHub PagesでSSL(HTTPS)に対応する

Last updated at Posted at 2015-08-25

1) s/http/https/ の置換

まずソースに書かれたhttp://の部分をhttps://に置換します。ただし、外部スクリプトの一部はhttpでしか動かないものもあるので注意。

次に、<head>内に以下を追記。環境変数はjekyllのものです。

head.html
<link rel="canonical" href="{{ site.url }}{{ page.url }}" />

jekyllの場合は、設定ファイルも例外なくhttpの部分はhttpsに書き換えます。

_config.yml
site.url = https://syui.github.io

2) http > httpsへのリダイレクト処理

次に、httphttpsにリダイレクトする処理をjavascriptで書きます。以下は、jekyllでの記述の仕方です。

head.html
<script type="text/javascript">
{% if site.enforce_ssl %}
    var enforce = "{{ site.enforce_ssl }}";
    if ((enforce == window.location.host) && (window.location.protocol != "https:"))
    window.location = window.location.toString().replace(/^http:/, "https:");
{% else %}
    var host = "syui.github.io";
    if ((host == window.location.host) && (window.location.protocol != "https:"))
    window.location.protocol = "https";
{% endif %}
</script>
_config.yml
site.enforce_ssl = syui.github.io

参考

enforce SSL on production domain

3) EV SSL

ついでに関係ありませんがEV SSLの話をします。これを導入すると、アドレスバーが緑色になります。FirefoxやChromeなど。

SSLサーバ証明書には、信頼性の高い順に、「EV SSL証明書」「企業認証(OV)証明書」「ドメイン認証(DV)証明書」という種類があります。

これらは、SSL証明書を購入して登録しなければなりません。

GeoGetSSLがおすすめらしいです。

以下の記事が登録までの手順を詳しく説明してくれています。

年額8.85ドル(約1,100円)の SSLサーバ証明書「RapidSSL」を試してみる

11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11