Ubuntu 18.04 LTSのNginxでTLS 1.3を有効にする方法

TLS 1.3は、RFC 8446で提案された標準として2018年に公開されたトランスポート層セキュリティ(TLS)プロトコルのバージョンです。以前のバージョンよりもセキュリティとパフォーマンスが向上しています。

このガイドでは、Ubuntu 18.04 LTSでNginx Webサーバーを使用してTLS 1.3を有効にする方法を示します。

必要条件

  • Nginxバージョン1.13.0以上。
  • OpenSSLバージョン1.1.1以降。
  • Ubuntu 18.04を実行するVultr Cloud Compute(VC2)インスタンス。
  • ドメインの有効なドメイン名と適切に構成されたA/ AAAA/ CNAMEDNSレコード。
  • 有効なTLS証明書。Let's Encryptから取得します。

あなたが始める前に

Ubuntuのバージョンを確認してください。

lsb_release -ds
# Ubuntu 18.04.1 LTS

アクセス権をnon-root持つ新しいユーザーアカウントを作成し、sudoそれに切り替えます。

adduser johndoe --gecos "John Doe"
usermod -aG sudo johndoe
su - johndoe

注: ユーザー名に置き換えjohndoeてください。

タイムゾーンを設定します。

sudo dpkg-reconfigure tzdata

システムが最新であることを確認します。

sudo apt update && sudo apt upgrade -y

build-essentialsocatおよびgitパッケージをインストールします。

sudo apt install -y build-essential socat git

Acme.shクライアントをインストールし、Let's EncryptからTLS証明書を取得します

Acme.shをダウンロードしてインストールします

sudo mkdir /etc/letsencrypt
git clone https://github.com/Neilpang/acme.sh.git
cd acme.sh 
sudo ./acme.sh --install --home /etc/letsencrypt --accountemail [email protected]
cd ~
source ~/.bashrc

バージョンを確認してください。

acme.sh --version
# v2.8.0

ドメインのRSAおよびECDSA証明書を取得します。

# RSA 2048
sudo /etc/letsencrypt/acme.sh --issue --standalone --home /etc/letsencrypt -d example.com --ocsp-must-staple --keylength 2048
# ECDSA
sudo /etc/letsencrypt/acme.sh --issue --standalone --home /etc/letsencrypt -d example.com --ocsp-must-staple --keylength ec-256

注: コマンドをドメイン名に置き換えexample.comます。

上記のコマンドを実行すると、証明書とキーに次の場所からアクセスできます。

  • RSAの場合:/etc/letsencrypt/example.comディレクトリ。
  • ECC / ECDSAの場合:/etc/letsencrypt/example.com_eccディレクトリ。

ソースからNginxをビルドする

Nginxはバージョン1.13.0でTLS 1.3のサポートを追加しました。Ubuntu 18.04を含むほとんどのLinuxディストリビューションでは、NginxはTLS 1.3をサポートしない古いOpenSSLバージョンで構築されています。したがって、TLS 1.3のサポートを含むOpenSSL 1.1.1リリースにリンクされた独自のカスタムNginxビルドが必要です。

Nginxソースコードの最新のメインラインバージョンをダウンロードして抽出します。

wget https://nginx.org/download/nginx-1.15.5.tar.gz && tar zxvf nginx-1.15.5.tar.gz

OpenSSL 1.1.1ソースコードをダウンロードして抽出します。

# OpenSSL version 1.1.1
wget https://www.openssl.org/source/openssl-1.1.1.tar.gz && tar xzvf openssl-1.1.1.tar.gz

.tar.gz不要になるため、すべてのファイルを削除します。

rm -rf *.tar.gz

Nginxソースディレクトリを入力します。

cd ~/nginx-1.15.5

Nginxを構成、コンパイル、インストールします。簡単にするために、TLS 1.3が機能するために必要な必須モジュールのみをコンパイルします。完全なNginxビルドが必要な場合は、Nginxコンパイルに関するこのVultrガイドを読むことができます。

./configure --prefix=/etc/nginx \
            --sbin-path=/usr/sbin/nginx \
            --modules-path=/usr/lib/nginx/modules \
            --conf-path=/etc/nginx/nginx.conf \
            --error-log-path=/var/log/nginx/error.log \
            --pid-path=/var/run/nginx.pid \
            --lock-path=/var/run/nginx.lock \
            --user=nginx \
            --group=nginx \
            --build=Ubuntu \
            --builddir=nginx-1.15.5 \
            --http-log-path=/var/log/nginx/access.log \
            --http-client-body-temp-path=/var/cache/nginx/client_temp \
            --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
            --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
            --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
            --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
            --with-compat \
            --with-http_ssl_module \
            --with-http_v2_module \
            --with-openssl=../openssl-1.1.1 \
            --with-openssl-opt=no-nextprotoneg \
            --without-http_rewrite_module \
            --without-http_gzip_module

make
sudo make install

Nginxシステムグループとユーザーを作成します。

sudo adduser --system --home /nonexistent --shell /bin/false --no-create-home --disabled-login --disabled-password --gecos "nginx user" --group nginx

シンボリックリンク/usr/lib/nginx/modules/etc/nginx/modulesディレクトリ。etc/nginx/modulesNginxモジュールの標準的な場所です。

sudo ln -s /usr/lib/nginx/modules /etc/nginx/modules

Nginxキャッシュディレクトリを作成し、適切な権限を設定します。

sudo mkdir -p /var/cache/nginx/client_temp /var/cache/nginx/fastcgi_temp /var/cache/nginx/proxy_temp /var/cache/nginx/scgi_temp /var/cache/nginx/uwsgi_temp
sudo chmod 700 /var/cache/nginx/*
sudo chown nginx:root /var/cache/nginx/*

Nginxのバージョンを確認します。

sudo nginx -V

# nginx version: nginx/1.15.5 (Ubuntu)
# built by gcc 7.3.0 (Ubuntu 7.3.0-27ubuntu1~18.04)
# built with OpenSSL 1.1.1  11 Sep 2018
# TLS SNI support enabled
# configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx . . .
# . . .

Nginx systemdユニットファイルを作成します。

sudo vim /etc/systemd/system/nginx.service

ファイルに次の設定を入力します。

[Unit]
Description=nginx - high performance web server
Documentation=https://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

Nginxを起動して有効にします。

sudo systemctl start nginx.service
sudo systemctl enable nginx.service

ディレクトリconf.dsites-availableおよびsites-enabledディレクトリに/etc/nginxディレクトリを作成します。

sudo mkdir /etc/nginx/{conf.d,sites-available,sites-enabled}

sudo vim /etc/nginx/nginx.conf次の2つのディレクティブを実行して、ファイルの最後、終了の直前に追加します}

    . . .
    . . .
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*.conf;
}

でファイルして終了保存:+ W+ Q

TLS 1.3用にNginxを構成する

Nginxが正常にビルドされたので、サーバーでTLS 1.3の使用を開始するように構成する準備が整いました。

sudo vim /etc/nginx/conf.d/example.com.confファイルを実行し、次の構成を入力します。

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

  # RSA
  ssl_certificate /etc/letsencrypt/example.com/fullchain.cer;
  ssl_certificate_key /etc/letsencrypt/example.com/example.com.key;
  # ECDSA
  ssl_certificate /etc/letsencrypt/example.com_ecc/fullchain.cer;
  ssl_certificate_key /etc/letsencrypt/example.com_ecc/example.com.key;

  ssl_protocols TLSv1.2 TLSv1.3;

  ssl_prefer_server_ciphers on;

  ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
}

でファイルして終了保存:+ W+ Q

ディレクティブの新しいTLSv1.3パラメーターに注意してくださいssl_protocols。このパラメーターは、TLS 1.3を有効にするために必要です。

構成を確認してください。

sudo nginx -t

Nginxをリロードします。

sudo systemctl reload nginx.service

TLS 1.3を確認するには、ブラウザ開発ツールまたはSSL Labsサービスを使用できます。以下のスクリーンショットは、TLS 1.3が機能していることを示すChromeのセキュリティタブを示しています。

Ubuntu 18.04 LTSのNginxでTLS 1.3を有効にする方法

Ubuntu 18.04 LTSのNginxでTLS 1.3を有効にする方法

おめでとう!Ubuntu 18.04 WebサーバーでTLS 1.3を正常に有効化しました。



Leave a Comment

CentOS 7にApacheをインストールする方法

CentOS 7にApacheをインストールする方法

CentOS 7サーバーにApache 2.4をインストールする方法を説明します。安定したウェブサーバーを構築するための前提条件と手順を解説します。

FreeBSD 11.1にBlacklistdをインストールする方法

FreeBSD 11.1にBlacklistdをインストールする方法

FreeBSD 11.1におけるBlacklistdのインストール方法について詳しく解説します。この方法を通じて、強力なセキュリティ対策を実装できます。

Windows Serverのサーバーマネージャーを使用した複数サーバーの管理

Windows Serverのサーバーマネージャーを使用した複数サーバーの管理

サーバーマネージャーを使用して、Windows Serverの管理が向上します。セキュリティリスクを軽減し、効率的な管理を実現します。

CentOS 7にSeafileサーバーをインストールする方法

CentOS 7にSeafileサーバーをインストールする方法

CentOS 7にSeafileサーバーをインストールする方法。Seafile(コミュニティバージョン)は、ownCloudに似た無料のオープンソースファイル同期および共有ソリューションです。

DebianでSnortを設定する方法

DebianでSnortを設定する方法

Snortは無料のネットワーク侵入検知システムです。最新の方法で、SnortをDebianにインストールし、設定する手順を紹介します。ネットワークのセキュリティを強化しましょう。

CentOS 7にGraylogサーバーをインストールする方法

CentOS 7にGraylogサーバーをインストールする方法

CentOS 7にGraylogサーバーをインストールし、ログ管理を行う方法を学びます。

WindowsでhMailServerを使用してメールサーバーを構築する

WindowsでhMailServerを使用してメールサーバーを構築する

WindowsサーバーでWebサイトを実行している場合、電子メールも受信できるようにするためにhMailServerを使用する方法を解説します。

Ubuntu 19.04にFiveMサーバーをインストールする方法

Ubuntu 19.04にFiveMサーバーをインストールする方法

FiveMサーバーをUbuntu 19.04にインストールするための詳細なガイド。必要条件からインストール、起動、トラブルシューティングまで、すべてのステップを含みます。

WsgiDAVを使用してDebian 10にWebDAVをデプロイする

WsgiDAVを使用してDebian 10にWebDAVをデプロイする

Debian 10にWebDAVをデプロイする方法を学び、WsgiDAVとSSL証明書で安全な接続を実現しましょう。

ヘルスケア2021における人工知能の影響

ヘルスケア2021における人工知能の影響

ヘルスケアにおけるAIは、過去数十年から大きな飛躍を遂げました。したがって、ヘルスケアにおけるAIの未来は、日々成長を続けています。