0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Let's Encryptを使ってhttpsを使えるようにする

Posted at

概要

何番煎じだろうと思いながらLets Encrypt を使って証明書をセットアップする。
Ubuntu 20.04

管理ツールのインストール

sudo apt -y install certbot

証明書のインストール

【ドメインは自分のものにする】
sudo certbot --nginx -d mattermost.example.com

下記のメッセージがでたら今回は「2」を選択した。
(httpのアクセスは許可せずhttpsにリダイレクトさせる)

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

確認

/etc/nginx/sites-available/default の中に # managed by Certbot というコメントがついて
設定が追加されていた。

設定にエラーが無いか確認

sudo nginx -t

以下のようにokが出ればよい。

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

設定反映のためnginxの再起動

sudo systemctl restart nginx

更新のテスト

テスト用サーバを使うので、たまに失敗するみたい。
実際1回目は失敗したけど、2回目は大丈夫だった…
sudo certbot renew --dry-run

成功した場合

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/mattermost.example.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert not due for renewal, but simulating renewal for dry run
Plugins selected: Authenticator nginx, Installer nginx
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for mattermost.example.com
Waiting for verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed with reload of nginx server; fullchain is
/etc/letsencrypt/live/mattermost.example.com/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

失敗した場合はログを見る。
sudo less /var/log/letsencrypt/letsencrypt.log

2023-12-06 22:51:52,091:DEBUG:urllib3.connectionpool:https://acme-staging-v02.api.letsencrypt.org:443 "POST /acme/new-order HTTP/1.1" 201 355
2023-12-06 22:51:52,092:DEBUG:acme.client:Received response:
HTTP 201
(snip)
2023-12-06 22:51:52,228:DEBUG:urllib3.connectionpool:https://acme-staging-v02.api.letsencrypt.org:443 "POST /acme/authz-v3/********** HTTP/1.1" 404 106
2023-12-06 22:51:52,229:DEBUG:acme.client:Received response:
HTTP 404

認証部分で404エラーが出ていた。
ただ、もう一度実行したら成功したので、失敗した場合は落ち着いて時間をおいてから
再実行するのがよさそう。

更新スケジュールの確認

sudo systemctl status certbot.timer

● certbot.timer - Run certbot twice daily
     Loaded: loaded (/lib/systemd/system/certbot.timer; enabled; vendor preset: enabled)
     Active: active (waiting) since Mon 2022-11-14 00:09:43 JST; 1 years 0 months ago
    Trigger: Thu 2023-12-07 15:03:49 JST; 3h 40min left
   Triggers: ● certbot.service

とりあえずここまでで大丈夫そうなので様子見。

参考

Let's Encrypt
【Ubuntu+Nginx】Let's EncryptでSSL証明書を発行してhttps通信を行う
Mattermost の SSL 証明書の更新を Certbot タイマーで行う

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?