• Skip to main content
  • Skip to primary sidebar

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

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

You are here: Home / ツールの使い方 / 無料のSSL証明書Let’s Encryptを設定・更新・自動更新する方法(CentOS7, Apache2.4対応)

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

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

Tweet
このエントリーをはてなブックマークに追加
Pocket

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

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

目次

  • 1 Let’ Encryptについて
    • 1.1 公式サイト
  • 2 Certbotについて
    • 2.1 公式サイト
  • 3 前提条件
  • 4 動画で学習する
    • 4.1 ① SSL証明書の設定 Let’s Encrypt
    • 4.2 ② SSL証明書設定の動作確認 Let’s Encrypt
    • 4.3 ③ SSL証明書の更新 Let’s Encrypt
  • 5 インストールされるcertbotのバージョンを確認
  • 6 certbotインストール
  • 7 SSL証明書の取得
  • 8 動作確認
    • 8.1 httpsでアクセス
    • 8.2 httpでアクセス
  • 9 SSL証明書の更新
    • 9.1 証明書の有効期限を確認する
    • 9.2 次のコマンドを実行すると更新できます。(エンターキーはまだおさないでください)
    • 9.3 –dry-run オプションをつけた上でリハーサル。
    • 9.4 もし、有効期限までの残り日数に関係なく、すぐに証明書を更新したい場合は、
  • 10 SSL証明書の自動更新。
    • 10.1 スケジュールを設定するファイルを開く
  • 11 例えば、毎朝3:10に、rootユーザでcertbot renewを実行するには。
  • 12 注意点
    • 12.1 動作確認環境
  • 13 おわりに
  • 14 今すぐメルマガ登録!
  • 15 動画でプログラミング入門をしよう

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を構築できる. さくらのVPSを設定して独自ドメインのオリジナルブログをWordPressを使って公開できる!CentOS7, Apache2.4, MySQL5.7, PHP7使用. 4.3 (1108 ratings)136 lectures, 7 hours

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

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

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

今すぐ詳細を確認する

Tweet
このエントリーをはてなブックマークに追加
Pocket

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

Primary Sidebar

Proglus(プログラス) 採用情報 FindU

Twitter

Follow @programmingnavi Tweets by programmingnavi

人気の記事

  • VirtualBoxでNATとホストオンリーアダプターによる安全なネットワーク環境構築方法
  • VSCodeで画像が表示されない場合の対処法
  • VSCodeの基本~プロジェクトフォルダの設定方法について解説します!
  • Visual Studio Codeのメニューを 日本語化する方法と英語化する方法について解説!
  • Node.jsをmacOSからアンインストールする方法
  • MySQL WorkbenchからMySQLサーバーへの接続時やSQLファイルを取り込み時にエラーが発生した時の対処方法
  • JavaScriptの「net::ERR_FILE_NOT_FOUND」エラーが出る原因と対処方法を紹介!
  • 【Arduino入門】LCD(液晶ディスプレイ)に文字を表示しよう
  • MySQLをXAMPPを使ってWindows環境にインストールする方法
  • MAMP for MacOSによるMySQLのインストール方法

最近の投稿

  • 【SQL】ER図(Entity-relationship Diagram)について解説します!
  • 【MySQL】公式インストーラー(dmg)を使って、MySQLサーバーをmacOSにインストールする方法を解説
  • 【AWS Cloud9】Gitで使用するエディタを再起動してもvimの設定にする方法
  • 【VSCode】アクティビティバーに拡張機能アイコンが表示表示されていない場合の解決方法
  • 【Windows】Gitをインストールする方法についてプログラミング入門者向けに解説します

カテゴリー

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

タグクラウド

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

アーカイブ

  • 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 © 2023 · programmingnavi.com ・About・プライバシーポリシー