世の中のWebサイトはHTTPSが主流となっていますので、自分のサイトもそろそろHTTPS化しようと思い実施しました。
認証局どうすっかなあと思っていたところDegital OceanにHow toがあったので、Let's Encryptにしました。
無料だし、助かります。
ちなみにサーバにログインするとこんなバナーも出ます。
If you'd like to use Let's Encrypt to create an SSL for this site, please see: http://do.co/le-apache for instructions
ついにHTTPS化に手を出す
手順に沿って設定
masashi@wordpress-s-1vcpu-1gb-sgp1-01:~$ sudo add-apt-repository ppa:certbot/certbot
masashi@wordpress-s-1vcpu-1gb-sgp1-01:~$ sudo apt-get update
masashi@wordpress-s-1vcpu-1gb-sgp1-01:~$ sudo certbot --apache -d dayoff.palomablog.com
サーバネームも設定済みです。
masashi@wordpress-s-1vcpu-1gb-sgp1-01:~$ sudo find /etc/apache2/* -type f | xargs grep ServerName /etc/apache2/sites-available/000-default.conf: ServerName dayoff.palomablog.com /etc/apache2/sites-available/000-default.conf.dpkg-dist: # The ServerName directive sets the request scheme, hostname and port that /etc/apache2/sites-available/000-default.conf.dpkg-dist: # redirection URLs. In the context of virtual hosts, the ServerName /etc/apache2/sites-available/000-default.conf.dpkg-dist: #ServerName www.example.com
これだけ。
といった作業は一切なく、コマンド数発で完了です。
認証の際にLet's Encryptのサーバからドメイン名の名前解決ができることが条件のようなので、ワイルドカードとかはできなさそうです。
- palomablog.comの証明書も入れておこうと思たらエラーになった。
masashi@wordpress-s-1vcpu-1gb-sgp1-01:~$ sudo certbot --apache -d palomablog.com -d dayoff.palomablog.com Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator apache, Installer apache Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): smasa619@gmail.com Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org (略) (Y)es/(N)o: y Starting new HTTPS connection (1): supporters.eff.org Obtaining a new certificate Performing the following challenges: http-01 challenge for dayoff.palomablog.com http-01 challenge for palomablog.com Waiting for verification... Cleaning up challenges Failed authorization procedure. palomablog.com (http-01): urn:ietf:params:acme:error:unknownHost :: The server could not resolve a domain name :: No valid IP addresses found for palomablog.com IMPORTANT NOTES: - The following errors were reported by the server: Domain: palomablog.com Type: unknownHost Detail: No valid IP addresses found for palomablog.com To fix these errors, please make sure that your domain name was entered correctly and the DNS A/AAAA record(s) for that domain contain(s) the right IP address. - 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.
Let's Encryptの有効期限は90日なので期限切れまでに更新が必要なのですが、これも大丈夫かな?
本来はcronに書いておくらしいのですが、これたたけばOKらしいです。
masashi@wordpress-s-1vcpu-1gb-sgp1-01:~$ sudo certbot renew --dry-run
インストールしたcertbotがsystemdタイマーを使ってrenewを1日2回実行してくれる、と書いてありますね。
不具合は期日が来てみないとわかりませんね。
(ログ見れば確認できそうですが別途)
httpからのリダイレクトをONにするかとあったので、有効にしておきました。
本当は不要となる80ポートは閉じるべきですが、影響が見切れず、壊れるのも嫌なので一旦ONにしています。
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: No redirect - Make no further changes to the webserver configuration. 2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS. You can undo this change by editing your web server's configuration. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2 Redirecting vhost in /etc/apache2/sites-enabled/000-default.conf to ssl vhost in /etc/apache2/sites-available/000-default-le-ssl.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://dayoff.palomablog.com
アクセスしてみる
アクセスしてみたところ、レイアウトが崩れてしまいました。
サーバが参照するパスも変えないといけないのでそりゃそうですね。
URLをHTTPSに変更。
画像周りのパスは特に変えなくても動きに問題ありませんでしたが、これはリダイレクトが効いているのかな? ちなみに画像拡大の処理が遅いのもこれが怪しいですね。
とりあえず無事にHTTPS化できてよかったです。
(と思ったら、ヘッダ画像が表示されていない…後で直します)
コマンド数ステップで簡単でした
個人の趣味サイトだからできることですが、Let's Encryptを使って無料かつ簡単に証明書取得&配置ができました。
今どきのVPSはこういう作業も自動化で便利にできるようになっていますが、
だからこそ仕組みを知っておかないとトラブル時に対処できなくなってしまいますね。