What's?
Rocky Linux 9でdnfを使ったApacheのインストールでmod_sslまでインストールしたことがなかったのですが、これを使うと意外と簡単にHTTPSサイトを作れるので試しておきます。
環境構築用メモです。
環境
今回の環境はこちらです。
$ cat /etc/redhat-release
Rocky Linux release 9.7 (Blue Onyx)
$ uname -srvmpio
Linux 5.14.0-611.24.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jan 23 11:42:43 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Apache+mod_sslをインストールする
それでは、Apacheとmod_sslをインストールしていきましょう。
パッケージの情報を確認してインストール
まずはパッケージの情報を確認します。
Apache。
$ dnf info httpd
メタデータの期限切れの最終確認: 0:00:06 前の 2026年01月31日 15時39分36秒 に実施しました。
利用可能なパッケージ
名前 : httpd
バージョン : 2.4.62
リリース : 7.el9_7.3
Arch : x86_64
サイズ : 45 k
ソース : httpd-2.4.62-7.el9_7.3.src.rpm
リポジトリー : appstream
概要 : Apache HTTP Server
URL : https://httpd.apache.org/
ライセンス : ASL 2.0
説明 : The Apache HTTP Server is a powerful, efficient, and extensible
: web server.
mod_ssl。
$ dnf info mod_ssl
メタデータの期限切れの最終確認: 0:00:24 前の 2026年01月31日 15時39分36秒 に実施しました。
利用可能なパッケージ
名前 : mod_ssl
エポック : 1
バージョン : 2.4.62
リリース : 7.el9_7.3
Arch : x86_64
サイズ : 110 k
ソース : httpd-2.4.62-7.el9_7.3.src.rpm
リポジトリー : appstream
概要 : SSL/TLS module for the Apache HTTP Server
URL : https://httpd.apache.org/
ライセンス : ASL 2.0
説明 : The mod_ssl module provides strong cryptography for the Apache HTTP
: server via the Secure Sockets Layer (SSL) and Transport Layer
: Security (TLS) protocols.
ではインストールしましょう。
$ sudo dnf install httpd mod_ssl
バージョン。
$ httpd -V
Server version: Apache/2.4.62 (Rocky Linux)
Server built: Dec 12 2025 00:00:00
Server's Module Magic Number: 20120211:134
Server loaded: APR 1.7.0, APR-UTIL 1.6.1, PCRE 8.44 2020-02-12
Compiled using: APR 1.7.0, APR-UTIL 1.6.1, PCRE 8.44 2020-02-12
Architecture: 64-bit
Server MPM: event
threaded: yes (fixed thread count)
forked: yes (variable process count)
Server compiled with....
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_PROC_PTHREAD_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=256
-D HTTPD_ROOT="/etc/httpd"
-D SUEXEC_BIN="/usr/sbin/suexec"
-D DEFAULT_PIDLOG="run/httpd.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="conf/mime.types"
-D SERVER_CONFIG_FILE="conf/httpd.conf"
systemdで有効化して起動までしておきましょう。
$ sudo systemctl enable httpd
$ sudo systemctl start httpd
この時点でHTTPSが有効です。
$ ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 511 0.0.0.0:443 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 511 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
curlでアクセスするには-kオプションが必要ですが。
$ curl -k -I https://localhost
HTTP/1.1 403 Forbidden
Date: Sat, 31 Jan 2026 06:44:26 GMT
Server: Apache/2.4.62 (Rocky Linux) OpenSSL/3.5.1
Last-Modified: Sat, 17 May 2025 02:45:05 GMT
ETag: "1dc4-6354be2d9ae40"
Accept-Ranges: bytes
Content-Length: 7620
Content-Type: text/html; charset=UTF-8
設定ファイルを確認
設定ファイルを確認してみましょう。
まずはmod_sslでなにがインストールされるのか見てみます。
$ rpm -ql mod_ssl
/etc/httpd/conf.d/rocky-snipolicy.conf
/etc/httpd/conf.d/ssl.conf
/etc/httpd/conf.modules.d/00-ssl.conf
/usr/lib/.build-id
/usr/lib/.build-id/3e/c1f188bfb1512896e2620ec082072e09ca99a4
/usr/lib/systemd/system/httpd-init.service
/usr/lib/systemd/system/httpd.socket.d/10-listen443.conf
/usr/lib64/httpd/modules/mod_ssl.so
/usr/libexec/httpd-ssl-gencerts
/usr/libexec/httpd-ssl-pass-dialog
/usr/share/man/man8/httpd-init.service.8.gz
/var/cache/httpd/ssl
Apacheの設定ファイルと、SSL/TLS証明書を作成しそうな雰囲気のものが見えますね。
設定ファイルを見てみましょう。
LoadModule ssl_module modules/mod_ssl.so
$ grep -v '#' /etc/httpd/conf.d/ssl.conf
Listen 443 https
SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog
SSLSessionCache shmcb:/run/httpd/sslcache(512000)
SSLSessionCacheTimeout 300
SSLCryptoDevice builtin
<VirtualHost _default_:443>
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn
SSLEngine on
SSLHonorCipherOrder on
SSLCipherSuite PROFILE=SYSTEM
SSLProxyCipherSuite PROFILE=SYSTEM
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "/var/www/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-5]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
CustomLog logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
$ grep -v '#' /etc/httpd/conf.d/rocky-snipolicy.conf
<IfDirective SSLVHostSNIPolicy>
SSLVHostSNIPolicy authonly
</IfDirective>
証明書を確認
Apacheの設定ファイルを見ると、SSL/TLS証明書は設定済みみたいでした。
こちらのパスからすると、
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
このスクリプトで作成しているみたいです。
#!/usr/bin/bash
set -e
FQDN=`hostname`
ssldotconf=/etc/httpd/conf.d/ssl.conf
if test -f /etc/pki/tls/certs/localhost.crt -a \
-f /etc/pki/tls/private/localhost.key; then
exit 0
fi
if test -f /etc/pki/tls/certs/localhost.crt -a \
! -f /etc/pki/tls/private/localhost.key; then
echo "Missing certificate key!"
exit 1
fi
if test ! -f /etc/pki/tls/certs/localhost.crt -a \
-f /etc/pki/tls/private/localhost.key; then
echo "Missing certificate, but key is present!"
exit 1
fi
if ! test -f ${ssldotconf} || \
! grep -q '^SSLCertificateFile /etc/pki/tls/certs/localhost.crt' ${ssldotconf} || \
! grep -q '^SSLCertificateKeyFile /etc/pki/tls/private/localhost.key' ${ssldotconf}; then
# Non-default configuration, do nothing.
exit 0
fi
sscg -q \
--cert-file /etc/pki/tls/certs/localhost.crt \
--cert-key-file /etc/pki/tls/private/localhost.key \
--ca-file /etc/pki/tls/certs/localhost.crt \
--dhparams-file /tmp/dhparams.pem \
--lifetime 365 \
--hostname $FQDN \
--email root@$FQDN
sscgというのは、x509証明書を簡単に作れるコマンドのようです。
$ dnf info sscg
メタデータの期限切れの最終確認: 0:00:03 前の 2026年01月31日 15時53分14秒 に実施しました。
インストール済みパッケージ
名前 : sscg
バージョン : 3.0.0
リリース : 10.el9
Arch : x86_64
サイズ : 105 k
ソース : sscg-3.0.0-10.el9.src.rpm
リポジトリー : @System
repo から : appstream
概要 : Simple SSL certificate generator
URL : https://github.com/sgallagher/sscg
ライセンス : GPLv3+ with exceptions
説明 : A utility to aid in the creation of more secure "self-signed"
: certificates. The certificates created by this tool are generated in a
: way so as to create a CA certificate that can be safely imported into a
: client machine to trust the service certificate without needing to set
: up a full PKI environment and without exposing the machine to a risk of
: false signatures from the service certificate.
以下で見ると、証明書のCommon Nameはホスト名ですね。
$ curl -k -I -v https://localhost
* Server certificate:
* subject: C=US; O=Unspecified; CN=myserver.localdomain; emailAddress=root@myserver.localdomain
* start date: Jan 31 06:41:06 2026 GMT
* expire date: Jan 31 06:41:06 2027 GMT
* issuer: C=US; O=Unspecified; OU=ca-7980457008796048413; CN=myserver.localdomain; emailAddress=root@myserver.localdomain
* SSL certificate verify result: self-signed certificate in certificate chain (19), continuing anyway.
自己署名証明書です。
ちなみに、OSの証明書ストアに登録されているわけでもないのでホスト名でアクセスしてもだめです。
$ curl -I https://$(hostname)
curl: (60) SSL certificate problem: self-signed certificate in certificate chain
More details here: https://curl.se/docs/sslcerts.html
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
証明書を使うならこうですね。
$ curl --cacert /etc/pki/tls/certs/localhost.crt -I https://$(hostname)
HTTP/1.1 403 Forbidden
Date: Sat, 31 Jan 2026 07:00:23 GMT
Server: Apache/2.4.62 (Rocky Linux) OpenSSL/3.5.1
Last-Modified: Sat, 17 May 2025 02:45:05 GMT
ETag: "1dc4-6354be2d9ae40"
Accept-Ranges: bytes
Content-Length: 7620
Content-Type: text/html; charset=UTF-8