【無料SSL】Let’s Encryptの簡単導入方法について

  • 2021年3月3日
  • 2021年3月12日
  • 技術
  • 0件

費用をかけずに無料で、HTTPS(SSL)を導入したい場合、Let’s Encryptを使うのが便利です。Let’s Encryptは無料のサーバ証明書になりますので、誰でも手軽に設定することができます。

Let’s Encryptとは

Let’s Encryptは、アメリカ合衆国カリフォルニアにある公益法人です。公式サイトは「https://letsencrypt.org/」になります。Let’s Encrypt自体は、寄付で運用されており、Googleなど多くの有名企業がスポンサーに入っているので、誰でも安心して使うことができます。

Let’s Encryptを導入する

導入するOSは、CentOS 7.7を想定して記載します。

  • epel-releaseの確認とインストール
$ yum install epel-release

必要なパッケージをインストールします。

  • certbotとpython2-certbot-apacheの確認とインストール
$ yum install certbot python2-certbot-apache

読み込んだプラグイン:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp-srv2.kddilabs.jp
 * epel: d2lzkl7pfhq30w.cloudfront.net
 * extras: ftp-srv2.kddilabs.jp
 * remi-safe: ftp.riken.jp
 * updates: ftp-srv2.kddilabs.jp
 ...

Let’s Encryptの利用には、certbotとpython2-certbot-apacheが必要になりますので、この2つをインストールします。

Certbot実行

インストールが完了したら、設定を進めていきます。下記のコマンドを実行してください。

$ certbot certonly --agree-tos --webroot -w ドキュメントルート -d 設定ドメイン

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-v02.api.letsencrypt.org

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, 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 our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for papamama-baby.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/papamama-baby.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/papamama-baby.com/privkey.pem
   Your cert will expire on 2020-11-18. 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

メールアドレスを入力する必要がありますが、それ以外は、N(No) で大丈夫です。

  • 設定ファイルの更新

最後に、設定ファイルを更新します。/etc/httpd/conf.d/ssl.conf のファイルに、下記のように設定を追記します。

$ /etc/httpd/conf.d/ssl.conf

SSLCertificateFile /etc/letsencrypt/live/[設定したドメイン]/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/[設定したドメイン]/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/[設定したドメイン]/chain.pem
  • 反映
$ service httpd restart

これで、設定完了です。httpsに変えてアクセスができるか確認してみましょう。