let's encryptでSSL証明書を発行
Let's encryptのコマンドの導入
# curl https://dl.eff.org/certbot-auto -o /usr/bin/certbot-auto
# chmod 700 /usr/bin/certbot-auto
証明書の必要な情報は
サーバのdocument root、ドメイン名、メールアドレス
# certbot-auto certonly --webroot -w /var/www/html/sub1 -d sub1.domain.com
以下のフォルダにpemファイルが生成される。フォルダはドメイン名
/etc/letsencrypt/live/sub1.domain.com/
cert.pem
chain.pem
fullchain.pem
privkey.pem
nginxのconfファイルにsslの設定行を追加
/etc/nginx/conf.d/sub1.conf
server {
listen 80;
}
sever {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/sub1.domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/sub1.domain.com/privkey.pem;
}
nginxを再起動してブラウザでアクセス(httpsで)。
SSL証明書の更新
Let's encryptの証明書は3ヶ月で切れるので
再取得のスクリプトをcronで更新する。
vi /etc/cron.d/letsencrypt
/etc/cron.d/letsencrypt
00 16 * * 0 root /usr/bin/certbot-auto renew --post-hook "systemctl restart nginx"