GrepBoard/Manuals
605 manuals ·

Enable HTTPS on Rocky Linux 9 httpd with mod_ssl

·Tested on Rocky Linux 9.8 (Docker rockylinux:9) · httpd 2.4.62 · mod_ssl 2.4.62 · 2026-10·Test scope ↓·7 steps

On Rocky 9, mod_ssl plus an httpd restart opens 443 with a self-signed localhost.crt. Swap in your certificate via two ssl.conf lines and check httpd -t.

On Rocky 9, httpd serves HTTPS on port 443 once you run dnf install mod_ssl and then start or restart it. An httpd that was already running does not open 443 from the install alone (end of [3]). It starts with a self-signed certificate the server generates itself (localhost.crt), so browsers warn; to use a real certificate, change the SSLCertificateFile and SSLCertificateKeyFile lines in /etc/httpd/conf.d/ssl.conf. All commands below run in a root shell.

[1] Install mod_ssl. Before that, there is no ssl_module.

console
# httpd -M 2>/dev/null | grep ssl_module; echo $?1# dnf -y install mod_ssl 2>&1 | grep -E "^(Installed:|  mod_ssl|  sscg|Complete)"; rpm -q mod_ssl opensslInstalled:  sscg-4.0.3-2.el9.x86_64            Complete!mod_ssl-2.4.62-13.el9_8.9.x86_64openssl-3.5.8-2.el9_8.x86_64

sscg, pulled in as a dependency, is the tool that generates the self-signed certificate. These are the configuration-related files the package installs:

console
# rpm -ql mod_ssl | grep -E 'conf|libexec|systemd'/etc/httpd/conf.d/rocky-snipolicy.conf/etc/httpd/conf.d/ssl.conf/etc/httpd/conf.modules.d/00-ssl.conf/usr/lib/systemd/system/httpd-init.service/usr/lib/systemd/system/httpd.socket.d/10-listen443.conf/usr/libexec/httpd-ssl-gencerts/usr/libexec/httpd-ssl-pass-dialog

[2] Look at the defaults in ssl.conf. It listens on 443 and has one _default_:443 virtual host pointing at localhost.crt.

console
# grep -nE '^(Listen|<VirtualHost|SSLEngine|SSLCertificateFile|SSLCertificateKeyFile|#SSLCertificateChainFile|SSLProtocol|SSLCipherSuite|SSLCryptoPolicy)' /etc/httpd/conf.d/ssl.conf5:Listen 443 https40:<VirtualHost _default_:443>54:SSLEngine on73:SSLCipherSuite PROFILE=SYSTEM85:SSLCertificateFile /etc/pki/tls/certs/localhost.crt93:SSLCertificateKeyFile /etc/pki/tls/private/localhost.key102:#SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt

There is no SSLProtocol line, and the cipher list is PROFILE=SYSTEM, meaning it follows the OS system-wide crypto policy. Changing the certificate doesn't touch these lines.

[3] Know when localhost.crt gets created. Installing the package doesn't create it, and in that state httpd -t fails:

console
# ls -l /etc/pki/tls/certs/localhost.crt /etc/pki/tls/private/localhost.keyls: cannot access '/etc/pki/tls/certs/localhost.crt': No such file or directoryls: cannot access '/etc/pki/tls/private/localhost.key': No such file or directory# httpd -t; echo $?AH00526: Syntax error on line 85 of /etc/httpd/conf.d/ssl.conf:SSLCertificateFile: file '/etc/pki/tls/certs/localhost.crt' does not exist or is empty1

httpd-init.service creates it. It runs only when either file is missing, and httpd.service lists it in Wants= and After=, so it runs first on systemctl start httpd.

console
# grep -E "^(Description|ConditionPathExists|ExecStart)" /usr/lib/systemd/system/httpd-init.serviceDescription=One-time temporary TLS key generation for httpd.serviceConditionPathExists=|!/etc/pki/tls/certs/localhost.crtConditionPathExists=|!/etc/pki/tls/private/localhost.keyExecStart=/usr/libexec/httpd-ssl-gencerts

In a container without systemd you have to run the script yourself. The result is self-signed, with the host name as CN, valid for one year:

console
# /usr/libexec/httpd-ssl-gencerts; echo $?0# openssl x509 -in /etc/pki/tls/certs/localhost.crt -noout -subject -issuer -enddatesubject=C=US, O=Unspecified, CN=server1, emailAddress=root@server1issuer=C=US, O=Unspecified, OU=ca-6751595745296312798, CN=server1, emailAddress=root@server1notAfter=Oct 27 09:43:46 2027 GMT

Started like this, httpd listens on 80 and 443 and answers, but a client that verifies certificates rejects it (curl exit code 60). With -k to skip verification, the same page comes back:

console
# httpd; echo $?; sleep 1; ss -ltn | grep -E ":(80|443) "0LISTEN 0      511          0.0.0.0:80        0.0.0.0:*   LISTEN 0      511          0.0.0.0:443       0.0.0.0:*   # curl -s https://127.0.0.1/; echo $?60# curl -sk https://127.0.0.1/ok

On a server where httpd has never run, systemctl enable --now httpd is enough. An httpd that is already running is different: enable --now does not restart a service that is already active, and the running httpd has never read the Listen 443 from mod_ssl. Here mod_ssl and the certificate were added to an httpd that was serving port 80 only (curl exit code 7 = connection refused):

console
# dnf -y install mod_ssl 2>&1 | grep -E "^Complete"; /usr/libexec/httpd-ssl-gencerts; echo $?Complete!0# ss -ltn | grep -E ":(80|443) "; curl -sk https://127.0.0.1/; echo $?LISTEN 0      511          0.0.0.0:80        0.0.0.0:*   7

Port 443 opens only after a restart; the Red Hat docs also run systemctl restart httpd after TLS setup. ⚠️ A restart drops connections in progress. Do it at a quiet time, and first confirm the certificate and key files exist (paths in [4]) and that httpd -t says Syntax OK. Without the certificate, startup fails with the AH00526 shown above.

console
# httpd -t; echo $?Syntax OK0# httpd -k restart; echo $?; sleep 2; ss -ltn | grep -E ":(80|443) "; curl -sk https://127.0.0.1/0LISTEN 0      511          0.0.0.0:80        0.0.0.0:*   LISTEN 0      511          0.0.0.0:443       0.0.0.0:*   ok

On a real server that is systemctl restart httpd (the test has no systemd, hence httpd -k restart). If the service does not come back, read journalctl -u httpd. To get back to the pre-install state in a hurry, rename ssl.conf to a name that does not end in .conf (ssl.conf.off) and start again. Listen 443 and the default 443 virtual host live in that file, so without it httpd listens on 80 only.

[4] Swap in your certificate. Following the Red Hat documentation, change it inside _default_:443 in ssl.conf:

1. Put the certificate in /etc/pki/tls/certs/ and the private key in /etc/pki/tls/private/. Make the key readable by root only: chown root:root and chmod 600. 2. If you have intermediate certificates, append them to the server certificate file. Since Apache 2.4.8, SSLCertificateFile loads the chain too, and SSLCertificateChainFile is obsolete. 3. Add ServerName www.example.com to the same virtual host (matching the name in the certificate). 4. Copy the original before editing.

This run uses a self-signed test certificate for www.example.com in place of a CA-issued one:

console
# cp -a /etc/httpd/conf.d/ssl.conf /root/ssl.conf.bak && ls -l /root/ssl.conf.bak-rw-r--r-- 1 root root 8720 Oct 22 21:02 /root/ssl.conf.bak# grep -nE '^SSLCertificate(Key)?File' /etc/httpd/conf.d/ssl.conf85:SSLCertificateFile /etc/pki/tls/certs/www.example.com.crt93:SSLCertificateKeyFile /etc/pki/tls/private/www.example.com.key# httpd -t; echo $?Syntax OK0# httpd -k graceful; echo $?; sleep 20# curl -sS --resolve www.example.com:443:127.0.0.1 --cacert /etc/pki/tls/certs/www.example.com.crt https://www.example.com/ok# openssl s_client -connect 127.0.0.1:443 -servername www.example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -enddatesubject=CN=www.example.comnotAfter=Nov 26 09:45:36 2026 GMT

The grep checks the two lines after editing them in an editor. Apply with systemctl reload httpd (the test used httpd -k graceful); a graceful restart finishes in-flight requests before switching to the new configuration. If s_client shows the new subject, the swap worked.

console
# cp -a /root/ssl.conf.bak /etc/httpd/conf.d/ssl.conf && httpd -t && httpd -k graceful; echo $?Syntax OK0

[5] If a separate <VirtualHost *:443> you added has no effect, run httpd -S. With ssl.conf left as it was and a same-name 443 virtual host added in conf.d/www.example.com.conf, the server still sent localhost.crt, not the new certificate:

console
# curl -sS --resolve www.example.com:443:127.0.0.1 --cacert /etc/pki/tls/certs/www.example.com.crt https://www.example.com/; echo $?curl: (60) SSL certificate problem: self-signed certificate in certificate chain…60# httpd -S 2>&1 | grep -A3 "^\*:443"*:443                  is a NameVirtualHost         default server www.example.com (/etc/httpd/conf.d/ssl.conf:40)         port 443 namevhost www.example.com (/etc/httpd/conf.d/ssl.conf:40)         port 443 namevhost www.example.com (/etc/httpd/conf.d/www.example.com.conf:1)

The _default_:443 host in ssl.conf has its own ServerName commented out, so it inherited the global ServerName www.example.com; with two hosts of the same name, the one read first wins (ssl.conf sorts before www.example.com.conf). /var/log/httpd/ssl_error_log logged a name-mismatch warning:

output
[Tue Oct 27 09:43:46.908719 2026] [ssl:warn] [pid 250:tid 250] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name

If the same name shows up twice, change the certificate in one place, ssl.conf, as in [4]. The global ServerName warning (AH00558) is covered in Fix httpd AH00558 Could not reliably determine FQDN on Rocky 9.

[6] Run httpd -t every time you change a certificate. A typo in the key path is caught right there:

console
# httpd -t; echo $?AH00526: Syntax error on line 6 of /etc/httpd/conf.d/www.example.com.conf:SSLCertificateKeyFile: file '/etc/pki/tls/private/www.example.org.key' does not exist or is empty1

If both files exist but the certificate and key are not a pair, httpd -t passes — in that guide's test, Apache went down on graceful. See Fix Apache AH02565: Certificate and private key do not match.

[7] Let clients reach 443 from outside. With firewalld, run firewall-cmd --permanent --add-port=443/tcp (or --add-service=https), then firewall-cmd --reload; the full steps are in Open a Port with firewalld on Rocky Linux 9. Redirect plain HTTP from a port 80 virtual host, but only after HTTPS answers correctly as in [4].

Put the redirect in a new file of its own. It leaves ssl.conf and www.example.com.conf from the earlier steps untouched, so undoing it means deleting this one file. First make sure no file with that name exists:

console
# ls /etc/httpd/conf.d/www.example.com-http.confls: cannot access '/etc/httpd/conf.d/www.example.com-http.conf': No such file or directory

Start with Redirect temp (302). Per the Apache docs, temp sends 302 and permanent sends 301.

/etc/httpd/conf.d/www.example.com-http.conf
<VirtualHost *:80>    ServerName www.example.com    Redirect temp / https://www.example.com/</VirtualHost>
console
# httpd -t && httpd -k graceful; echo $?; sleep 2Syntax OK0# curl -sI -H "Host: www.example.com" http://127.0.0.1/ | grep -iE "^(HTTP|Location)"HTTP/1.1 302 FoundLocation: https://www.example.com/

If httpd -t fails, && skips the reload and the running config stays in place. On a real server use systemctl reload httpd instead of httpd -k graceful. Click through a few pages in a browser; if all is well, change temp to permanent and reload the same way:

console
# grep -n Redirect /etc/httpd/conf.d/www.example.com-http.conf3:    Redirect permanent / https://www.example.com/# httpd -t && httpd -k graceful; echo $?; sleep 2Syntax OK0# curl -sI -H "Host: www.example.com" http://127.0.0.1/ | grep -iE "^(HTTP|Location)"HTTP/1.1 301 Moved PermanentlyLocation: https://www.example.com/

To undo, delete the file, check, and reload. After deletion the response went back to 200:

console
# rm /etc/httpd/conf.d/www.example.com-http.conf && httpd -t && httpd -k graceful; echo $?; sleep 2Syntax OK0# curl -sI -H "Host: www.example.com" http://127.0.0.1/ | grep -iE "^HTTP"HTTP/1.1 200 OK

⚠️ Undoing a 301 on the server is not the end of it. Under the HTTP standard (RFC 9110) a 301 response is cacheable by default, so a browser that has seen it keeps going straight to HTTPS for a while after the file is gone. Check the server side with a cache-free tool such as curl; browsers need their cache cleared. That is why 302 comes first.

Sources: Red Hat Enterprise Linux 9 — Adding TLS encryption to an Apache HTTP Server · Apache mod_ssl — SSLCertificateFile · Apache — Name-based Virtual Host Support · Apache mod_alias — Redirect · RFC 9110 — 301 Moved Permanently · systemctl(1)

Analyze your Apache log in the browser ↗ — nothing is uploaded.

#httpd#apache#mod_ssl#https#rocky