LoginSignup
10
19

More than 5 years have passed since last update.

SSL証明書の期限が切れたのでLet's Encryptの証明書に変えた

Last updated at Posted at 2017-01-07

What's this?

個人で運営している PRESENT4229 というサイトのSSL証明書の期限が切れたので、無料でHTTPS対応出来る Let's Encrypt の証明書に変えてみました。

この記事はその作業の備忘録です。
結論から言うと、めっちゃ簡単に出来ました。置き換えだけなら数分で終わると思います。

前提

経緯

PRESENT4229というサイトはうるう日(2月29日)限定のサイトなので、正直サービス稼働していないうるう日以外はHTTPS対応しなくてもまぁいいんだけど、このご時世常時SSL化したほうがいいかなと思いつつ、稼働していないのにコストかけるのもなと思い、そう言えば、Let's Encryptが去年から正式に使えるようになっていたことを思い出し、光の速さでやってみたのであります。

なお、Let's Encryptの説明については割愛させていただきます。

環境

環境は以下です。

  • さくらVPS
  • CentOS6系
  • Nginx1.8系

Let's Encrypt証明書への更新方法

では早速VPSにSSHログインして更新していきましょう。

STEP1:ダウンロード

$ git clone https://github.com/letsencrypt/letsencrypt

いい感じの場所で git clone してください。

STEP2:インストール

$ cd letsencrypt/
$ ./letsencrypt-auto --help

Pythonなど諸々インストールします。
インストールが完了すると、helpが表示されます。

STEP3:セットアップ

$ ./letsencrypt-auto certonly --webroot -w nginxのドキュメントルートパス / -d present4229.com -d www.present4229.com

ドメイン部分は適当に置き換えてください。
上記コマンドを実行すると、GUIが起動して、メールアドレスの入力を求められますので、適当なメールアドレスを入力してください。
そして、利用規約に同意したら、証明書の取得がはじまります。

取得が完了すると、以下のようなメッセージが表示され、鍵の場所などが表示されます。

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at
   /etc/letsencrypt/live/present4229.com/fullchain.pem. Your cert will
   expire on 2017-04-06. To obtain a new or tweaked version of this
   certificate in the future, simply run letsencrypt-auto again. To
   non-interactively renew *all* of your certificates, run
   "letsencrypt-auto renew"
 - If you lose your account credentials, you can recover through
   e-mails sent to xxxxxxxxx@hogehoge.com.
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

STEP4:Nginx設定変更

今回は置き換えなので鍵のパスを変更するだけです。

default.conf(変更箇所のみ抜粋)
#ssl config
    ssl_certificate  /etc/letsencrypt/live/present4229.com/fullchain.pem;
    ssl_certificate_key  /etc/letsencrypt/live/present4229.com/privkey.pem;

STEP5:Nginx再起動

そして、Nginxを再起動すれば無料のHTTPSライフが手に入ります。

# service nginx restart

image

STEP6:cron設定

最後に、Let's Encryptは3ヶ月で証明書の期限が切れるので、cronで自動で更新されるようにしておきます。(root権限で設定してください)

00 05 01 * * /hoge/fuga/letsencrypt/letsencrypt-auto renew && service nginx restart

letsencryptまでのパスは適宜変更してください。

まとめ

超簡単!

参考サイト

10
19
2

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
10
19