본문 바로가기
서버

[ubuntu] Let's Encrypt 와일드카드 인증서 발급받기 + 자동연장(갱신)

by for2gles 2023. 6. 29.
반응형
sudo apt-get update
sudo apt-get install certbot
sudo certbot certonly --manual -d "*.ewq.kr" -d ewq.kr --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory

 

그러면 DNS TXT 설정을 요구할것이고

DNS설정하는곳에가서 설정

나는 클라우드플레어에 가서 설정하면 됐다.

그리고 

https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.mydomain.com

본인 도메인을 입력해서 여기에서 해당 TXT가 잘 적용되었는지 확인하고

Continue 해주면 발급된다.

 

다만 발급후 메시지

NEXT STEPS: - This certificate will not be renewed automatically. Autorenewal of --manual certificates requires the use of an authentication hook script (--manual-auth-hook) but one was not provided. To renew this certificate, repeat this same certbot command before the certificate's expiry date.

 

자동 갱신을 해주도록 하자

crontab을 스케쥴링을 사용해줄 건데, sudo 권한이 필요하므로

 

sudo crontab -e

를 사용해 에디터를 실행했다.

 

그리고 하단에

0 0 5,20 * * /bin/bash -l -c 'certbot renew --quiet && docker service update web_nginx --force'

이렇게 넣어주었다.

그러면 root의 권한으로 매달 5일 20일 두번 연장을 재시도 할것이고, 내 기억으로는 완료 후에 nginx를 재시작 해주어 변경된 인증서 적용해주는것이 필요했다.

따라서 nginx를 자동 재시작 해주게 설정해주었다.

나는 도커를 쓰기 때문에 이렇게 했지만 systemctl restart nginx를 해도 무관할것이다.(root 권한이기 때문에 Sudo는 불필요)

반응형

댓글