Let’s EncryptでWebサイトSSL化に挑戦したら簡単過ぎた(ConoHa, CentOS7)

昨今の時代の流れに乗ってサイトのSSL化をやってみた。以前別のサービスを使ってSSL化していたことがあったけど、そのためにはSSL化するドメインのメールサーバを立ててないといけなくて、メールのやりとりとかも必要で正直メンドくさかった(しかも英語で)。

↑の経験からSSL化っていろいろ面倒なんだろうなーとか思ってたけど、Let’s Encryptで挑戦してみたら一瞬にできてしまった。すごい。

必要なWebサーバ環境

メールサーバとかは立てなくて大丈夫。でも一応最低限必要な環境を用意しないといけないので念のため記載。

  • ドメイン名(DNS名)でアクセスできるサーバであること
  • http(80番ポート/tcp)、https(443番ポート/tcp)でアクセスできること

また、今回はApacheが動いている状態で実行。他のWebサーバ(Nginxとか)が動いている場合も同じコマンドでいけるみたい。
Webサーバが動いていないサーバでもオプション追加でOK。詳しくは参考サイトを参照。

インストール

# yum install epel-release
# yum install certbot

証明書取得

-wオプションはドキュメントルートディレクトリ、-dはドメイン(FQDN)

[root@www ~]# certbot certonly --webroot -w /var/www/html -d www.tetsis.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): (連絡がとれるメールアドレス)
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org

-------------------------------------------------------------------------------
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.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: Y
Starting new HTTPS connection (1): supporters.eff.org
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for www.tetsis.com
Using the webroot path /var/www/html for all unmatched domains.
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/www.tetsis.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/www.tetsis.com/privkey.pem
Your cert will expire on 2018-01-27. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"certbot 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

Apacheに証明書を設定

# vim /etc/httpd/conf.d/ssl.conf

SSLCertificateFile /etc/letsencrypt/live/www.tetsis.com/fullchain.pem

SSLCertificateKeyFile /etc/letsencrypt/live/www.tetsis.com/privkey.pem

# systemctl restart httpd

これで完了。いい時代になりました。

参考

https://letsencrypt.jp/usage/