Nginx에서 Let's Encrypt SSL 인증서 자동 갱신 설정하기

inguk·2024년 11월 4일

1. 문제 상황

Let's Encrypt SSL 인증서는 90일마다 만료되며, 수동으로 갱신하는 것은 번거롭습니다. 특히 Nginx를 사용하는 경우 포트 80 충돌로 인한 갱신 실패가 자주 발생할 수 있습니다.

2. 해결 방법

2.1. Certbot Nginx 플러그인 설치

sudo apt-get install python3-certbot-nginx

2.2. 인증서 갱신 설정 수정

sudo nano /etc/letsencrypt/renewal/your-domain.com.conf
//설정파일 내용
version = 1.21.0
archive_dir = /etc/letsencrypt/archive/your-domain.com
cert = /etc/letsencrypt/live/your-domain.com/cert.pem
privkey = /etc/letsencrypt/live/your-domain.com/privkey.pem
chain = /etc/letsencrypt/live/your-domain.com/chain.pem
fullchain = /etc/letsencrypt/live/your-domain.com/fullchain.pem

[renewalparams]
authenticator = nginx
installer = nginx
account = your-account-hash
server = https://acme-v02.api.letsencrypt.org/directory

2.3. 자동 갱신 설정

sudo crontab -e

다음 내용 추가:

0 0,12 * * * /usr/bin/certbot renew --quiet --nginx

2.4. 설정 테스트

# 갱신 테스트 (실제 갱신하지 않음)
sudo certbot renew --nginx --dry-run

3. 설정 확인

3.1. 인증서 만료일 확인

sudo tail -f /var/log/letsencrypt/letsencrypt.log

3.2. 자동 갱신 로그 확인

sudo tail -f /var/log/letsencrypt/letsencrypt.log

3.3. Cron 작업 확인

sudo crontab -l

4. 주요 특징

  • Nginx 플러그인을 사용하여 자동으로 웹서버 관리
  • 매일 0시와 12시에 갱신 시도
  • 만료 30일 전부터 자동 갱신 시도
  • 로그를 통한 갱신 상태 모니터링 가능

5. 문제 해결

만약 갱신이 실패하는 경우:

# 수동 갱신 시도
sudo certbot renew --force-renewal --nginx

# 로그 확인
sudo tail -f /var/log/letsencrypt/letsencrypt.log

6. 주의사항

방화벽 설정에서 포트 80과 443이 열려있어야 함
Nginx 설정 파일에 SSL 관련 설정이 올바르게 되어있어야 함
도메인의 DNS 설정이 올바르게 되어있어야 함
이제 SSL 인증서가 자동으로 갱신되며, 만료 걱정 없이 안전한 웹 서비스를 운영할 수 있습니다.

0개의 댓글