2 분 소요

HTTPS는 더 이상 선택이 아닌 필수입니다. Let’s Encrypt는 무료로 SSL/TLS 인증서를 제공하며, Certbot 도구를 통해 발급과 갱신을 자동화할 수 있습니다.

보안 인프라 이미지

SSL 인증서로 보호되는 서버 인프라

Certbot 설치

RHEL / Rocky Linux / AlmaLinux

# EPEL 저장소 추가
dnf install epel-release -y

# Certbot 및 Nginx 플러그인 설치
dnf install certbot python3-certbot-nginx -y

Ubuntu / Debian

# 시스템 업데이트
apt update

# Snapd를 통한 설치 (권장)
apt install snapd -y
snap install core && snap refresh core
snap install --classic certbot

# 심볼릭 링크 생성
ln -s /snap/bin/certbot /usr/bin/certbot

인증서 발급

Nginx 자동 설정 방식

# Nginx 설정을 자동으로 수정하여 인증서 발급
certbot --nginx -d example.com -d www.example.com

# 이메일 주소 입력 (갱신 알림 수신용)
# Let's Encrypt 약관 동의 후 발급 완료

Standalone 방식 (포트 80 사용)

# 웹 서버를 잠시 중단하고 발급
systemctl stop nginx
certbot certonly --standalone -d example.com
systemctl start nginx

Webroot 방식 (서비스 중단 없음)

# 웹 서버 Document Root를 지정
certbot certonly --webroot \
  -w /var/www/html \
  -d example.com \
  -d www.example.com

발급된 인증서 확인

# 설치된 인증서 목록
certbot certificates

# 출력 예시:
# Found the following certs:
#   Certificate Name: example.com
#     Domains: example.com www.example.com
#     Expiry Date: 2025-12-11 (VALID: 89 days)
#     Certificate Path: /etc/letsencrypt/live/example.com/fullchain.pem
#     Private Key Path: /etc/letsencrypt/live/example.com/privkey.pem

Nginx SSL 설정

server {
    listen 443 ssl http2;
    server_name example.com www.example.com;

    # Certbot이 자동 생성한 인증서 경로
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    # HSTS 설정 (6개월)
    add_header Strict-Transport-Security "max-age=15768000" always;

    root /var/www/html;
    index index.html;
}

server {
    listen 80;
    server_name example.com www.example.com;
    return 301 https://$host$request_uri;
}

네트워크 보안 이미지

HTTPS로 암호화된 안전한 통신

자동 갱신 설정

Let’s Encrypt 인증서는 90일 유효기간으로 발급됩니다. Certbot은 기본적으로 cron이나 systemd timer로 자동 갱신을 처리합니다.

# 갱신 테스트 (실제 갱신 없이 시뮬레이션)
certbot renew --dry-run

# 자동 갱신 타이머 확인 (Ubuntu/systemd)
systemctl status snap.certbot.renew.timer

# 수동 갱신 실행
certbot renew

Cron으로 갱신 예약

# crontab 편집
crontab -e

# 매일 새벽 3시와 오후 3시에 갱신 시도
0 3,15 * * * certbot renew --quiet --post-hook "systemctl reload nginx"

갱신 후 훅 활용

# 갱신 성공 후 Nginx 리로드 자동화
certbot renew --post-hook "systemctl reload nginx"

# /etc/letsencrypt/renewal-hooks/post/ 디렉토리에 스크립트 배치
cat > /etc/letsencrypt/renewal-hooks/post/reload-nginx.sh << 'EOF'
#!/bin/bash
systemctl reload nginx
logger "SSL certificate renewed and Nginx reloaded"
EOF
chmod +x /etc/letsencrypt/renewal-hooks/post/reload-nginx.sh

와일드카드 인증서 발급

# DNS 챌린지로 와일드카드 인증서 발급
certbot certonly \
  --manual \
  --preferred-challenges dns \
  -d "*.example.com" \
  -d example.com

# DNS TXT 레코드 추가 안내가 표시됨
# _acme-challenge.example.com 에 제시된 값 추가 후 진행

인증서 삭제

# 특정 인증서 삭제
certbot delete --cert-name example.com

# 모든 설정 파일 포함 완전 삭제
certbot delete --cert-name example.com --noninteractive

Let’s Encrypt와 Certbot의 조합은 SSL 인증서 관리의 부담을 크게 줄여줍니다. 자동 갱신이 정상적으로 동작하는지 주기적으로 --dry-run으로 확인하고, 인증서 만료 알림 이메일을 꼭 확인하는 습관을 유지하세요.

댓글남기기