Let’s Encryptでは無料でSSL証明書が利用できます。企業で利用する際に採用する実在の証明などは利用出来ませんが、ドメインの証明は可能なため、個人のサイトとしては十分かと思います。
更新作業も完全自動化に対応しており、とても便利なので実際に行なった手順を元に導入方法を紹介します。
作業の前にEBSのスナップショットかAMIを取っておきます。
前提作業
例として本サイトのアドレスtroches.jpでの設定で記載します。
nginxの設定
troches.jp, www.troches.jpどちらからもアクセス出来るようにnginxを設定しておきます。
1 2 3 4 5 | ... server { ... server_name troches.jp www.troches.jp; ... |
RHEL7のリポジトリをインストール&有効化
Redhat Enterprise Linux 7 のリポジトリインストールパッケージを取得&インストール
1 | $ sudo wget -r --no-parent -A 'epel-release-*.rpm' http: //dl .fedoraproject.org /pub/epel/7/x86_64/Packages/e/ |
リポジトリをインストール
1 | $ sudo rpm -Uvh dl.fedoraproject.org /pub/epel/7/x86_64/Packages/e/epel-release- *.rpm |
リポジトリを有効化
1 | $ sudo yum-config-manager -- enable epel* |
Certbot のインストールと実行
インストール
1 | $ sudo yum install certbot-nginx |
certbotを実行
1 | $ sudo certbot --nginx |
以下のように入力
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | Enter email address.... (Enter 'c' to cancel): // Emailを入力 // ----------------------------------------------- Please read the Terms of Service at ... (A)gree/(C)ancel: A ----------------------------------------------- Would you be willing to share your email ... (Y)es/(N)o: Y ----------------------------------------------- Starting new HTTPS connection ... Select the appropriate numbers separated by commas and/or spaces, or leave input blank to select all options shown (Enter 'c' to cancel):そのままEnter ----------------------------------------------- Please choose whether or not to redirect HTTP traffic to HTTPS, ... Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2 ----------------------------------------------- Congratulations! と出ればよいでしょう。 |
nginxのコンフィグにリダイレクトの設定など追加されているはず。
以下のようにエラーになったらこちらを参照
1 2 3 4 | Cleaning up challenges An unexpected error occurred: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 in position 15: ordinal not in range(128) Please see the logfiles in /var/log/letsencrypt for more details. |
Nginxのコンフィグをチェック&再起動
1 2 3 4 | $ sudo nginx -t nginx: the configuration file /etc/nginx/nginx .conf syntax is ok nginx: configuration file /etc/nginx/nginx .conf test is successful $ sudo systemctl restart nginx |
セキュリティグループを変更する
443を開放する
URLにアクセスして確認します。
http://troches.jp/, http://www.troches.jp/にアクセスした時にhttps://troches.jpへリダイレクトされているか、証明書の詳細などを確認します。
証明書を自動で更新されるように設定する
cronかsystemdで自動実行されるように設定する。
以下、systemdでの設定
サービスファイル
1 2 3 4 5 6 | [Unit] Description=Let's Encrypt renewal [Service] Type=oneshot ExecStart=/usr/bin/certbot renew --quiet --agree-tos --deploy-hook "systemctl reload nginx.service" |
タイマーファイル
1 2 3 4 5 6 7 8 9 10 | [Unit] Description=Daily renewal of Let's Encrypt's certificates [Timer] OnCalendar=0/12:00:00 RandomizedDelaySec=1h Persistent=true [Install] WantedBy=timers.target |
設定ファイルをリロードする
1 | $ sudo systemctl daemon-reload |
手動で実行する
1 | $ sudo systemctl start certbot.service |
ログを確認しましょう
1 | $ sudo less /var/log/letsencrypt/letsencrypt .log |
タイマーを有効化する
1 | $ sudo systemctl enable certbot.timer |
参考
You lack the details of the /etc/nginx/nginx.conf.
Surprisingly, I just learned Japanese for a year and I can read your post.
Hi Peng. What lack is it?