2
0

More than 3 years have passed since last update.

無料の SSL 証明書を取得する

Last updated at Posted at 2021-06-05

はじめに

当投稿は LSWS と組み合わせて使用することを前提にしています。

DNSを設定する

dns.png

レジストラまたはDNSサーバーによって画面が異なるのでそちらに従ってください。
上図の例ではvsoと、それ以下のワイルドカード*.vsoをAレコードに登録してます。

Certbot をインストールする

[root@vm opc]# dnf install certbot

見つからないと言われてしまう場合はEPELリポジトリを有効化してください。

SSL 証明書を発行する

certbotコマンドは次の通りです。
certbot certonly --standalone -d <ドメイン> -m <メールアドレス> --agree-tos

LSWSを一旦止める
[root@vm opc]# systemctl stop lsws
Certbotで証明書取得
[root@vm opc]# certbot certonly --standalone -d test.vso.mydomain.com -m webmaster@mydomain.com --agree-tos

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Requesting a certificate for test.vso.mydomain.com
Performing the following challenges:
http-01 challenge for test.vso.mydomain.com
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/test.vso.mydomain.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/test.vso.mydomain.com/privkey.pem
   Your certificate will expire on 2021-08-28. To obtain a new or
   tweaked version of this certificate in the future, simply run
   certbot again. 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
LSWSをもう一度起動する
[root@vm opc]# systemctl start lsws

SSL証明書の自動更新

SSL証明書の自動更新は次の通り。

実際のコマンド
[root@vm opc]# certbot renew 
    --standalone #certbotが単独で80番ポートを使って認証する
    --pre-hook "systemctl stop lsws" #更新前に実行するコマンド(例ではLSWS停止)
    --post-hook "systemctl start lsws" #更新後に実行するコマンド(例ではLSWS開始)

これを cron.d に登録する。

cron.dに登録
[root@vm opc]# vi /etc/cron.d/certbot
/etc/cron.d/certbot
00 04 02,17 * * root certbot renew --standalone --pre-hook "systemctl stop lsws" --post-hook "systemctl start lsws"

これで自動更新されます。

PHPファイルを作る

[root@vm opc]# mkdir -m 755 -p /usr/local/lsws/virtual/test.vso.mydomain.com/html
[root@vm opc]# chown -R nobody:nobody /usr/local/lsws/virtual/
[root@vm opc]# vi /usr/local/lsws/virtual/test.vso.mydomain.com/html/index.php
/usr/local/lsws/virtual/test.vso.mydomain.com/html/index.php
<?php
echo 'Hello World';

ドメインにアクセスする https://~

cap.png

警告が出なければ成功。

Next

2
0
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
2
0