GrepBoard/매뉴얼
605 편 ·

Rocky 9 httpd mod_ssl 로 HTTPS 켜기

·시험 환경 Rocky Linux 9.8 (Docker rockylinux:9) · httpd 2.4.62 · mod_ssl 2.4.62 · 2026-10·시험 범위 ↓·7 단계

Rocky 9 httpd 는 mod_ssl 을 넣고 재시작하면 443 이 열리고 자체 서명 localhost.crt 를 씁니다. ssl.conf 의 인증서 두 줄을 바꾸고 httpd -t 로 확인해 갈아 끼웁니다.

Rocky 9 의 httpd 는 dnf install mod_ssl 을 한 뒤 처음 시작하거나 재시작하면 443 포트에서 HTTPS 를 받습니다. 이미 돌고 있던 httpd 는 설치만으로는 443 을 열지 않습니다([3] 끝). 처음에는 서버가 스스로 만든 자체 서명 인증서(localhost.crt)라 브라우저가 경고를 띄우고, 실제 인증서는 /etc/httpd/conf.d/ssl.conf 의 SSLCertificateFile·SSLCertificateKeyFile 두 줄을 바꿔 씁니다. 아래 명령은 모두 root 셸 기준입니다.

[1] mod_ssl 을 설치합니다. 설치 전에는 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 는 자체 서명 인증서를 만드는 도구입니다. 패키지가 놓는 파일 중 설정과 관련된 것은 이렇습니다.

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] ssl.conf 의 기본값을 봅니다. 443 을 열고, _default_:443 가상 호스트 하나가 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

SSLProtocol 줄은 없고 암호 목록은 PROFILE=SYSTEM, 즉 OS 의 시스템 암호 정책을 따르는 값입니다. 인증서를 바꾸는 데 이 줄은 건드리지 않습니다.

[3] localhost.crt 가 언제 생기는지 압니다. 패키지 설치만으로는 아직 없고, 그 상태에서 httpd -t 는 오류입니다.

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 입니다. 두 파일 중 하나라도 없을 때만 돌고, httpd.service 가 이 유닛을 Wants=·After= 로 걸고 있어 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

systemd 없이 띄우는 컨테이너에서는 이 스크립트를 직접 돌려야 생깁니다. 만든 인증서는 호스트 이름이 CN 인 자체 서명이고 유효 기간은 1년이었습니다.

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

이 상태로 띄우면 80·443 을 모두 듣고 응답도 오지만, 인증서를 검증하는 클라이언트는 받아들이지 않습니다(curl 종료 코드 60). -k 로 검증을 끄면 같은 페이지가 나옵니다.

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

httpd 를 처음 띄우는 서버라면 systemctl enable --now httpd 로 됩니다. 이미 돌고 있는 httpd 는 다릅니다. enable --now 는 이미 active 인 서비스를 다시 시작하지 않고, 돌고 있는 httpd 는 mod_ssl 의 Listen 443 을 읽은 적이 없습니다. 80 만 듣던 httpd 에 mod_ssl 을 설치하고 인증서까지 만든 뒤의 결과입니다(curl 종료 코드 7 = 연결 거부).

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

재시작해야 443 이 열립니다. Red Hat 문서도 TLS 설정 뒤 systemctl restart httpd 를 씁니다. ⚠️ 재시작은 처리 중인 연결을 끊습니다. 사용자가 적은 시간에 하고, 그 전에 인증서·키 파일이 있는지([4] 의 경로)와 httpd -t 가 Syntax OK 인지 먼저 봅니다. 인증서가 없으면 위에서 본 AH00526 으로 시작에 실패합니다.

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

실제 서버에서는 systemctl restart httpd 입니다(시험은 systemd 가 없어 httpd -k restart). 재시작 뒤 서비스가 뜨지 않으면 journalctl -u httpd 로 원인을 봅니다. 급하게 설치 전 상태로 돌리려면 ssl.conf 를 .conf 가 아닌 이름(ssl.conf.off)으로 옮기고 다시 시작합니다. Listen 443 과 기본 443 가상 호스트가 이 파일에 있으므로, 빼면 80 만 듣는 설정이 됩니다.

[4] 실제 인증서로 바꿉니다. Red Hat 문서의 순서대로 ssl.conf 의 _default_:443 안에서 바꿉니다.

1. 인증서는 /etc/pki/tls/certs/, 개인키는 /etc/pki/tls/private/ 에 둡니다. 키는 chown root:root · chmod 600 으로 root 만 읽게 합니다. 2. 중간 인증서가 있으면 서버 인증서 파일 뒤에 이어 붙입니다. Apache 2.4.8 부터 SSLCertificateFile 이 체인을 함께 받으며 SSLCertificateChainFile 은 쓰지 않습니다. 3. 같은 가상 호스트에 ServerName www.example.com 을 넣습니다(인증서의 이름과 같게). 4. 고치기 전에 원본을 복사해 둡니다.

아래는 CA 발급 인증서 대신 www.example.com 이름의 시험용 자체 서명 인증서로 돌린 결과입니다.

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

grep 은 두 줄을 편집기로 고친 뒤의 확인입니다. 적용은 systemctl reload httpd(시험은 httpd -k graceful)입니다. graceful 재시작은 처리 중인 요청을 끝낸 뒤 새 설정으로 바꿉니다. s_client 의 subject 가 새 이름이면 바뀐 것입니다.

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

[5] 따로 만든 <VirtualHost *:443> 이 먹지 않으면 httpd -S 를 봅니다. ssl.conf 를 그대로 두고 conf.d/www.example.com.conf 에 같은 이름의 443 가상 호스트를 더하자, 새 인증서가 아니라 localhost.crt 가 나갔습니다.

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)

ssl.conf 의 _default_:443 은 자기 ServerName 이 주석이라 전역 ServerName www.example.com 을 물려받았고, 같은 이름이면 먼저 읽힌 쪽이 쓰입니다(ssl.conf 가 www.example.com.conf 보다 앞). 이때 /var/log/httpd/ssl_error_log 에는 인증서 이름이 맞지 않는다는 경고가 남았습니다.

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

같은 이름이 두 번 보이면 인증서는 [4] 처럼 ssl.conf 한 곳에서 바꿉니다. 전역 ServerName 경고(AH00558)는 Rocky 9 httpd AH00558 서버 이름 경고 끄기에 있습니다.

[6] 인증서를 바꿀 때마다 httpd -t 를 먼저 돌립니다. 키 경로 오타는 여기서 바로 잡힙니다.

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

파일은 있는데 인증서와 키가 짝이 아니면 httpd -t 는 통과합니다 — 그 글의 시험에서는 graceful 에서 Apache 가 내려갔습니다. 그 경우는 Apache AH02565 인증서·키 do not match 해결을 봅니다.

[7] 바깥에서 443 으로 들어올 수 있게 합니다. firewalld 를 쓰면 firewall-cmd --permanent --add-port=443/tcp(또는 --add-service=https) 뒤 firewall-cmd --reload 입니다 — 자세한 순서는 Rocky 9 에서 firewalld 로 포트 열기에 있습니다. HTTP 로 오는 요청은 80 가상 호스트에서 넘깁니다. HTTPS 가 [4] 처럼 제대로 응답하는 것을 확인한 뒤에 합니다.

리디렉션은 새 파일 하나에 둡니다. 앞 단계의 ssl.conf·www.example.com.conf 를 덮어쓰지 않으므로, 되돌리기는 이 파일을 지우는 것으로 끝납니다. 같은 이름의 파일이 이미 없는지 먼저 봅니다.

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

처음에는 Redirect temp(302)로 겁니다. Apache 문서 기준으로 temp 는 302, permanent 는 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/

httpd -t 가 실패하면 && 때문에 다시 읽기는 하지 않고, 돌고 있는 설정이 그대로 남습니다. 실제 서버에서는 httpd -k graceful 대신 systemctl reload httpd 입니다. 브라우저로 몇 페이지 넘어가 보고 문제가 없으면 temp 를 permanent 로 바꿔 같은 순서로 다시 읽힙니다.

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/

되돌릴 때는 파일을 지우고 검사한 뒤 다시 읽힙니다. 지운 뒤에는 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

⚠️ 301 은 서버에서 되돌려도 끝나지 않습니다. HTTP 표준(RFC 9110)상 301 응답은 기본으로 캐시될 수 있어, 한 번 받은 브라우저는 파일을 지운 뒤에도 한동안 HTTPS 로 바로 갑니다. curl 처럼 캐시가 없는 도구로 서버 쪽을 확인하고, 브라우저는 캐시를 지워야 원래대로 보입니다. 그래서 302 로 먼저 확인합니다.

출처: 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)

Apache 로그를 브라우저에서 바로 분석 ↗ — 아무것도 올라가지 않습니다.

#httpd#apache#mod_ssl#https#rocky