まあ便利なこと。無料でSSL証明書が発行できるなんて!!
ということでね、Let’s encryptを使って期限が切れたSSL証明書を再発行していきたいと思います。 参考サイトは以下のとおりです。
step1 クライアントソフトのインストール
sudo apt install certbot python3-certbot-nginx
step2 443のポート開放 & ファイアウォールの設定
step3 SSL証明書の発行
sudo certbot certonly
これでインタラクティブに設定できる。聞かれたことを書けばいいだけです。
Saving debug log to /var/log/letsencrypt/letsencrypt.log
How would you like to authenticate with the ACME CA?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Spin up a temporary webserver (standalone)
2: Place files in webroot directory (webroot)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Plugins selected: Authenticator webroot, Installer None
Please enter in your domain name(s) (comma and/or space separated) (Enter 'c'
to cancel): ingenboy.com
Obtaining a new certificate
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/ingenboy.com-0001/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/ingenboy.com-0001/privkey.pem
Your cert will expire on 2023-08-22. 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
step4 nginx or apacheの設定を変更する。
nginxが証明書にアクセスできるようにパスをnginx.confに書き込むわけですね。はい、以上。
2023/08/24追記
はい、この記事の投稿から3ヶ月が立ってからの追記ということで、証明書が切れたということですね。 更新に当たり新しく学ぶことがありました。上にも書いてあるけど、standaloneとwebrootは違うんですね。 standaloneはcertbotがwebserverとして働き、外部とやり取りをするんですね。そのときに443ポートと80版ポートを専有しないと行けないんです。でもnginxが動いていると、standaloneサーバが443と80を使えないですよね。そんな時は、webrootでssl証明書を発行しないと行けなかったということです。 はい。そして、更新のときはcertbot renewで自動で更新してくれるみたいですね。あとは、そうですね。最後にnginxをrestartするのを忘れないでください。鍵の変更が反映されないので。
追記
証明書の更新は sudo certbotだけでも行けます。それで、今動いてるやる、もしくは過去に登録されたやつでどれを更新したいかを聞かれるので後はその通りにやるだけです。
さらに追記
なんでか知らんけど、nginxが動いていて、webrootでやるとうまくいかないことがあるんだよね。まあ、一瞬で終わるので、nginxを一回stopして、standaloneでやるので十分だと思います。