Let's EncryptでHTTPS化しようとしたらCertbotで簡単に出来た記録
久しぶりに Let’s Encrypt でウェブサイトを HTTPS 化したのだが、昔とはかなり変わっていたのでメモ代わりに書いておく。
いきなり結論書いておくと Certbot で簡単に出来る。
1. 環境
- OS
- Linux
- Ubuntu 22.04
- Linux
- Webサーバ
- Apache 2.4.52
2. snapd インストール
Linux では snapd でやるのがおすすめと公式ドキュメントにあるので、それに沿って進めてみる。
まずは snapd のインストール。
$ sudo apt update
$ sudo apt install snapd
公式ドキュメントに沿って snapd がちゃんと動作しているか確認する。
$ sudo snap install hello-world
(中略)
$ hello-world
Hello World!
大丈夫っぽいね。
3. Certbot インストール
今度は Certbot 本体をインストールする。
$ sudo snap install --classic certbot
certbot 4.0.0 from Certbot Project (certbot-eff✓) installed
$ sudo ln -s /snap/bin/certbot /usr/bin/certbot
$ certbot --version
certbot 4.0.0
パスもちゃんと通ってるね。
4. Certbot 実行
ついに Certbot で HTTPS 化してみる。
$ sudo certbot --apache
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address or hit Enter to skip.
(Enter 'c' to cancel):
メールアドレスを聞かれるけど、何も入力せずエンターで進めてみる。
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at:
https://letsencrypt.org/documents/LE-SA-v1.5-February-24-2025.pdf
You must agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y
規約への同意を求められるので y で同意する。
Account registered.
Which names would you like to activate HTTPS for?
We recommend selecting either all domains, or all domains in a VirtualHost/server block.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: site1.example.com
2: site2.example.com
3: site3.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel):
Certbot が自動で Apache の設定をチェックして、対象になるバーチャルホストの候補をリスト化して出してくれる。
今回はすべて HTTPS 化するので、何も選択せずにエンターで進める。
Requesting a certificate for example.com and 2 more domains
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/example.com/fullchain.pem
Key is saved at: /etc/letsencrypt/live/example.com/privkey.pem
This certificate expires on 2025-08-16.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
Deploying certificate
Successfully deployed certificate for site1.example.com to /etc/apache2/sites-available/site1.example.com-le-ssl.conf
Successfully deployed certificate for site2.example.com to /etc/apache2/sites-available/site2.example.com-le-ssl.conf
Successfully deployed certificate for site3.example.com to /etc/apache2/sites-available/site3.example.com-le-ssl.conf
Congratulations! You have successfully enabled HTTPS on https://site1.example.com, https://site2.example.com, and https://site3.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/etc/apache2/site-available/ 以下に HTTPS 化した設定ファイルが作られ、ちゃんと/etc/apache2/site-enable からリンク貼られてた。
もともとの HTTP 用の設定ファイルに HTTPS へのリダイレクト設定も自動的に入ってた。
5. 自動更新チェック
Certbot は ACME での自動更新がウリなので、ちゃんと動くかチェックする。
$ sudo certbot renew --dry-run
Saving debug log to /var/log/letsencrypt/letsencrypt.log
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/example.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Account registered.
Simulating renewal of an existing certificate for site1.example.comand 2 more domains
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all simulated renewals succeeded:
/etc/letsencrypt/live/example.com/fullchain.pem (success)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
更新成功している。
念の為 90 日後に再チェックすること。
6. HTTPS でアクセスしてみる
アクセスできたら設定完了、お疲れ様。
実はファイアウォールで 443 ポート開けてなかったので、しばらく悩んでしまったのは秘密だ。
いやー Certbot がかなり進化していて、ほとんど何もすることがなかった。
便利な時代だね。