본문 바로가기
정보/웹서비스 Tip

Nginx SSL 보안 인증서 갱신

by 서율97 2024. 2. 2.

Nginx 설치와 도메인은 이미 연결되있다고 가정

 

sudo add-apt-repository ppa:certbot/certbot
sudo apt install python-certbot-nginx

/* -d 구입한 도메인 */
sudo certbot --nginx -d test.co.kr -d www.test.co.kr

 

Let's Encrypt 는 90일짜리 인증서이기 때문에 마지막 갱신 후 2~3개월 사이에 인증서를 갱신시켜줘야함

 

- 인증서 갱신 테스트

sudo certbot renew --dry-run

 

- 인증서 갱신

sudo certbot renew


- 인증서 만료일 확인

sudo certbot certificates

 

 

- 인증서 자동 갱신(crontab)

/* date로 현재시간 일치여부 확인( UTC면 KST로 변경 ) */

sudo ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime



sudo crontab -e

/* 에디터 선택 ( 본인은 vim으로 함 ) */



/* 크론탭 제일 마지막 줄에서 엔터 후 입력 */
/* 매달 1일 3시에 갱신 시도, 갱신 후 nginx 재시작 */

0 3 1 * * sudo certbot renew --pre-hook "sudo systemctl stop nginx" --post-hook "sudo systemctl restart nginx"


/* 크론탭 저장 후 나옴 */
:wq


/* 크론탭 갱신 */

sudo service cron restart