さくらVPS Debian jessie に Certbot で SSL/TLS を導入してみた

PC
スポンサーリンク

Google が https 対応したサイトを検索順位に優遇すると発表したことで、うちのサイトも対応しないとなーと思っていました。

調べていると、最近は証明書も無料で取得できるところもあったりするので、時代の流れを感じます。

今回は、Let’s Encrypt で証明書を取得します。

期間が3ヶ月間しかありませんが、「Certbot」というプログラムを使うことで、自動で更新をしてくれます。

さらに、そのプログラムで簡単に https サイトを構築してくれますので、とても簡単です。

[q3-adsense01]

スポンサーリンク

SSL/TLS を導入したサーバ

VPSサーバ さくらVPS
OS Debian jessie
Webサーバ apache
公開済み独自ドメイン数 11

今回は、1ページのみ静的サイトを https 化しました。相対リンクしかなかったので、リンク修正はありません。

CMS などに関しては次回チャレンジしたいと思います。

Certbot クライアントのインストール

「certbot」 と、 apacheCertbot クライアントを使うために、「python-cert-apache」プラグインをインストールします。

jessie では、Certbotjessie-backports リポジトリにしか入っていません。

apt に jessie-backports の設定

(うちのさくらVPS Debian jessie では、aptitude で管理しています。昔の名残です。)

~$ sudo aptitude update
~$ sudo aptitude install certbot python-certbot-apache -t jessie-backports
パッケージリストを読み込んでいます... 完了
E: APT::Default-Release の 値 'jessie-backports' は、そのようなリリースをソース中から利用できないため、無効です
~$

まだ jessie-backport リポジトリが入っていませんでした。

ですので、リポジトリを追加します。

~$ sudo vim /etc/apt/sources.list
[/etc/apt/sources.list]

# jessie-backports
deb http://ftp.debian.org/debian jessie-backports main

インストール

~$ sudo aptitude update
~$ sudo aptitude install certbot python-certbot-apache -t jessie-backports
以下の新規パッケージがインストールされます:
  augeas-lenses{a} certbot libaugeas0{a} python-acme{a} python-augeas{a} 
  python-certbot{a} python-certbot-apache python-cffi-backend{a} 
  python-chardet{a} python-configargparse{a} python-configobj{a} 
  python-cryptography{a} python-dnspython{a} python-enum34{a} 
  python-funcsigs{a} python-idna{a} python-ipaddress{a} python-mock{a} 
  python-ndg-httpsclient{a} python-openssl{a} python-parsedatetime{a} 
  python-pbr{a} python-pkg-resources{a} python-psutil{a} python-pyasn1{a} 
  python-pyicu{a} python-requests{a} python-rfc3339{a} python-setuptools{a} 
  python-six{a} python-tz{a} python-urllib3{a} python-zope.component{a} 
  python-zope.event{a} python-zope.interface{a} 
更新: 0 個、新規インストール: 35 個、削除: 0 個、保留: 45 個。
2,971 k バイトのアーカイブを取得する必要があります。展開後に 14.0 M バイトのディスク領域が新たに消費されます。
先に進みますか? [Y/n/?] 

このまま進んでインストールは完了です。

SSL/TLS サーバ証明書の取得

コマンドを実行して証明書を取得していきます。

Certbot の起動とドメインの選択

Certbot を起動します。

~$ sudo certbot
Saving debug log to /var/log/letsencrypt/letsencrypt.log

Which names would you like to activate HTTPS for?
-------------------------------------------------------------------------------
1: hogehoge1.com
2: hogehoge2.com
3: hogehoge3.com
4: hogehoge4.top
5: hogehoge5.com
6: hogehoge6.com
7: hogehoge7.com
8: hogehoge8.com
9: hogehoge9.com
10: hogehoge10.com
11: hogehoge11.com
-------------------------------------------------------------------------------
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel):

このサーバでは11個のドメインを運用しています。(ドメイン名は伏せています)

すべてのドメインをまとめて認証書を発行する場合は、何も入力せずにエンターを押してください。

今回は、5番目のドメインの認証書を発行しました。

管理用メールアドレスの入力(初回のみ)

Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel):

初回のみ管理用メールアドレスの入力を求められます。

緊急の通知、鍵を紛失したときの復旧、証明書の有効期限が近付いた場合の通知に使用されるそうです。

利用規約への同意 (初回のみ)

Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org

-------------------------------------------------------------------------------
Please read the Terms of Service at
404 Page not found - Let's Encrypt
Let's Encrypt is a free, automated, and open certificate authority brought to you by the nonprofit Internet Security Research Group (ISRG). Read all about our n...
You must agree in order to register with the ACME server at
https://acme-v01.api.letsencrypt.org/directory
------------------------------------------------------------------------------- (A)gree/(C)ancel:

PDF や ページを確認して問題がなければ、「a」を入力します。

常時 SSL/TLS 化設定

Please choose whether HTTPS access is required or optional.
-------------------------------------------------------------------------------
1: Easy - Allow both HTTP and HTTPS access to these sites
2: Secure - Make all requests redirect to secure HTTPS access
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):

証明書を発行するドメインを、http と https 両方見れるようにするか、常時 https に飛ぶかの選択です。

今回は常時 https にしますので、「2: Secure」を選択しました。

SSL/TLS サーバ証明書の取得完了

-------------------------------------------------------------------------------
Congratulations! You have successfully enabled https://hogehoge5.com

You should test your configuration at:
SSL Server Test: hogehoge5.com (Powered by Qualys SSL Labs)
------------------------------------------------------------------------------- IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/hogehoge5.com/fullchain.pem. Your cert will expire on 2017-11-23. To obtain a new or tweaked version of this certificate in the future, simply run certbot again with the "certonly" option. To non-interactively renew *all* of your certificates, run "certbot renew" - If you lose your account credentials, you can recover through e-mails sent to foo@hogehoge5.com. - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le ~$

これで完了です。

サイト確認

https になるか、普通にサイトを開いてみましょう。

http:// でアクセスしても、無事に https:// になっていました。

きちんと「保護された通信」になっていますね。

証明書の保存先

証明書は /etc/letsencrypt/archive/ドメイン名/ に保存されています。

~$ sudo ls -al /etc/letsencrypt/archive/hogehoge5.com/
合計 24
drwxr-xr-x 2 root root 4096  8月 26 07:01 .
drwx------ 3 root root 4096  8月 26 07:01 ..
-rw-r--r-- 1 root root 1793  8月 26 07:01 cert1.pem
-rw-r--r-- 1 root root 1647  8月 26 07:01 chain1.pem
-rw-r--r-- 1 root root 3440  8月 26 07:01 fullchain1.pem
-rw-r--r-- 1 root root 1704  8月 26 07:01 privkey1.pem
~$

Certbot で再度証明書を取得すると、上書きされるのではなく数字が増えて別に保存されます。

ですので、この証明書を使いたい場合はシンボリックリンクのリンク先を指定します。

~$ sudo ls -al /etc/letsencrypt/live/hogehoge5.com/
合計 12
drwxr-xr-x 2 root root 4096  8月 26 07:01 .
drwx------ 3 root root 4096  8月 26 07:01 ..
-rw-r--r-- 1 root root  543  8月 26 07:01 README
lrwxrwxrwx 1 root root   38  8月 26 07:01 cert.pem -> ../../archive/hogehoge5.com/cert1.pem
lrwxrwxrwx 1 root root   39  8月 26 07:01 chain.pem -> ../../archive/hogehoge5.com/chain1.pem
lrwxrwxrwx 1 root root   43  8月 26 07:01 fullchain.pem -> ../../archive/hogehoge5.com/fullchain1.pem
lrwxrwxrwx 1 root root   41  8月 26 07:01 privkey.pem -> ../../archive/hogehoge5.com/privkey1.pem
~$

Certbot で取得するたびに新しい証明書にリンクし直されますので、ファイル設定での書き換えが不要になりますね。

 

[q3-adsense01]

Google アナリティクスの設定

http が https に変わると、アドレスが変わって別サイトと認識されていまします。

Google アナリティクスを使っている方は、こちらの設定を見直す必要があります。

Redirecting...

プロパティ設定

①サイドメニューの「管理」をクリックします。

②「プロパティ設定」をクリックします。

「デフォルトのURL」を「https://」に変更します。

一番下の「保存」をクリックして完了です。

ビュー設定

「ビュー設定」をクリックします。

「ウェブサイトのURL」を「https://」に変更します。

一番下の「保存」をクリックして完了です。

サーチコンソールの新規追加

Google Search Console を使っている人はサイトを新たに登録する必要があります。

Google アナリティクスの「プロパティ設定」にリンクがありますので、そこからサイトに飛びましょう。

関連付けがない状態になっていますので、編集をクリックします。

Search Consoleにサイトを追加」をクリックします。

Search Console のサイトに飛びますので、「プロパティを追加」をクリックします。

URL を入力して、「追加」ボタンをクリックします。

これで完了です。

言語設定や、サイトマップを忘れずに上げておいてください。

さいごに

今回は静的サイトを SSL/TLS 化してみました。

Certbot を使うことで簡単に出来ましたね。

しかし、他のサイトは WordPress を使用しているものが多く、常時 SSL/TLS 化すると、リンクの不具合が心配になります。

次回はその部分もきちんと対応できるように、Wordpress を使ったサイトも常時 SSL/TLS 化してみようと思います。

参考

Let’s Encrypt の使い方

 

[q3-adsense01]

PC
スポンサーリンク
なもをフォローする
スポンサーリンク
Q3

コメント

  1. […] さくらVPS Debian jessie に Certbot で SSL/TLS を導入してみた […]