LoginSignup
7
6

More than 3 years have passed since last update.

Let's Encryptの更新エラーを解決した。

Posted at

SSLの証明書の有効期限切れでサイトにアクセスできなくなり、更新をしようとしたらエラーになってしまったので、その時の解決方法を残します。

この接続ではプライバシーが保護されません

サイトにアクセスしたら上記のメッセージが表示され、サイトが見れない。

SSLの証明書の有効期限が切れていたのが原因だった。

Let's EncryptでSSL化したが、その際に行った自動更新の設定がうまくいっていなかったよう。

Let's Encryptの更新

更新のチェック

$ cd /usr/local/certbot

# 更新ができるかチェック
$ ./certbot-auto renew --dry-run

Challenge failed for domain xxx.com
http-01 challenge for xxx.com
Cleaning up challenges
Attempting to renew cert (xxx.com) from /etc/letsencrypt/renewal/xxx.com.conf produced an unexpected error: Some challenges have failed.. Skipping.
All renewal attempts failed. The following certs could not be renewed:
  /etc/letsencrypt/live/xxx.com/fullchain.pem (failure)

could not be renewedとあるので、どうやら失敗したようです。

./certbot-autoとcertbot

certbot-autoを"wget" や "git clone" コマンドなどでダウンロードした場合は./certbot-autoを使う。
OS のパッケージ管理システムから Certbot パッケージをインストールした場合はcertbotコマンドを入力します。

--dry-run

実際に更新はかけずに、チェックのみ実行する機能

Let's Encryptでは何度も証明書の発行に失敗をすると、制限がかかってしまい、しばらく発行ができなくなってしまいます。
実際に更新をする前に、--dry-runをつけて問題がないかチェックしましょう。

nginxの設定変更

$ sudo vi /etc/nginx/conf.d/hogehoge.conf
  server {
    listen 80;
# 以下追記
    location ^~ /.well-known/acme-challenge/ {
        default_type "text/plain";
        root         /var/www/hogehoge/current/public; #ドキュメントルート
    }

    return 301 https://$host$request_uri; #リダイレクト用
  }

設定の反映

$ systemctl reload nginx

証明書更新

$ cd /usr/local/certbot

$ ./certbot-auto certonly --webroot -w /var/www/hogehoge/current/public -d www.hogehoge.com --agree-tos -n
Congratulations! Your certificate and chain have been saved at:

更新成功しました!

心配な方は更新前に以下のコマンドでチェックをしておきましょう。

$ ./certbot-auto renew --dry-run

オプション

--webroot :サーバーを止めずに証明書を更新するためのもの
-w :ドキュメントルートを指定
-d :ドメインを指定
--agree-tos :ACME 利用規約に同意
-n:ユーザーからの入力が不要
参考:https://free-ssl.jp/command/

設定の反映

$ systemctl reload nginx

サイトが無事に表示されるようになりました!

参考

https://free-ssl.jp/
https://qiita.com/HeRo/items/f9eb8d8a08d4d5b63ee9
https://qiita.com/shozzy/items/372bb9e4a76076d7021e
https://server-recipe.com/1577/#Letsencrypt-3

7
6
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
7
6