LoginSignup
56
58

More than 5 years have passed since last update.

AWS EC2 で Let's Encrypt

Posted at

注意
Let's encryptのクライアントがCertbotクライアントに更新されています。
使い方はさほど変わってないようですが新たに利用する人は最新の情報をご確認の上ご利用ください。


AWS EC2上のnginxLet's Encryptの証明書を取得、更新するための手順をまとめました。
nginxのセットアップ手順などは省略しております。

Let's encryptクライアントをインストールする

$ sudo git clone https://github.com/letsencrypt/letsencrypt /usr/local/letsencrypt
$ sudo /usr/local/letsencrypt/letsencrypt-auto --help --debug

Amazon Linux はまだ正式な取扱ではないため--debugオプションが必要になります。

証明書を取得する

事前にAWSのセキュリティグループで80ポートへのインバウンドを有効にしておき、証明書取得後に不要であれば無効に戻します。

$ sudo /usr/local/letsencrypt/letsencrypt-auto certonly --standalone -d example.com --agree-tos

ドメインは適宜変更してください。

証明書の自動更新を設定する

$ sudo vi /etc/cron.daily/letsencrypt
$ sudo chmod +x /etc/cron.daily/letsencrypt

以下は /etc/cron.daily/letsencrypt の内容です。
DOMAINWEBROOTなどは適宜変更してください。
今回はWebサーバにnginxを利用しているためservice nginx reloadしています。Apacheなどをご利用の方は適宜変更してください。

#!/bin/sh

LE_HOME=/usr/local/letsencrypt
WEBROOT=/usr/share/nginx/html
DOMAIN=example.com
LOG=/var/log/letsencrypt/renew.log

$LE_HOME/letsencrypt-auto certonly --debug --non-interactive --keep-until-expiring --webroot -w $WEBROOT -d $DOMAIN >> $LOG 2>&1
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
    echo Automated renewal failed:
    exit 1
fi
service nginx reload
56
58
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
56
58