サイト構築

Let’s encrypt してみる

投稿日:

Let’s Encrypt設定

ドメイン名を取得してから、Let’s Encryptの自動設定を行うまでを書いてみようかと思います。
一度ドメインとSSL証明書、取ってみたかったんです。

環境

  • OS: Centos7
  • Webサーバ: nginx + php + wordpress

DNSレコード設定

DNS関連の設定は以下の通りです。

ドメイン: tech-law-pyscho.info
Aレコード: totokun
CNAMEレコード: www -> totokun.tech-law-pyscho.info

以下のような設定にしてあります。

KAGOYACLOUDでのDNSレコード設定

以下を参考にしました。
https://www.kagoya.jp/howto/webhomepage/lets-encrypt/

iptablesは割愛

port 443を通す設定は既に行っているので、割愛しました。

Nginx (Webサーバー)設定

server_nameをドメイン名に変更しておきます。

$ cat /etc/nginx/conf.d/wp.conf | grep server_name
  server_name www.tech-law-pyscho.info;
$ systemctl reload nginx

Certbotクライアントソフトウェアのインストール

以下でCertbotプログラムをインストールします。

$ sudo yum install --enablerepo=epel certbot-nginx

以下のコマンドでSSL証明書を取得します。

$ sudo certbot –-nginx -d www.tech-law-pyscho.info
### メールアドレス登録
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): ke.tanino@gmail.com
### 規約
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-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

とやっていたら、以下で失敗しました。nginx.confの中で日本語を使用すると以下のエラーが出るらしいです。
確かにpython2で日本語文字列の読み込みをすると、よく出るエラーメッセージですね。。

An unexpected error occurred:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 in position 15: ordinal not in range(128)
Please see the logfiles in /var/log/letsencrypt for more details.

nginxの設定を変更しようとしたところで落ちているようです。python2で作ってるからなんじゃ。。python3にしようよ。。。

気を取り直して、設定ファイルから日本語を削除して、再度実行。以下続きです。

### 自動的にリダイレクトするかどうかの設定
### ここではリダイレクトすることにした。
Deploying Certificate to VirtualHost /etc/nginx/conf.d/wp.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

Congratulations! You have successfully enabled https://www.tech-law-pyscho.info

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=www.tech-law-pyscho.info
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/www.tech-law-pyscho.info/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/www.tech-law-pyscho.info/privkey.pem
   Your cert will expire on 2019-08-28. 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"
 - 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

ここまで行くと成功です。

https://www.tech-law-pyscho.info

にアクセスできたことを確認しました。

証明書は以下になります。

取得した電子証明書

cronで回す

このままだと有効期限が3ヶ月で切れるので、cron設定をしておきます。

crontab -eで以下の設定を行います。renewとすると、30日以内で切れる場合は自動的に更新してくれるらしいです。

30 2 * * * /usr/bin/certbot renew --quiet

一応、dry-runして問題なさそうなのは確認しました。

# /usr/bin/certbot renew --dry-run
(略)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
** DRY RUN: simulating 'certbot renew' close to cert expiry
**          (The test certificates below have not been saved.)

Congratulations, all renewals succeeded. The following certs have been renewed:
  /etc/letsencrypt/live/www.tech-law-pyscho.info/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
**          (The test certificates above have not been saved.)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

ここまでで、記録しながら、2時間ぐらいなので、簡単でした。

-サイト構築

執筆者:

関連記事

初投稿、、ではない

2019/05/05にWordPressを立ち上げ、一応の設定をしておいた。初投稿になってない。。

CentOS7をアップデートしてみる

少し暇になったので、CentOS7をyum updateしようと思います。 いきなりエラー –> 依存性解決を終了しました。 エラー: パッケージ: gd-last-2.3.0-2.el7.remi …

CentOS7をRocky Linux 9に移行する

このVMのOSをCentOS7にした関係上、そろそろupdateする必要があります。そもそもCentOS7を選択した理由は、仕事で使用するからでした。 で、仕事ではRocky Linux 9なので、こ …

WordPressインストール

カゴヤでVPS作成した いまさらだが、WordPressでブログを作ってみたかった。 カゴヤの設定はほぼ記述通り 【VPS活用】絶対やっておきたい初期設定リスト WordPress インストール 基本 …

PHP7.2 からPHP 7.4にアップデート

なんとなくやってみようかと思いました。 $ yum install –enablerepo=remi-php74 php $ systemctl restart nginx $ systemctl …

google オプトアウト Click here to opt-out.