0
0

Let’sEncryptでLet’s SSL対応

Posted at

こんにちは、堀井です。

今回は無料でSSL証明書を発行できる「Let’sEncrypt」を使ってサーバーのSSL対応をしていこうと思います。

Let’sEncryptとは

無料で利用可能なSSL証明書の認証局のことです。
全てのWebサイトを暗号化することを目指しているプロジェクトで、多くの有名企業もスポンサーとして付いています。

Let’s Encryptの発行するSSL証明書

無料ということもあり、有効期限は90日となっています。
その為、90日毎に新たにSSL証明書を再発行する必要があります。

環境

OS:AlmaLinux9
WEBサーバー:Apache
※サーバーにApacheを導入した前提での導入記事となります。

導入手順

1. 対象サーバーに接続

ツールは何でも良いので接続する。

2. snapdのインストール

「certbot」というツールをインストールするためのツールです。
以下のようにコマンドを打ってインストールし、コマンドを使えるようにします。

sudo dnf install epel-release
sudo dnf install snapd
sudo systemctl enable --now snapd.socket
sudo ln -s /var/lib/snapd/snap /snap

3. certbotのインストール

「Let’sEncrypt」を導入するのに必要なツールです。
以下のようにコマンドを打ってインストールします。

sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot

4. VirtualHostの設定

「certbot」利用時に必要な設定です。
「/etc/httpd/conf/httpd.conf」の最下部に以下を追記します。

NameVirtualHost *:80

<VirtualHost *:80>
ServerAdmin root@あなたのドメイン
DocumentRoot /var/www/html
ServerName あなたのドメイン
</VirtualHost>

5. certbot実行

以下コマンドを実行します。

sudo certbot --apache

実行するといくつか質問されるので、答えていきます。

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): ○○○@gmail.com

好きなメールアドレスを入力します。

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

利用規約に同意しますかとのことなので、「Y」を入力します。

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N

Certbot を開発する非営利団体であるElectronic Frontier Foundationにメールアドレスを共有しますかとのことなので、今回は「N」を入力します。
(これは好きな方を選択していただいて問題ないです)

Account registered.
Please enter the domain name(s) you would like on your certificate (comma and/or
space separated) (Enter 'c' to cancel): あなたのドメイン

SSL対応する対象のドメインを入力します。
※以降「あなたのドメイン」と書いてある箇所にはここで入力したドメイン名が入ります。

Requesting a certificate for あなたのドメイン
Which names would you like to activate HTTPS for?
We recommend selecting either all domains, or all domains in a VirtualHost/server block.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: あなたのドメイン
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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つだけなので「1」を選択。
(複数ある場合は基本的には全て選択することをおすすめしてるみたいです)

Requesting a certificate for あなたのドメイン
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/あなたのドメイン/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/あなたのドメイン/privkey.pem
This certificate expires on 2024-06-27.
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 あなたのドメイン to /etc/httpd/conf/httpd-le-ssl.conf
Congratulations! You have successfully enabled HTTPS on https://あなたのドメイン
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Successfullyと出たので成功となります。
これでSSL対応は完了です。

6. 再発行

基本的には期限の30日前から再発行できるので、以下コマンドを実行して再発行しましょう。

sudo certbot renew

とても簡単ですね。
※ちなみにですが、期限を過ぎてしまった場合でも同じコマンドを実行すれば再発行されます。

まとめ

今回は「Let’sEncrypt」を利用して無料でSSL対応を行いました。

やってみると難しいことはなく、pemの配置なども自動でやってくれるので、すんなりと導入出来ました。

実際のところ導入手順は調べればたくさんあるのですが、部分的に上手くいかないところがあったりしたので、実際に試してみて成功した手順を記しました。

この手順が誰かの役に立てば幸いです。

以上、堀井でした。

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