ネットワークのセキュリティを強化するために、HTTPSを用いたWebサイトが徐々に増えています。しかし、有料のSSL証明書を購入する際の高額な料金は多くの中小サイトを落胆させています。“Let’s encrypt”の出現は世界の清流のようなものであり、情報発信に活力を吹き込んでいます。
“Let’s encrypt”が発行するSSL証明書を取得する方法はいくつかありますが、ここではLinuxサーバにSSL証明書をインストールする方法のみを紹介します。
1 “Cerbot”クライアントをインストール
SSL証明書をインストールする時に、“Cerbot”クライアントが必要です。まだインストールしていない場合は、以下の方法を参考にしてインストールします。
[root@usite ~]# yum -y install epel-release ← yum用EPELリポジトリのインストール
[root@usite ~]# yum -y install snapd ← 安装snapd
[root@usite ~]# systemctl enable --now snapd.socket ← snapd.socketの有効化
[root@usite ~]# ln -s /var/lib/snapd/snap /snap ← “/var/lib/snapd/snap”から“/sna”までのリンク
[root@usite ~]# snap install --classic certbot ← certbotのインストール
[root@usite ~]# ln -s /snap/bin/certbot /usr/bin/certbot ← “/snap/bin/certbot”から“/usr/bin/certbot”までのリンク
2 mod_sslのインストール
ApacheサーバにSSL証明書を使用する時、よく“OpenSSL”の“mod_ssl”モジュールを使います。まだインストールされていない場合は、以下の方法を参考にすることができます。
[root@usite ~]# yum -y install mod_ssl ← mod_sslのインストール
3 SSL証明書の取得
[root@usite ~]# certbot certonly --webroot -w USiteDocumentRoot -m UMail@Address -d DomainName --agree-tos ← SSL証明書の取得
備考:
USiteDocumentRoot:/var/www/html/usite/ ← サイトのDocumentRoot
UMail@Address:自分のメアド ← SSL証明書の取得
DomainName:usite.com ← 対象ドメイン
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Requesting a certificate for usite.com
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/usite.com/fullchain.pem
Key is saved at: /etc/letsencrypt/live/usite.com/privkey.pem
This certificate expires on 2023-05-15.
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4 Apacheサーバの設定
SSL証明書を取得したあとに、Apacheサーバ上にSSL証明書をインストールすることが必要です。方法は以下の通りです。
[root@usite ~]# vi /etc/httpd/conf.d/ssl.conf ← SSL証明書の設定ファイル
# Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate. If
# the certificate is encrypted, then you will be prompted for a
# pass phrase. Note that a kill -HUP will prompt again. A new
# certificate can be generated using the genkey(1) command.
SSLCertificateFile /etc/letsencrypt/live/usite.com/cert.pem ← 公開鍵の指定
# Server Private Key:
# If the key is not combined with the certificate, use this
# directive to point at the key file. Keep in mind that if
# you've both a RSA and a DSA private key you can configure
# both in parallel (to also allow the use of DSA ciphers, etc.)
SSLCertificateKeyFile /etc/letsencrypt/live/usite.com/privkey.pem ← 秘密鍵の指定
# Server Certificate Chain:
# Point SSLCertificateChainFile at a file containing the
# concatenation of PEM encoded CA certificates which form the
# certificate chain for the server certificate. Alternatively
# the referenced file can be the same as SSLCertificateFile
# when the CA certificates are directly appended to the server
# certificate for convinience.
SSLCertificateChainFile /etc/letsencrypt/live/usite.com/chain.pem ←証明書の指定
上記の設定を完了したあとに、Apacheサーバをリロードすることが必要です。方法は以下の通りです。
[root@usite ~]# systemctl reload httpd ← Apacheサーバのリロード
以上の方法を使って、無料の“Let’s encrypt”SSL証明書を取得し、設定することができます。以上の方法は、“centossrv.com”を参照しています。もし、“Let’s encrypt”発行のSSL証明書を自動的に更新したい場合は、「https://centossrv.com/apache-certbot.shtml」を参考にしてください。