본문 바로가기
WebApp

[HTTPS] certbot을 통한 nginx에서 HTTPS 설정.

by ds31x 2023. 9. 10.

환경

  • Ubuntu 22.04.3 LTS
  • certbot 1.21.0

certbot설치

다음 명령어로 certbot을 설치함.

sudo apt install certbot python3-certbot-nginx

certification 발행받기.

아래 진행은 도메인 네임 ds31x.site 라는 도메인 명에서 code.test.me 서브도메인 명을 certbot의 chain으로 삼아 certification을 발행받는 것을 목표로 함. (해당 도메인 명들을 자신의 것으로 바꾸어야 함)

sudo certbot -d test.me -d code.test.me --manual --preferred-challenges dns certonly --dry-run
  • --dry-run 옵션은 일종의 시뮬레이션으로 성공해도 실제 certification 발행이 되지 않는다.
  • 즉, 테스트용이다.
  • 1시간 정도에 계속해서 certification발행 과정에 문제가 발생하면 letsencrypt에서 해당 도메인명에 대한 인증서 발급이 일정시간 잠기기 때문에 꼭 --dry-run으로 성공하고 나서 실제 진행을 하길 권한다.
  • 처음에 약 3시간 정도 잠겼던 경험이 있음.

질문 등에 합리적(?)으로 대답해야 한다.
인증서 갱신 안내 등을 받을 email address와 서비스 약관동의 등에 대한 질문이 있다.

 

가장 중요한 건 인증서를 발급받을 대상 도메인 이름의 소유자 인지 체크하는 부분으로 DNS TXT record를 지시한 키와 값으로 추가하고 이를 확인하는 부분이다.

대략 다음과 같은 메시지이다.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name:

_acme-challenge.code.test.me.

with the following value:

_b5snIfsfybd8PhH8KjBnv_VZNa2S-zIuewzggNEi48
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue
  • 해당 검증을 위해선 도메인 TXT record를 수정하고 나서
  • 반드시 dig등을 통해 실제 수정이 되었는지를 확인하고 난 이후 certification 발급을 진행하기위한 Enter를 입력해야 한다.
  • 다른 terminal을 띄우고 꼭 해당 TXT record가 제대로 반영이 된 것을 확인하고 나서 해야 한다.

dighost 명령어로 해당 문자열이 TXT record로 제대로 반영되었는지를 확인해야 한다.

다음은 host로 TXT record를 확인한 경우임.

$ host -t txt _acme-challenge.code.test.me
_acme-challenge.code.test.me descriptive text "_b5snIfsfybd8PhH8KjBnv_VZNa2S-zIuewzggNEi48"

다음은 dig를 사용한 경우임.

$ dig _acme-challenge.code.test.me TXT

; <<>> DiG 9.18.12-0ubuntu0.22.04.2-Ubuntu <<>> _acme-challenge.code.test.me TXT
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 21015
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;_acme-challenge.codetest.me. IN    TXT

;; ANSWER SECTION:
_acme-challenge.code.test.me. 60 IN  TXT     "_b5snIfsfybd8PhH8KjBnv_VZNa2S-zIuewzggNEi48"

;; Query time: 40 msec
;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
;; WHEN: Sun Sep 10 14:20:24 UTC 2023
;; MSG SIZE  rcvd: 116

해당 검증과정에서 여러 TXT record입력을 요구할 때, 앞서 입력한 TXT record를 변경하지 말고 새로 추가해서 처리해야 한다.
(여러개를 추가해도 되니 꼭 새로 추가로 처리하자.)


nginx 설정에 HTTPS 통신 구성하기

다음 명령어를 통해 certbot이 자동으로 설정을 추가해준다.

sudo certbot --nginx -d code.test.me

문제없이 진행되면 다음과 같은 메시지가 뜬다

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Requesting a certificate for code.test.me

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/code.test.me/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/code.test.me/privkey.pem
This certificate expires on 2023-12-09.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Deploying certificate
Successfully deployed certificate for code.ds31x.site to /etc/nginx/sites-enabled/대상nginx.conf
Congratulations! You have successfully enabled HTTPS on https://code.test.me

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  • /etc/nginx/sites-enabled/대상nginx.conf을 확인하여 문제 없는지 체크한다.
  • sudo nginx -t 로 확인해서 문제 없는지 체크하는게 좋다.

nginx를 바뀐 설정으로 다시 시작시킨다.


sudo systemctl reload nginx.service
  • 웹브라우저로 https 동작여부를 확인한다.

참고자료

https://atl.kr/dokuwiki/doku.php/let_s_encrypt_certbot_wildcard_certificates

 

let_s_encrypt_certbot_wildcard_certificates [AllThatLinux!]

— 이강우 2020/12/13 14:36 이 문서는 Let's Encrypt에서 발급해주는 와일드카드 인증서를 발급받는 방법을 설명한다. 와일드카드 인증서는 당연하게도 도메인에 대한 소유 권한이 있어야 한다. 인증서

atl.kr

https://yoyostudy.tistory.com/60

 

[SSL] Ubuntu NGINX + SSL(HTTPS) 적용, 자동갱신

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 1. 이메일 입력( 인증서

yoyostudy.tistory.com

https://velog.io/@jakeshin/AWS-EC2%EC%97%90-code-server-%EC%84%A4%EC%B9%98%ED%95%98%EA%B3%A0-%EC%BB%A4%EC%8A%A4%ED%85%80-%EB%8F%84%EB%A9%94%EC%9D%B8-ssl-%EB%B0%B0%ED%8F%AC%EA%B9%8C%EC%A7%80

 

AWS EC2에 code-server 설치하고 커스텀 도메인 ssl 배포까지

code-server는 웹에서 VS-Code를 쓸 수 있도록 해주는 서비스다. 전역 후 아이패드로 코딩할 생각에 행복회로를 돌리던 나는 미리 구현해놓기로 했다...

velog.io

 

https://www.hakawati.co.kr/entry/Code-Server-%EA%B5%AC%EC%B6%95%ED%8E%B8#code-server%20%EA%B5%AC%EC%B6%95-1

 

Code Server - 구축편

페이지 목차 Code Server - 구축편 컨텐츠 목차 소개 구축 code-server 구축 및 설정 code-server 구축 code-server 운영 옵션 code-server 시스템 서비스 설정 NginX 구축 및 설정 NginX 구축 NginX의 패스워드 인증 구

www.hakawati.co.kr

 

728x90

'WebApp' 카테고리의 다른 글

[HTTPS] Certification 갱신 : certbot renew  (0) 2023.09.10
[HTTPS] certbot 사용법 : chain 삭제  (0) 2023.09.10
[Nginx] 설치 및 설정 추가.  (0) 2023.09.08
[WebApp] NginX 설정 관련 .  (0) 2023.08.01
[WebApp] CGI vs. WSGI  (0) 2023.07.31