0. 일단 http(80) 포트 끄기
1. 발급 받기
2. 경로 확인해서 .pem 파일들 서버 프로그램에 먹이기
3. 재발급
0. 라이브러리 설치 및 관련 포트 끄기
1. certbot 설치 (Ubuntu 기준)
sudo apt update
sudo apt install certbot python3-certbot-nginx
2. Nginx 일시 중지 (도커 컨테이너 멈춤)
docker-compose stop nginx
(도커 아닌경우) 로컬에서 Nginx종료
Problem binding to port 80: Could not bind to IPv4 or IPv6. 오류 떴을때
# process 확인
sudo lsof -i :80
# nginx 중지
sudo systemctl stop nginx
# nginx 재시작
sudo systemctl start nginx
1. certbot으로 인증서 발급
이 명령은 80 포트를 직접 바인딩해서 인증을 수행하기 때문에, Nginx 컨테이너를 멈춰야 함
sudo certbot certonly --standalone -d hacktheworldctf.xyz
인증서 확인
인증서가 아래에 저장됨:
/etc/letsencrypt/live/hacktheworldctf.xyz/
필요한 파일:
fullchain.pem
privkey.pem
2. 복사 또는 마운트
경로 확인해서 .pem 파일들 서버 프로그램에 먹이기
이 인증서를 서버 프로그램이 조할 수 있는 위치로 복사
sudo mkdir -p /home/ssl/hacktheworldctf.xyz
sudo cp /etc/letsencrypt/live/hacktheworldctf.xyz/fullchain.pem /home/ssl/hacktheworldctf.xyz/
sudo cp /etc/letsencrypt/live/hacktheworldctf.xyz/privkey.pem /home/ssl/hacktheworldctf.xyz/
3. 재발급
현재 외부 인증서 확인
echo | openssl s_client -connect safe-hi.xyz:443 -servername safe-hi.xyz 2>/dev/null \
| openssl x509 -noout -enddate -serial -issuer
certbot이 가지고 있는 인증서 경로 확인
sudo certbot certificates

아래 명령 후 서버에서 읽도록 재 부팅
certbot renew
예를들어 nginx가 물고있는 인증서 다시 물리기
certbot renew \
--deploy-hook "systemctl reload nginx"
자동 갱신이 제대로 되려면 반드시 필요한 3가지
- /etc/letsencrypt/renewal/<domain>.conf가 정상이어야 함
- /etc/letsencrypt/live/<domain>/ 구조가 정상이어야 함
- certbot renew 명령이 에러 없이 끝나야 함
⭐ 자동 갱신을 다시 정상화하는 방법
이번에 네가 “완전 재발급”을 진행하면 아래 세 가지가 자동으로 복원됨:
- /etc/letsencrypt/renewal/yangcheon.ai.kr.conf 새로 생성됨
- /etc/letsencrypt/live/yangcheon.ai.kr/ 정상 구조 생성됨
- renewal 프로세스 정상 작동 시작
그때부터는 systemd timer가 알아서 갱신함.
자동 갱신이 돌아가는지 직접 확인:
sudo certbot renew --dry-run