mod_ssl

Table of Contents

AlmaLinux 9でApache HTTP ServerをHTTPS化(mod_ssl)

AlmaLinux 9の標準リポジトリからmod_sslを導入し、取得済みの証明書をhttpdで使用する手順です。
証明書の取得・自己署名証明書の作成は、別記事を参照してください。

mod_sslのインストール

# dnf info mod_ssl
# dnf install mod_ssl
# httpd -M | grep ssl_module

証明書と秘密鍵の配置

証明書はサーバー証明書と中間証明書を含むfull chainを使用します。
証明書と秘密鍵のパスは環境に合わせてください。秘密鍵はroot所有とし、一般ユーザーに読ませないでください。

# install -o root -g root -m 0644 /path/to/fullchain.pem /etc/pki/tls/certs/example.org.fullchain.pem
# install -o root -g root -m 0600 /path/to/private.key /etc/pki/tls/private/example.org.key

秘密鍵の置き場所は/etc/pki/tls/private/とし、公開ディレクトリやソース管理下に置かないでください。
SELinuxを有効にしている環境では、標準パスを使用し、必要に応じて正しいファイルコンテキストを確認してください。

HTTPS VirtualHostの設定

パッケージ付属の/etc/httpd/conf.d/ssl.confを直接上書きせず、サイト用の設定ファイルを作成します。

# vi /etc/httpd/conf.d/example.org-ssl.conf
<VirtualHost *:443>
    ServerName example.org
    DocumentRoot /var/www/html

    SSLEngine on
    SSLCertificateFile /etc/pki/tls/certs/example.org.fullchain.pem
    SSLCertificateKeyFile /etc/pki/tls/private/example.org.key
</VirtualHost>

example.org、DocumentRoot、証明書パスを実環境に合わせます。
TLSプロトコルや暗号スイートはAlmaLinux 9のシステム全体の暗号化ポリシーを利用し、
個別設定で古いプロトコルを有効化しないでください。
HTTPからHTTPSへ転送する場合は、サイトの要件を確認した上で別途リダイレクトを設定します。

設定検査と起動

# apachectl configtest
# systemctl enable --now httpd
# systemctl reload httpd
# systemctl status httpd --no-pager

構文検査でエラーが出た場合は、修正してからreloadしてください。

ファイアウォール

有効なゾーンを確認し、HTTPSを公開するインターフェースのゾーンだけに許可します。
以下のpublicは例なので、実環境のゾーン名に置き換えてください。

# firewall-cmd --get-active-zones
# firewall-cmd --zone=public --add-service=https --permanent
# firewall-cmd --reload
# firewall-cmd --zone=public --list-services

不要なゾーンにHTTPSを開放しないでください。

接続確認

クライアントからアクセスし、証明書の名前・有効期限・チェーンが正しいことを確認します。

# openssl s_client -connect example.org:443 -servername example.org </dev/null
# journalctl -u httpd -n 50 --no-pager

参考資料

コメントを残す

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