SSL証明書(ウェブサイトの暗号化通信を行うために必要)をリーズナブルに導入する言うニーズを想定しまして、当該Webサーバに Let’s Encrypt と呼ばれるSSL証明書を導入いたしました。
ちなみに Let’s Encrypt とはざっと調べたところ、 ISRG と言う米国公益法人がインターネット上での安全な通信を行う障壁を減らすことを目的として無償で提供している SSL 証明書だそうです。以下に備忘録的ではありますが手順をメモいたします。
- インストール (certbot)
Let’s Encryptが提供する「certbot」と呼ばれるソフトウェアをインストールします。
# curl https://dl.eff.org/certbot-auto -o /usr/bin/certbot-auto
# chmod 700 /usr/bin/certbot-auto - 証明書を発行する (certbot-autoコマンド)
以下のコマンドで証明書を
# certbot-auto certonly --webroot -w /home/xxx -d www.xxx.com --email xxx@xxx.com
※この時、当該環境では Let’s Encrypt 導入のための python 系のパッケージが導入されていなかったため、yumの追加インストール画面に遷移しましたが、継続してインストールを完了させました。 - 規約に承諾する
-------------------------------------------------------------------------------
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v01.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: A - メーリングリストへの加入
-------------------------------------------------------------------------------
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let’s Encrypt project and the non-profit
organization that develops Certbot? We’d like to send you email about EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: N - 証明書の作成
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for www.xxx.com
Using the webroot path /home/xxx for all unmatched domains.
Waiting for verification…
Cleaning up challenges - 証明書作成完了 (以下の画面が出れば成功)
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/xxx.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/xxx.com/privkey.pem
Your cert will expire on 2018-08-23. To obtain a new or tweaked
version of this certificate in the future, simply run certbot-auto
again. To non-interactively renew *all* of your certificates, run
“certbot-auto renew”
- 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 - SSL 化に伴う NGINX のコンフィグファイル変更
/etc/nginx/conf.d に格納している conf ファイル内で主に変更する箇所を追加・変更します。
https ではないアクセスでも自動的にSSLへリダイレクトさせる設定です。
server {
listen 80;
server_name xxx.com;
return 301 https://www.xxx.com$request_uri;
}server {
listen 80;
server_name www.xxx.com;
return 301 https://www.xxx.com$request_uri;
}server {
listen 443 ssl;
ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
ssl_ciphers ALL:!aNULL:!SSLv2:!EXP:!MD5:!RC4:!LOW:+HIGH:+MEDIUM;
ssl_certificate /etc/letsencrypt/live/www.xxx.com/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/www.xxx.com/privkey.pem;
ssl_session_timeout 10m;
・・・ - NGINX 再起動
# service nginx restart - Webサイトの修正
今回は証明書導入に特化する記事なので割愛 - 証明書の有効期限更新
# /usr/bin/certbot-auto renew --post-hook “sudo service nginx restart”
-------------------------------------------------------------------------------
Processing /etc/letsencrypt/renewal/test.example.com.conf
-------------------------------------------------------------------------------
Cert not yet due for renewalThe following certs are not due for renewal yet:
/etc/letsencrypt/live/www.xxx.com/fullchain.pem (skipped)
No renewals were attempted.
No hooks were run.下記のように表示されればOK、cronに登録する
# crontab -e
00 6 * * * /usr/bin/certbot-auto renew --post-hook “service nginx restart”
もしうっかり間違ったドメインを登録してしまった場合は、[certbot-auto delete -d xxx.com]にて削除できます。