手当たり次第に書くんだ

飽きっぽいのは本能

Ubuntu 26.04 Apache TLS の設定

Ubuntu 26.04 サーバー管理ガイドに戻る

Ubuntu 26.04 の Apache で HTTPS を扱うには、証明書と秘密鍵を配置し、SSL モジュール、TLS 用 VirtualHost、暗号スイート設定を有効にします。

この記事では Apache の基本設定が終わっている前提で、TLS 終端として Apache を動かすための手動手順を整理します。内部環境では自己署名 CA の証明書を使う場面もあります。

前提を確認する

apache2 -v
systemctl status apache2 --no-pager
sudo apache2ctl -t

証明書と秘密鍵を確認する

例では /etc/my-ssl 配下に配置済みの証明書を使います。秘密鍵は読み取り権限を絞ります。

sudo ls -l /etc/my-ssl/certs/example.local.crt
sudo ls -l /etc/my-ssl/private/example.local.key
sudo openssl x509 -in /etc/my-ssl/certs/example.local.crt -noout -subject -issuer -dates

TLS 関連モジュールを有効化する

sudo a2enmod ssl
sudo a2enmod rewrite
sudo a2enmod headers

TLS 暗号設定を配置する

sudo install -d -m 0755 -o root -g root /etc/apache2/https-custom-config.d
sudo tee /etc/apache2/https-custom-config.d/tls-cipher.conf >/dev/null <<'EOF'
SSLProtocol -All +TLSv1.2 +TLSv1.3
SSLCipherSuite ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-CHACHA20-POLY1305
SSLHonorCipherOrder On
EOF

HTTPS VirtualHost を作成する

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
        ServerName web01.example.local
        ServerAdmin webmaster@example.local
        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        SSLEngine on
        SSLCertificateFile /etc/my-ssl/certs/example.local.crt
        SSLCertificateKeyFile /etc/my-ssl/private/example.local.key
        IncludeOptional /etc/apache2/https-custom-config.d/*.conf
    </VirtualHost>
</IfModule>

サイトを有効化する

sudo tee /etc/apache2/sites-available/default-ssl.conf >/dev/null <<'EOF'
<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
        ServerName web01.example.local
        ServerAdmin webmaster@example.local
        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        SSLEngine on
        SSLCertificateFile /etc/my-ssl/certs/example.local.crt
        SSLCertificateKeyFile /etc/my-ssl/private/example.local.key
        IncludeOptional /etc/apache2/https-custom-config.d/*.conf
    </VirtualHost>
</IfModule>
EOF
sudo a2ensite default-ssl

設定を検証して反映する

sudo apache2ctl -t
sudo apache2ctl -S
sudo systemctl restart apache2

HTTPS の動作確認をする

curl -k -I https://127.0.0.1/
openssl s_client -connect 127.0.0.1:443 -servername web01.example.local </dev/null | openssl x509 -noout -subject -issuer -dates

まとめ

Apache の TLS 設定では、証明書と秘密鍵、SSL モジュール、HTTPS VirtualHost、暗号設定、構文確認をまとめて扱います。自己署名証明書を使う場合は、クライアント側の CA 信頼設定も合わせて考える必要があります。

Ubuntu 26.04 サーバー管理ガイドに戻る

Ubuntu 26.04 Apache TLS の設定

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)

トップへ戻る