• Skip to main content
  • Skip to primary sidebar

プログラミング入門ナビ by Proglus(プログラス)

プログラミング学習初心者のための情報メディア

本ページにプロモーションが含まれる場合があります

You are here: Home / Archives for Certbot

Certbot

無料のSSL証明書Let’s Encryptを設定・更新・自動更新する方法(CentOS7, Apache2.4対応)

2018-03-10 By プログラミング入門ナビ編集部

無料のSSL証明書Let’s Encryptを設定・更新・自動更新する方法を初心者向けに解説します。
GoogleがSSL化されたWebサイトをSEOの評価として優遇すると発表しており、Webページのhttps化は必須の流れとなっています。

Linuxサーバー構築運用入門 (CentOS7, PHP7, Apache, MySQL, WordPress対応)サポート記事です。

Let’ Encryptについて

誰でも無料で使えるSSL/TLS証明書発行サービスです。
mozilla, Google Chrome, facebook, ciscoなどがメジャースポンサーとなっていて安心感が有ります。

公式サイト


Let’s Encrypt

Certbotについて

この記事では、certbot(サートボット)という、Let’s Encryptの自動化を行うためのソフトウェアを利用します。

公式サイト

Certbot

ドキュメントなどが掲載されています(英語)

前提条件

  • CentOS7
  • Apache 2.4
  • httpでWebページを表示できる状態(http://blog.example.com といったURLではブラウザで表示できている状態)
  • VirtualHost設定済み
  • 設定するドメインはblog.example.com (各自のドメインに読み替えてください)

動画で学習する

① SSL証明書の設定 Let’s Encrypt

② SSL証明書設定の動作確認 Let’s Encrypt

③ SSL証明書の更新 Let’s Encrypt

インストールされるcertbotのバージョンを確認

$ yum list available | grep certbot-apache
python2-certbot-apache.noarch             0.21.1-1.el7                   epel

certbotインストール

$  sudo yum install certbot-apache
・・・略・・・
Is this ok [y/d/N]: y
・・・略・・・
完了しました!

SSL証明書の取得

$ sudo certbot --apache

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): nakamura@example.com ← 各自のメールアドレスを入力してエンターキー。
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org

-------------------------------------------------------------------------------
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 ← 利用規約を確認したら、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 ←  Electronic Frontier Foundationからメールを受け取り場合はY, 受け取らない場合は、Nを入力してエンターキー。
Starting new HTTPS connection (1): supporters.eff.org

Which names would you like to activate HTTPS for?
-------------------------------------------------------------------------------
1: blog.example.com
-------------------------------------------------------------------------------
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1 ← 1を入力してエンターキー(ドメインの選択)
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for blog.example.com
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/httpd/conf.d/blog.example.com-le-ssl.conf
Deploying Certificate for blog.example.com to VirtualHost /etc/httpd/conf.d/blog.example.com-le-ssl.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2 ← 2を選択してエンターキー(リダイレクトの設定。httpでのアクセスをhttpsにリダイレクトする)
Redirecting vhost in /etc/httpd/conf.d/blog.example.com.conf to ssl vhost in /etc/httpd/conf.d/blog.example.com-le-ssl.conf

-------------------------------------------------------------------------------
Congratulations! You have successfully enabled https://blog.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=blog.example.com
-------------------------------------------------------------------------------

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/blog.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/blog.example.com/privkey.pem
   Your cert will expire on 2018-06-08. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. 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

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

「Congratulations! You have successfully enabled https://blog.example.net」と表示されれば、設定完了です。

動作確認

httpsでアクセス

ブラウザでhttpsから始まるURLでWebサイトを表示。

httpでアクセス

ラウザでhttpsから始まるURLでWebサイトを表示。
httpsへリダイレクトすることを確認する。

SSL証明書の更新

証明書の有効期限を確認する

$ sudo certbot certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log

-------------------------------------------------------------------------------
Found the following certs:
  Certificate Name: blog.example.com
    Domains: blog.example.com
    Expiry Date: 2018-06-03 10:31:54+00:00 (VALID: 88 days)
    Certificate Path: /etc/letsencrypt/live/blog.example.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/blog.example.com/privkey.pem
-------------------------------------------------------------------------------

あと、SSL証明書の有効期限は、2018-06-03まで。残り88日であることが分かる。
Let’ EncrytpのSSL証明書は、有効期限3ヶ月と短いので注意しましょう。

次のコマンドを実行すると更新できます。(エンターキーはまだおさないでください)

$sudo   certbot renew

ただし、有効期限が30日未満のときしか更新されません。

–dry-run オプションをつけた上でリハーサル。

ドライランとは、簡単にいうとリハーサルです。おためし的に証明書を更新するコマンドを実行してエラーが起きないかなどを確認できます。ドライランでは、データの更新は行われないので安全です。

$ sudo certbot renew --dry-run
・・・略・・・
Congratulations, all renewals succeeded. 
・・・略・・・

ドライランが成功しました。
手動でSSL証明書を有効期限が30日未満になったら、ドラインランを実行してから、

$ sudo certbot renew

します。

もし、有効期限までの残り日数に関係なく、すぐに証明書を更新したい場合は、

次のコマンドを実行します。

$ certbot renew --force-renew

Saving debug log to /var/log/letsencrypt/letsencrypt.log

-------------------------------------------------------------------------------
Processing /etc/letsencrypt/renewal/blog.example.com.conf
-------------------------------------------------------------------------------
Plugins selected: Authenticator apache, Installer apache
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for blog.example.com
Waiting for verification...
Cleaning up challenges

-------------------------------------------------------------------------------
new certificate deployed with reload of apache server; fullchain is
/etc/letsencrypt/live/blog.example.com/fullchain.pem
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------

Congratulations, all renewals succeeded. The following certs have been renewed:
  /etc/letsencrypt/live/blog.example.com/fullchain.pem (success)
-------------------------------------------------------------------------------

更新できました。

SSL証明書の自動更新。

更新を3ヶ月に一回手動でおこなっていると、いつか忘れてしまうので、自動で更新する方法を学習します。
「cron」クロンという、定期的に指定したプログラムを実行できる仕組みを使います。
クロンの読み方ですが、英語のカタカタ読みですので、なにが正しいとかは無いのですが、
実務上、クーロンと呼ぶこともあります。

スケジュールを設定するファイルを開く

$ sudo vim /etc/crontab

例えば、毎朝3:10に、rootユーザでcertbot renewを実行するには。

下記を追記。

10 3 *  *  * root /usr/bin/certbot renew

※ 注意点としては、ここでは、–force-renewalオプションはつけないでください、let’s encryptの使用量制限に引っかかる可能性があります。

これで、毎日更新がこころみられて、有効期限が30日未満だと、証明書の更新が実際に行われます。

注意点

特に初めてSSL証明書の更新が行われるまでは、

時々、証明書の有効期限を確認して、期限切れにならないように注意しましょう。

$ sudo certbot certificates

cronによって自動で証明書が更新されているか、確認してください。残り30日を切っているのに、数日様子を見ても、更新がされない場合は、なにかトラブルが起きている可能性があります。

その場合は、手動で更新を試みてみるのも一つの手です。

$sudo certbot renew

ログを確認して、トラブルシューティングをする方法もあります。
letsencryptのログは、このディレクトリにありますのでトラブルが起きたときに確認します。

$ sudo ls -la /var/log/letsencrypt/

例えば、最新のログを確認するには、

sudo less  /var/log/letsencrypt/letsencrypt.log

とします。表示されている、エラーメッセージをgoogleで検索したりしながら、解決を試みます。

SSL証明書の有効期限が切れると、ユーザーがサイトをブラウザで表示した時に、ブラウザにエラーが表示されて、ユーザから不審に思われてしまいますので、注意しましょう。

動作確認環境

  • CentOS Linux release 7.4.1708 (Core)
  • Server version: Apache/2.4.6 (CentOS)
  • python2-certbot-apache 0.21.1-1.el7
  • さくらのVPS 1Gプラン

おわりに

この記事では、無料のSSL証明書Let’s Encryptを設定・更新・自動更新する方法を学習しました。

オンライン講座、Linuxサーバー構築運用入門 (CentOS7, PHP7, Apache, MySQL, WordPress対応)では、Linuxの操作に慣れていない方向けに、無料のSSL証明書Let’s Encryptを設定・更新・自動更新する方法を説明しています。

動画で1からわかりやすく説明していますので、ぜひご利用ください。

Bestseller はじめてのLinuxサーバー構築運用入門 - Linuxコマンドを基礎から学ぶはじめてのLinuxサーバー構築運用入門 - Linuxコマンドを基礎から学ぶ中村 祐太 Yuta Nakamura, Proglus (プログラス)Linuxコマンド操作を基礎から学習してLAMPを構築できる. Linux, Apache MySQL(MariaDB), PHP, WordPressのインストールを実施. 4.4 (1949 ratings)99 lectures, 5 hours

動画でプログラミング入門をしよう

オンライン学習サービスProglus(プログラス)でプログラミングを学び、創れる人になろう!

プレミアムプランを2週間無料体験しよう

今すぐ詳細を確認する

Filed Under: ツールの使い方 Tagged With: Certbot, Let's Encrypt, Linux, SSL証明書, Udemy, サーバー

Primary Sidebar

Proglus(プログラス)

Twitter

Follow @programmingnavi Tweets by programmingnavi

最近の投稿

  • 【05/02更新】Udemyプログラミング入門講座等の割引クーポン配布
  • AWSのパブリックIPv4アドレス有料化について 2024/2より
  • 【CSS】Google Fontsの利用方法について解説します!新UIに対応2023年11月更新
  • 【SQL】XAMPPのMySQLがXAMPPがポートの競合で起動できない問題について解決方法を解説します!
  • 【Colab】–NOMAL– と表示されて、ショートカットキー(ctrl+c)でコピーができない場合の解決方法を解説します!

カテゴリー

  • AIの使い方
  • Arduino入門
  • AWS
  • その他
  • エンジニアのしごと
  • エンジニアへの道
  • ツールの使い方
  • ニュース
  • プログラミング入門
  • 電子工作入門

タグクラウド

AI AWS AWS Cloud9 Cloud9 CodeWing CSS Emmet GCP Git GitHub Heroku HTML JavaScript li Linux macOS MySQL MySQL Workbench node.js Nuxt.js ol Proglus Python Ruby Ruby on Rails SQL Udemy Visual Studio Code Vue.js Web開発 Windows インストール エラー エンジニア オンライン学習 サーバー スクリーンショット セール プログラミング プログラミング入門 プログラミング学習 ユーデミー 初心者 未経験 機械学習

アーカイブ

  • 2025年5月
  • 2024年1月
  • 2023年11月
  • 2023年9月
  • 2023年8月
  • 2023年7月
  • 2023年5月
  • 2023年4月
  • 2023年2月
  • 2023年1月
  • 2022年12月
  • 2022年11月
  • 2022年10月
  • 2022年9月
  • 2022年8月
  • 2022年7月
  • 2022年4月
  • 2022年3月
  • 2022年2月
  • 2022年1月
  • 2021年10月
  • 2021年9月
  • 2021年8月
  • 2021年6月
  • 2021年4月
  • 2021年3月
  • 2021年1月
  • 2020年12月
  • 2020年11月
  • 2020年10月
  • 2020年9月
  • 2020年8月
  • 2020年7月
  • 2020年5月
  • 2020年4月
  • 2020年3月
  • 2020年2月
  • 2020年1月
  • 2019年11月
  • 2019年9月
  • 2019年7月
  • 2019年6月
  • 2019年5月
  • 2019年4月
  • 2019年3月
  • 2019年2月
  • 2019年1月
  • 2018年12月
  • 2018年11月
  • 2018年10月
  • 2018年9月
  • 2018年8月
  • 2018年7月
  • 2018年6月
  • 2018年5月
  • 2018年4月
  • 2018年3月

検索

Copyright © 2025 · programmingnavi.com ・About・プライバシーポリシー