このサイトは、只今WEB業界で活躍中のデザイナー、プログラマーの方々の情報を集めたweb統合情報サイトです。

Archives Details

Ubuntu 20.04 LTS サーバ構築 – Let’s EncryptでSSL/TLS化

ubuntu

2022.05.01

この記事は最終更新日から1年以上が経過しています。

前回のUbuntu 20.04 LTS サーバ構築 – Nginxインストールの続きです。

今回は、Let’s EncryptでSSL/TLS化していきます。

メニュー

Cerbotのインストール

CertbotとNginxプラグインをインストール。

$ sudo apt install certbot python3-certbot-nginx

Nginxの設定確認

Certbotが`server`ブロックを見つけられるか、Nginxの設定確認します。

$ sudo vim /etc/nginx/sites-available/example.com

既存のserver_name 行を確認。

/etc/nginx/sites-available/example.com

...
server_name example.com www.example.com;
...

問題なければNginxの設定の構文チェック。

$ sudo nginx -t

修正が発生した際は、Nginxをリロードします。

$ sudo systemctl reload nginx

SSL証明書の取得

Certbotで設定しているドメインに対してSSL証明書を取得します。

$ sudo certbot --nginx -d example.com -d www.example.com

初めてcertbotを実行する場合は、メールアドレスを入力し、利用規約に同意するよう求められるのでメールアドレス入力。

その後、すべてHTTPSにリダイレクトするかどうか聞かれるので、2を選択。

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):

ENTERキーで設定が更新され、Nginxがリロードして新しい設定を取得。

Output
IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/example.com/privkey.pem
   Your cert will expire on 2022-07-13. 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

/etc/nginx/sites-available/example.com を確認。
serverブロック、80番ポートに301リダイレクトが挿入される

if ($host = example.com) {
   return 301 https://$host$request_uri;
}

serverブロック、443番ポートに以下が挿入される

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

http2にする場合は変更。

listen 443 ssl http2;
listen [::]:443 ssl http2;

ブラウザで、https://example.com をアクセス。サイトが適切に保護されている。

SSL Labs Server TestでチェックでA判定となる。

Certbotの自動更新

Let’s Encryptの証明書は90日間のみ有効なので自動更新の設定。

certbot.timerを追加で処理を行います。スクリプトは1日に2回実行され、有効期限の30日以内にある証明書を自動更新となります。

タイマーのステータスを確認。

$ sudo systemctl status certbot.timer
Output
● certbot.timer - Run certbot twice daily
     Loaded: loaded (/lib/systemd/system/certbot.timer; enabled; vendor preset: enabled)
     Active: active (waiting) since Mon 2020-05-04 20:04:36 UTC; 2 weeks 1 days ago
    Trigger: 2022-04-15 04:03:32 UTC; 10h left
   Triggers: ● certbot.service

certbot ドライランで、更新プロセスをテスト

$ sudo certbot renew --dry-run

エラーが表示されなければ、設定は完了。

必要に応じて、Certbotは証明書を更新し、Nginxをリロードして変更を反映。

自動更新プロセスが失敗時は、設定したメールアドレスにメッセージを送信される。

次はPostfixの設定を行っていきましょう。

Ubuntu 20.04 LTS サーバ構築 – Postfixインストール

Comment

Related Article

Ubuntu 20.04 LTS サーバ構築 – DKIM、DMARCを設定する

2022.05.01

Ubuntu 20.04 LTS サーバ構築 – Postfix Let’s EncryptでTLS化

2022.05.01

Ubuntu 20.04 LTS サーバ構築 – Postfix SASL認証

2022.05.01

Ubuntu 20.04 LTS サーバ構築 – Dovecotインストール

2022.05.01

Ubuntu 20.04 LTS サーバ構築 – Postfixインストール

2022.05.01

Ubuntu 20.04 LTS サーバ構築 – Let’s EncryptでSSL/TLS化

2022.05.01

Ubuntu 20.04 LTS サーバ構築 – Nginxインストール

2022.05.01

Ubuntu 20.04 LTS サーバ構築 – 初期セットアップ

2022.05.01

Ubuntu 18.04 LTSで OpenGL開発

2019.05.20

平成最後のお買い物!!「Logicool MX Master 2 Wireless Mouse」と「K780 マルチデバイス BLUETOOTH® キーボード」で快適PC生活。

2019.04.27

CATEGORY LIST

LATEST NEWS

Rust - Actix Web mongo ユーザー登録 JWT認証

Rust

2024.03.24

Rust - Actix Web JWT 認証認可 APIの作成

Rust

2024.02.25

Rust - Actix Web × JSON 静的ファイルをAPIで返却

Rust

2024.01.19

Rust - Actix Web × MongoDB環境をサクッと起動

Rust

2024.01.18

5分で学ぶ RustでWave Function Collapse (波動関数崩壊アルゴリズム)

Rust

2024.01.15

LLaMAモデル GGMLフォーマット(llama.cpp)をRustフレームワーク Leptosを用いて M1MacMiniでサクッと動かす。

Rust

2024.01.11

2024年 狙っているモバイルノートPC

tool

2024.01.07

MacOS XcodeにSDL2を追加

tool

2023.12.26

php 7.4にアップデート

PHP

2023.12.24

5分で覚える Flutter Flameで作る Wave Function Collapse - 波動関数崩壊アルゴリズム

AI・Bot・algorithm

2023.12.20

Flutter - Flameでゲーム作成 (キャラクターの移動)

Flutter

2023.07.23

Flutterで作る ChatGPT Prompt Manager

Flutter

2023.07.12

RANKING

Follow

SPONSOR

現在、掲載募集中です。



Links

About Us

WEBデザイナーの、WEBデザイナーによる、WEBデザイナーの為のサイト。「みんなで書こう!」と仲間を募ってみたが、結局書くのは自分だけとなってしまいました。日々のメモを綴っていきます。

Entry Profile

Graphical FrontEnd Engineer
- Daisuke Takayama

MAD CITY 北九州市で生まれ育つ。20代はバンド活動に明け暮れ、ふと「webデザイナーになりたい。」と思い、デジタルハリウッド福岡校入学。卒業後、数々の賞を受賞、web業界をざわつかせる。
現在、主に、ゲーム制作中心に港区六本木界隈で活動中。

FOLLOW US