LoginSignup
8
12

More than 5 years have passed since last update.

Let's Encryptの導入方法

Last updated at Posted at 2018-07-30

開発環境にもHTTPSを導入したいがドメインが増えると費用も大変なので、無料のサーバ証明書を試してみました。
Let's Encryptの詳しい内容は検索すれば出てきますが簡単に説明します。
公式サイトは「https://letsencrypt.org/」で、運営はInternet Security Research Group(ISRG)というアメリカ合衆国カリフォルニア州にある公益法人になります。
寄付で運営しており、Googleなど多くのスポンサーが付いているので安心して利用できると思います。
今回は解説しませんが、ワイルドカード証明書も利用できます。

導入OS:CentOS 7.5
導入手順(Webrootプラグイン)

  • Certbotインストール
1. epel-releaseの確認とインストール

    yum list installed | grep epel-release
    yum install epel-release

2. certbotとpython2-certbot-apacheの確認とインストール

    yum list installed | grep certbot
    yum list installed | grep python2-certbot-apache
    yum install certbot python2-certbot-apache
  • ドメインの設定手順
1. Certbot実行

    certbot certonly --agree-tos --webroot -w ドキュメントルート -d 設定ドメイン
    --agree-tos
    ACME利用規約に同意します。このオプションを有効にした場合、過去に利用規約の同意を行ったことがない場合であっても、利用規約の同意を求める画面が表示されません。
    --webroot
    ウェブサーバのDocumentRootディレクトリ以下に認証用のファイルを設置することでドメイン使用権者の認証を行って、SSL/TLSサーバ証明書を取得します。デフォルトはfalseになります。
    -wはドキュメントルートディレクトリを指定し、-dはドメインを指定します。

    実行後は英文での対話形式で下記の入力を求められます。
    ・緊急及びセキュリティ連絡用のメールアドレス入力。
    ・上記で入力したメールアドレスを電子フロンティア財団のメーリングリストに登録するかのYまたはNの入力。

2. Apacheに設定

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/設定ドメイン/cert.pem
    SSLCertificateChainFile /etc/letsencrypt/live/設定ドメイン/chain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/設定ドメイン/privkey.pem

3. Certbot自動化

    1. cronの動作確認
        systemctl status crond

    2. vi /etc/crontabで下記を追加する(毎日、01:39 と 13:39 にコマンドが実行されるようにスケジュール、スケジュールの値は任意)
        39 1,13 * * * root certbot renew --webroot-path ドキュメントルート --post-hook "systemctl restart httpd"

        renew
        取得済みの SSL/TLS サーバ証明書のうち、有効期限が近い証明書を自動的に更新します。

        --webroot-path
        ウェブサーバのDocumentRootディレクトリ以下に認証用のファイルを設置することでドメイン使用権者の認証を行って、SSL/TLSサーバ証明書を取得します。

    3. cron デーモンを再起動
        systemctl restart crond

検証用で実行するコマンド
certbot renew --webroot-path ドキュメントルート --post-hook "systemctl reload httpd"

AWSへの導入はAWS公式ドキュメント - Amazon Linux 2 での Let's Encrypt と Certbot の使用が参考になります。

8
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
12