LoginSignup
5
6

More than 3 years have passed since last update.

WordPressでLet’s Encryptの設定+自動更新設定

Posted at

実現したいこと

centos(Wordpress)にてLet’s Encryptを入れてSSL証明書を発行、Let’s Encryptは有効期間が90日のため自動更新設定までを行います。

前提条件

  • ドメインを取得していること (今回は仮にsample.comのドメインで実施)
  • Apacheがインストールされていること

Lets'sEncryptの導入手順

Lets'sEncryptを入れるには、Certbotクライアントのインストールが必要

Certbotクライアントのインストール

$ sudo yum install epel-release
$ sudo yum install certbot python-certbot-apache

インストールが完了したら準備完了!!!
これでcertbotコマンドが実行可能になりました。

証明書発行

$ sudo certbot certonly --agree-tos --webroot -w /var/www/html/ -d sample.com

※オプションの意味は下記のリファレンスを参照
certbot公式リファレンス

証明書確認

$ ls -al /etc/letsencrypt/archive/sample.com/

下記のようなファイルがあればOK!

cert.pem サーバ証明書(公開鍵を含む)
chain.pem 中間証明書
privkey.pem 秘密鍵
fullchain.pem サーバ証明書(公開鍵を含む)と中間証明書は一緒になっているファイル※今回は使用しません

SSL証明書の設定
下記部分を修正

$ sudo vim /etc/httpd/conf.d/sample_ssl.conf
SSLCertificateFile /etc/letsencrypt/archive/sample.com/cert.pem
SSLCertificateChainFile /etc/letsencrypt/archive/sample.com/chain.pem
SSLCertificateKeyFile /etc/letsencrypt/archive/sample.com/privkey.pem

再起動
再起動して変更を反映

$ sudo systemctl restart httpd.service

SSL証明書の自動更新設定

テスト ※これでは更新されません
まずはコマンドが正しいことを確認

$ sudo certbot renew --force-renew --dry-run --webroot-path /var/www/html/ --post-hook "apachectl graceful"

--force-renew:残りの有効期限に関係なく強制更新
--dry-run:テスト実行オプション

実行
実際に更新されることを確認 ※ブラウザの鍵マークをクリックして証明書の有効期限を確認

$ sudo certbot renew --force-renew --webroot-path /var/www/html/ --post-hook "apachectl graceful"

cron設定
毎月1日の5:00に更新する設定
Cronの詳しい設定方法はこちら

$ sudo vim /etc/cron.d/letsencrypt
00 05 01 * * root certbot renew --force-renew --webroot-path /var/www/html/ --post-hook "apachectl graceful"
5
6
1

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
5
6