Let's Encryptの証明書を更新する

動機

前回Let’s Encryptを使ったSSL証明書の作成を行いました。そのときに、2020年8月4日には有効期限が切れてしまうようですと言っていたにもかかわらず更新をするのを忘れていました…

なので、今回は更新作業を行いたいと思います。

SSL証明書の更新作業

前回も記載していましたが、

1
2
3
Your cert will expire on 2020-08-04. To obtain a new or tweaked
version of this certificate in the future, simply run certbot again
with the "certonly" option.

ということなので、certonlyオプションをつけて実行したいと思います。

1
2
3
4
5
6
7
8
9
10
$ sudo certbot certonly --nginx
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: book-reviews.blog
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel):

一つしかドメインがないですが、選択する必要があるので1を入力してエンターキーを押します。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
1: book-reviews.blog
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1
Cert is due for renewal, auto-renewing...
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for book-reviews.blog
Waiting for verification...
Challenge failed for domain book-reviews.blog
http-01 challenge for book-reviews.blog
Cleaning up challenges
Some challenges have failed.

IMPORTANT NOTES:
- The following errors were reported by the server:

Domain: book-reviews.blog
Type: dns
Detail: During secondary validation: DNS problem: networking error
looking up A for book-reviews.blog

なぜか失敗してしまっているようです。原因も記載されていますね。

1
Detail: During secondary validation: DNS problem: networking error looking up A for book-reviews.blog

ドメインの名前解決中にネットワークエラーが発生したという感じでしょうか…

原因が不明なので再度実行してみます。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$ sudo certbot certonly --nginx
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: book-reviews.blog
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1
Cert is due for renewal, auto-renewing...
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for book-reviews.blog
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/book-reviews.blog/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/book-reviews.blog/privkey.pem
Your cert will expire on 2020-11-03. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"certbot renew"
- 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

今回はなぜかうまく行きました。

動作確認

ブラウザでアクセスしてみます。すると、まだ「保護されていない通信」として警告が出ています。証明書を確認すると、有効期限が更新されていませんでした。

証明書を更新したらnginxの再起動が必要ですね。再起動します

1
$ sudo systemctl restart nginx

証明書が更新され、有効期限が2020年11月4日になりました。これで証明書の更新は終わりです、が、なぜかChromeで見たときの「保護されていない通信」という警告はまだ残っています…なぜなのでしょうか…

原因調査

こちらに調査方法が詳しく記載されていました。

デベロッパーツールを立ち上げ、Securityを選択します。
Security overviewを確認すると、証明書やコネクションに関してはグリーンになっていますが、Resourcesがレッドになっています。
メッセージを見ると

1
2
Resources - active content with certificate errors
You have recently allowed content loaded with certificate errors (such as scripts or iframes) to run on this site.

ということでした。証明書を更新する前の、有効期限が切れている状態でサイトへのアクセスを許可したために警告が消えないようです。

ということは、証明書の更新とは関係ありませんでした。試しに別のブラウザで表示したところ問題ありませんでした。

まとめ

  • Let’s Encryptの証明書更新を行うにはcertonlyオプションをつけて実行する
  • 更新した証明書を反映するにはWebサーバの再起動が必要
  • 証明書の期限が切れた状態で、サイトへのアクセスを許可すると、証明書更新後も「保護されていない通信」が解除されない。

次回また2020年11月に行います。次はもっとスムーズにできると思います。