0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SSL証明書(Let's Encrypt)の有効期限が切れた場合

Last updated at Posted at 2025-03-03
../

VPSサーバー(CentOS Stream 8)を3か月以上停止したまま放置していたら、Let's Encrypt のSSLサーバー証明書の有効期限が切れてしまった。再度、設定した。その手順をメモしておく。

古い証明書の退避とサービス停止

ドメインは仮に「kankeri.com」とする。古い証明書を一旦退避し、httpdとtomcat9のサービスを停止しておく。これらのサービスが動作しているとcertbotの実行時にエラーになる。

$ cd /etc/letsencrypt/renewal/
$ cd /etc/letsencrypt/live
$ ls
$ mkdir bak
$ mv kankeri.com bak
 
$ systemctl stop httpd 
$ systemctl stop tomcat9

certbotの実行

certbotを実行して「kankeri.com」を指定する。「kankeri.com-0001」という新たなフォルダで鍵などが生成される。

$ certbot certonly --standalone

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Please enter the domain name(s) you would like on your certificate (comma and/or
space separated) (Enter 'c' to cancel): kankeri.com
Requesting a certificate for kankeri.com

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/kankeri.com-0001/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/kankeri.com-0001/privkey.pem
This certificate expires on 2025-06-01.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

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

フォルダの変更

「kankeri.com-0001」というフォルダは嫌なので「kankeri.com」に戻しておきたい。いくつかのフォルダ名、ファイル、シンボリックリンクを修正する必要がある。/etc/letsencrypt/ 配下のarcive,live,renewalを修正する。退避したbakも削除しておく。

$ cd /etc/letsencrypt/
$ ls
archive
live
renewal

$ cd archive					// (1) archive配下を変更
$ ls
$ rm -rf kankeri.com
$ mv kankeri.com-0001/ kankeri.com

$ cd ../renewal					// (2) renewal配下を変更
$ ls
$ rm kankeri.com.conf
$ mv kankeri.com-0001.conf kankeri.com.conf
$ vi kankeri.com.conf			//「-0001」を削除して保存すること

# renew_before_expiry = 30 days
version = 3.2.0
archive_dir = /etc/letsencrypt/archive/kankeri.com-0001
cert = /etc/letsencrypt/live/kankeri.com-0001/cert.pem
privkey = /etc/letsencrypt/live/kankeri.com-0001/privkey.pem
chain = /etc/letsencrypt/live/kankeri.com-0001/chain.pem
fullchain = /etc/letsencrypt/live/kankeri.com-0001/fullchain.pem
# Options used in the renewal process

$ cd ../live					// (3) live配下を変更
$ ls
$ rm -rf bak
$ mv kankeri.com-0001/ kankeri.com
$ cd kankeri.com
$ rm -rf cert.pem
$ rm -rf chain.pem
$ rm -rf fullchain.pem
$ rm -rf privkey.pem
$ ln -s  ../../archive/kankeri.com/cert1.pem cert.pem
$ ln -s  ../../archive/kankeri.com/chain1.pem chain.pem
$ ln -s  ../../archive/kankeri.com/fullchain1.pem fullchain.pem
$ ln -s  ../../archive/kankeri.com/privkey1.pem privkey.pem

フォルダやシンボリックリンクの変更は冗長で面倒だけど、httpd.conf などは変更しなくていいので、こっちの作業の方がすっきりすると思う。

サービスの再開と確認

サービスを再開させ、「 https://www.ssllabs.com/ssltest/analyze.html?d=kankeri.com 」でSSL接続を確認する。またブラウザから実際に「 https://kankeri.com 」に接続して確認する。Chromeからだと「保護されていない接続」にはなるけど「証明書は有効です」となる。

$ systemctl start httpd 
$ systemctl start tomcat9

以上

../
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?