今回は、UbuntuサーバにLet's Encryptをインストールする方法をまとめました。
コンテンツ
インストール前の事前準備
まず、インストールに必要な依存パッケージを設定します。
mod_sslを有効にする
Gitをインストール
Gitからソースをクローンします。
これで事前準備は完了したので、
ここからがインストールの開始です。
証明書のインストール
GitからCertbotをインストール
これで、「/usr/local/certbot」以下に「Certbot」がインストールされました。
証明書を発行
もし、エイリアス「www」あり・なしの両方に対応する場合には、「-d」を2つ設定する必要があります。
↓
正常に処理が完了すると、以下のようなメッセージが出ます
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for sample.com
http-01 challenge for www.sample.com
Using the webroot path /var/www/html for all unmatched domains.
Waiting for verification...
Cleaning up challenges
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/sample.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/sample.com/privkey.pem
Your cert will expire on 2018-12-24. To obtain a new or tweaked
version of this certificate in the future, simply run certbot-auto
again. To non-interactively renew *all* of your certificates, run
"certbot-auto 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
証明書が発行されているかを確認
drwxr-xr-x 2 root root 4096 Sep 25 19:40 ./
drwx------ 5 root root 4096 Sep 25 19:40 ../
lrwxrwxrwx 1 root root 34 Sep 25 19:40 cert.pem -> ../../archive/sample.com/cert1.pem
lrwxrwxrwx 1 root root 35 Sep 25 19:40 chain.pem -> ../../archive/sample.com/chain1.pem
lrwxrwxrwx 1 root root 39 Sep 25 19:40 fullchain.pem -> ../../archive/sample.com/fullchain1.pem
lrwxrwxrwx 1 root root 37 Sep 25 19:40 privkey.pem -> ../../archive/sample.com/privkey1.pem
-rw-r--r-- 1 root root 682 Sep 25 19:40 README
Apacheから証明書を参照できるように設定
証明書の発行が完了したら、
Apacheから証明書を参照できるように読み込みの設定します。
Apacheのconfを修正
でconfファイルを開いて以下を追記します
<VirtualHost 162.133.263.158:443>
ServerName sample.com
ServerAlias www.sample.com
DocumentRoot /var/www/html
CustomLog /var/log/apache2/ssl.sample.com-access_log combined
ErrorLog /var/log/apache2/ssl.sample.com-error_log
AllowOverride All
Require all granted
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/sample.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/sample.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/sample.com/fullchain.pem
</VirtualHost>
ブラウザからの確認
実際に「https://sample.com」と「https://www.sample.com」にアクセスしてみて、
正常に画面が表示されるかを確認して下さい。
問題なく表示されていれば、
これでインストールまで完了です。
自動更新設定
Let's Encryptは90日毎に更新が必要になります。
が、毎回更新を行うのは手間になるので、Cronで自動更新をスケジューリングしておきます。
自動更新設定の前
※インストールしたばかりなので、以下のようなメッセージが出ればOK
The following certs are not due for renewal yet:
/etc/letsencrypt/live/sample.com/fullchain.pem expires on 2018-12-24 (skipped)
No renewals were attempted.
No hooks were run.
・
・
証明書自動更新の設定
スケジュールを設定することにします。
で、以下を記述します。
30 12 * * 1 root /usr/local/certbot/certbot-auto renew --deploy-hook 2>&1 "sudo service apache2 restart" >&1 | mail -s "Let's Encrypt auto update" info@sample.com
※毎週月曜日の12:30に実行
※念のために、実行結果を指定のメールアドレスに届くようにしています。
これで、設定は完了です。
この記事へのコメントはありません。