Ubuntu에 letsencrypt를 통해 https를 세팅해보자
06 Feb 2023 | linux ubuntu letsencrypt https
목차
개요
https를 사용하기 위해서는 인증서가 필요하다. 그러나 공인되지 않은 인증서의 경우 브라우저에서 경고를 띄우기 때문에 공인된 인증서를 사용해야 한다. letsencrypt를 통해 공인인증서로 https를 세팅해보자.
필자가 기술하는 방법은 letsencrypt로 도메인의 와일드카드 인증서를 발급하는 방법이다.
letsencrypt는 무료 인증서지만 인증서 기간이 90일이므로 90일마다 갱신해주어야 한다.
설치
apt-get install -y letsencrypt
apt-get install -y certbot
인증서 발급
명령어의 domain.com
값을 실제 도메인 값으로 변경한다.
-d
옵션을 통해 인증서를 발급받을 도메인을 지정할 수 있다.
-d
옵션을 여러번 사용하여 여러 도메인에 대한 인증서를 발급받을 수 있다.
certbot certonly --manual --preferred-challenges dns
-d domain.com \
-d *.domain.com \
-d *.test.domain.com
처음 진행한다면 이메일을 기입하고 몇가지 정책에 대한 동의를 해야 한다.
이후 아래와 같은 메시지가 나온다.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name:
_acme-challenge.test.domain.com.
with the following value:
IAD9na8emo0ZqFbLs5DPQsf4ii6ii9HI4ZHc5Le4JJI
Before continuing, verify the TXT record has been deployed. Depending on the DNS
provider, this may take some time, from a few seconds to multiple minutes. You can
check if it has finished deploying with aid of online tools, such as the Google
Admin Toolbox: https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.uu.iasdf.com.
Look for one or more bolded line(s) below the line ';ANSWER'. It should show the
value(s) you've just added.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue
자신의 도메인 설정 페이지에서 다음과 같이 설정해준다.
_acme-challenge.test.domain.com.
해당 도메인에 대한 TXT 레코드를 추가해야 하니
_acme-challenge.test
입력
유형(type)은 TXT
이후 value 값에 위에서 나온 값 IAD9na8emo0ZqFbLs5DPQsf4ii6ii9HI4ZHc5Le4JJI
를 입력한다.
설정을 완료하였다면 저장하고 nslookup 명령어를 통해 txt 레코드가 잘 등록되었는지 확인한다.
nslookup -q=txt _acme-challenge.test.domain.com
결과
Server: 172.27.160.1
Address: 172.27.160.1#53
Non-authoritative answer:
_acme-challenge.iasdf.com text = "IAD9na8emo0ZqFbLs5DPQsf4ii6ii9HI4ZHc5Le4JJI"
Authoritative answers can be found from:
이후 Enter
키를 눌러 인증서 발급을 진행한다.
오류가 발생한다면 한 번 더 실행해보고 그래도 오류가 발생한다면 구글링을 통해 찾아보자.
인증서 적용
정상적으로 발급이 완료되었다면 /etc/letsencrypt/
에 인증서가 생성된다.
아래와 같이 인증서가 생성된다.
/etc/letsencrypt/
- live/
- domain.com/
- cert.pem
- chain.pem
- fullchain.pem
- privkey.pem
- archive/
- domain.com/
- cert1.pem
- chain1.pem
- fullchain1.pem
- privkey1.pem
- renewal/
- domain.com.conf
archive 의 fullchain1.pem 파일이 인증서, privkey1.pem 파일이 개인키이다.
필자는 해당 두개의 파일을 따로 저장하였다.
cp -r fullchain1.pem /path/to/domain.com.crt
cp -r privkey1.pem /path/to/domain.com.key
nginx를 사용한다면 아래와 같이 설정해주면 된다.
ssl_certificate /path/to/domain.com.crt; #인증서 경로
ssl_certificate_key /path/to/domain.com.key; #인증서 키 경로
Comments