こすられまくっている内容とは知りつつも、導入できたのでまとめずにはいられない。
1. mod_sslを導入
以下のコマンドで導入します。
yum install -y mod_ssl
インストールできたらhttpdを再起動。
apachectl restart
2. certbotを導入
導入は公式に書いてあります。
certbot --apache
で、正しい入力をしているにも関わらず、以下のようなエラーが出力される場合があります。
Unable to find a virtual host listening on port 80 which is currently needed for Certbot to prove to the CA that you control your domain. Please add a virtual host for port 80.
これは仮想ポートの設定がされていないためです。
以下のサイトを参考に/etc/httpd/conf/httpd.conf
を修正します。
echo 'NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin root@hogehoge
DocumentRoot /var/www/html
ServerName hogehoge
</VirtualHost>' >> /etc/httpd/conf/httpd.conf
hogehoge
を自分のサーバードメインに修正するのを忘れずに。
3. sslの設定
certbotの導入後は、/etc/httpd/conf.d/ssl.conf
を編集する必要があります。(ここ大事)
以下のサイトを参考。
4. cronの設定
証明書の更新を自動化します。
ここでは毎月1日と15日の4時に証明書の更新を行うように設定します。
/etc/crontab
を編集します。
00 04 01 * * certbot renew && systemctl restart httpd
00 04 15 * * certbot renew && systemctl restart httpd
以上です。
お疲れさまでした。