EC2において、Let's scriptを用いてSSL証明獲得し、HTTPをHTTPS接続に変更する方法


1. EPEL7の有効化

LinuxディストリビューションにおけるOSオプションパッケージ群(機能拡張のようなイメージ?)。


$ sudo wget -r --no-parent -A 'epel-release-*.rpm' http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/
$ sudo rpm -Uvh dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-*.rpm
$ sudo yum-config-manager --enable epel*

2. certbotのインストール

Let's Encrypt のクライアントである certbot をインストールする。

$ sudo yum install certbot python2-certbot-nginx

3. 証明書を取得

$ sudo certbot --nginx

4. 設定変更

nginx virtual
server {
    server_name  atlier.online;
    rewrite index.html https://atlier.online permanent;
}
server {
    listen       443 ssl; # 変更または追加
    server_name  atlier.online;
    # 以下各種設定
}

5. cron

SSL証明の更新の自動化、をcornに設定する。

0 4 * * * root certbot renew --no-self-upgrade

https://www.express.nec.co.jp/linux/distributions/knowledge/system/crond.html

このように、定期的に実行されるジョブは、crond というデーモンによって、自動的に行なうように管理することができます。