LoginSignup
4
8

More than 5 years have passed since last update.

[Amazon Linux / Node] CertbotをインストールしてSSL対応する

Last updated at Posted at 2016-08-29

はじめに

Amazon LinuxへのCertbotインストールは現在非推奨ですが、
--debug オプションを付けることでインストールと設定が行えます。

証明書の作成

  • 対象のインスタンスにsshログイン
  • Webサーバーを立ち上げている場合は事前に止めておく
  • セキュリティグループでIPアドレス制限など掛けている場合は、一時的にHTTPとHTTPSを 0.0.0.0/0 にして全て開放する
  • gitからcertbotをcloneしてインストールする
$ git clone https://github.com/certbot/certbot.git
$ cd certbot/
$ sudo ./certbot-auto certonly --standalone -d {ドメイン名} --debug
確認ダイアログが出るので Agree を選択

証明書の自動更新設定

  • crontabを編集して、毎月の初日にSSL証明書が更新されるように設定

$ crontab -e

  • 以下の記述を追加して保存
# SSL証明書の期限を月1回更新
00 00 01 * * sudo /home/ec2-user/certbot/certbot-auto renew --standalone --debug --pre-hook "サーバー停止コマンド" --post-hook "サーバー開始コマンド"

証明書をnode.jsで読み込む

  • 以下のようにして作成した証明書へのパスを通す
// 本番環境の場合、certbotの証明書を読み込む
if (process.env.NODE_ENV === 'production') {
  options = {
    key: fs.readFileSync('/etc/letsencrypt/live/{domainName}/privkey.pem'),
    cert: fs.readFileSync('/etc/letsencrypt/live/{domainName}/cert.pem')
  };
}

サーバー起動して動作確認

  • https://{domainName} に接続して、証明書情報を確認
4
8
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
4
8