https 적용

by yuyeol3, 2025-02-11


1. 개요

1. https란?

  • 웹 프로토콜 http의 보안 버전
  • 암호화 프로토콜을 사용해 통신을 암호화
    • 개인 키 : 웹 서버에서 관리, 전송받은 데이터를 복호화하는데 사용
    • 공개 키 : 웹 서버와 사용하는 모든 사람이 접근 가능. 전송할 데이터를 암호화하는데 사용

2. Let's Encrypt

  • Let's Encrypt
  • https 확산을 위해 인증서를 무료로 발급
  • 인증서 유효기간은 90일(주기적 갱신 필요)

2. 적용 방법

1. certbot 설치

$ sudo apt update & sudo apt upgrade
$ sudo add-apt-repository ppa:certbot/certbot  # certbot 리포지토리 권한 부여
$ sudo apt install python3-certbot-nginx

2. ssl 인증서 취득(nginx 플러그인 이용)

$ sudo certbot --nginx -d [도메인 이름]

3. nginx 재시작

$ sudo service nginx restart

3. 갱신 방법

$ sudo certbot renew --nginx

혹은 아래와 같이 /bin 아래에 자동화 스크립트를 만들고, cron에 등록한다

1. 스크립트 생성

$ cd /bin
$ sudo nano recert_https.sh
#!/bin/sh

sudo certbot renew --nginx > ~/wigit/cert_renew.log
sudo service nginx restart

2. 권한 부여 및 cron 등록

$ sudo chmod +x recert_https.sh
$ sudo crontab -e
# recert_https.sh
0 1 30 * * recert_https.sh # 매월 30일 1시 30분에 recert_https.sh 실행
$ sudo service cron start