작업 전 확인
어느 조치를 하든 여기서 시작한다. SSH로 접속하고, sudo 권한이 있어야 한다.
웹서버 종류와 버전을 확인한다.
ps -ef | grep -E 'httpd|apache2' | grep -v grep
httpd -v 2>/dev/null || apache2 -v # 버전 (Debian 계열은 apache2)
httpd -V 2>/dev/null || apache2ctl -V # HTTPD_ROOT·SERVER_CONFIG_FILE 경로 출력
TLS 1.3은 OpenSSL 1.1.1 이상에서 쓸 수 있다(mod_ssl 공식 문서). 구버전 httpd는 TLSv1.3 키워드를 아예 모른다. configtest에서 걸리면 1.2까지만 설정한다.
설정 파일 위치는 -V 출력에 나온다.
-D HTTPD_ROOT="/etc/httpd"
-D SERVER_CONFIG_FILE="conf/httpd.conf"
SSL 설정은 보통 conf.d/ssl.conf(RHEL)나 sites-enabled/*(Debian)에 있다. 이렇게 찾는다.
grep -rn "SSLProtocol\|SSLCertificateFile" /etc/httpd/ /etc/apache2/ 2>/dev/null
여기 나온 SSLCertificateFile, SSLCertificateKeyFile 값이 인증서 경로다.
TLS 1.0, 1.1 끄고 TLS 1.3 켜기
SSL 설정 파일(VirtualHost 443 또는 전역)에 넣는다.
# OpenSSL 1.1.1+ 환경
SSLProtocol -all +TLSv1.2 +TLSv1.3
# TLSv1.3 을 모르는 구버전이면
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
두 표기 모두 mod_ssl 공식 문법이다. -all +...는 전부 끈 뒤 고른 것만 켜고, all -...는 전부 켠 뒤 뺀다.
보안 헤더
mod_headers가 켜져 있어야 한다(Debian은 a2enmod headers).
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set Content-Security-Policy "default-src 'self'"
HTTP → HTTPS 리다이렉트
80 포트 VirtualHost에 넣는다.
<VirtualHost *:80>
ServerName 도메인
Redirect permanent / https://도메인/
</VirtualHost>
약한 키나 서명이면 인증서 교체
절차는 Apache와 IIS 인증서 교체 절차에 있다. 2.4.8 미만은 SSLCertificateChainFile을 따로 지정해야 하니 주의한다.
신규 도메인 인증서 설치
발급과 파일 준비는 발급 공통 가이드에서 먼저 끝낸다.
파일은 /etc/httpd/ssl/ 같은 곳에 두고, 개인키는 chmod 600으로 막는다. 그다음 VirtualHost를 추가한다.
<VirtualHost *:443>
ServerName 새도메인
SSLEngine on
# 2.4.8+ : fullchain 한 파일
SSLCertificateFile /etc/httpd/ssl/fullchain.pem
SSLCertificateKeyFile /etc/httpd/ssl/privkey.pem
# 2.4.8 미만은 분리:
# SSLCertificateFile /etc/httpd/ssl/cert.pem
# SSLCertificateChainFile /etc/httpd/ssl/chain.pem
</VirtualHost>
<VirtualHost *:80>
ServerName 새도메인
Redirect permanent / https://새도메인/
</VirtualHost>
진단 툴이나 openssl로 확인한다. 버전별 체인 지정 실수는 교체 절차 글에 있다.
재검사
진단 툴로 다시 검사한다. 결과는 최대 10분 캐시된다.
공식 문서
- mod_ssl: SSLProtocol, SSLCertificateFile, SSLCertificateChainFile(2.4.8부터 deprecated)
- mod_headers: Header 지시자
- apachectl: configtest, graceful