Let’s Encrypt - Free SSL/TLS Certificates
Let’s Encrypt is a free, automated, and open certificate authority brought to you by the nonprofit Internet Security Research Group (ISRG).

Let's Encrypt라는 비영리 기관을 통해 무료로 TLS인증서를 발급받을수 있습니다.

루트 도매인, 서브 도매인, 와일드카드 도매인 인증서까지 무료로 발급 받을수 있습니다.
인증서 발급을 위해 Certbot을 사용 합니다.

Certbot
Automatically enable HTTPS on your website with EFF’s Certbot, deploying Let’s Encrypt certificates.

Certbot 홈페이지에서 자신의 서버 사양을 입력하면 설치 방법을 안내해줍니다.

Certbot 설치는 공식 홈페이지 권장하는 방법인 snap을 통해 설치합니다.

sudo snap install certbot --classic

Certbot이 인증서를 발급해주기위해 아래 과정을 진행합니다.

  1. Certbot 인증서 요청
  2. 요청한 도메인 소유주 확인
  3. 인증서 발급

3가지 방법을 통해 요청 도메인의 소유주가 자신임을 인증할 수 있습니다.

  1. standalone - 가상 웹서버를 가동하여 도메인소유주 확인
  2. webroot - 자신의 웹서버가 제공하는 특정 파일로 도메인소유주 확인
  3. dns - dns 레코드에 특정 값을 작성하여 도메인소유주 확인

우선 standalone, webroot 방식을 먼저 다루겠습니다.

1. standalone방식으로 인증서 발급

  • 80번포트가 개방되어야함 -> 이미 실행중인 서비스, 데몬이 존재시, 이를 중단해야함
  • 자동 갱신 가능
  • 와일드카드 서브도매인 사용불가 (*.example.com)
  • 도메인이 자신의 서버에 연결되어야함 (A레코드를 자신의 서버로)
  • 와일드카드 서브도메인 인증서가 필요하지 않다면 권장

certbot이 인증서를 발급할때 도메인의 소유주임을 확인하기위해 80번 포트를 사용하는 간이 웹서버를 가동합니다. 이 방식으로 인증서를 발급하려면 80번 포트를 점유하는 서비스를 중지 해야 합니다. (nginx 등등)
만약 자신의 웹서버를 중단할 수 없을경우 2번 방법을 사용하면 됩니다.

sudo certbot certonly --standalone
dev@vultr:~$ sudo certbot certonly --standalone                                   
[sudo] password for dev:   <root password>
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y <- ACME 약관에 동의하는지 N선택시 진행불가

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N <- 이메일을 통해 Let's Encrypt 프로젝트 정보를 받아볼지
Please enter in your domain name(s) (comma and/or space separated)
(Enter 'c' to cancel): vompressor.com www.vompressor.com  <- {1} 인증서를 발급할 도메인 입력
Requesting a certificate for vompressor.com and www.vompressor.com

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/vompressor.com/fullchain.pem <- {2} 발급된 인증서 경로
   Your key file has been saved at:
   /etc/letsencrypt/live/vompressor.com/privkey.pem <- {2} 발급된 인증서 경로
   Your certificate will expire on 2021-05-16. To obtain a new or
   tweaked version of this certificate in the future, simply run
   certbot again. To non-interactively renew *all* of your
   certificates, run "certbot renew"
 - 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                   

{1} 도메인을 입력할때 여러개를 입력할 수 있습니다.
ex)

example.com www.exapme.com subdomain1.example.com subdomain2.example.com

인증서가 발급되면 {2}처럼 인증서의 경로가 출력됩니다.

2. webroot방식으로 인증서 발급

  • 서버 중단없이 발급
  • 웹서버에 사전 세팅이 필요
  • 자동 갱신 가능
  • 와일드카드 서브도매인 사용불가

도메인 소유주임을 확인하기위해 certbot의 웹서버가 아닌, 서버의 웹서버에서 특정 파일을 요청하여 인증합니다.
자신의 서버를통해 소유주를 인증하여 인증서가 발급되지만 웹서버에 특정 세팅을 해야합니다.

인증에 사용할 특정 폴더를 만들고, 폴더안에는 .well-known/acme-challenge 디렉토리를 만듭니다.
ex)

# letsencrypt 폴더가 인증에 사용됨
dev@vultr:/var/www/letsencrypt/.well-known/acme-challenge$ pwd
/var/www/letsencrypt/.well-known/acme-challenge

nginx등의 웹서버로 {자신의 도메인}/.well-known/acme-challenge 안에 파일이 제공되도록 설정하고 다음 명령어로 인증서를 발급받습니다.

sudo certbot certonly --webroot
Input the webroot for www.vompressor.com: (Enter 'c' to cancel):

중간에 웹루트 경로 요구시 {webroot}의 경로를 입력하면 됩니다.

nginx를 사용해서 발급

추가

아래 과정 + 현재 Nginx config 를 TLS 연결을 사용하도록 설정을 업데이트 하는 명령이 있습니다.

sudo certbot certonly --nginx

명령어 입력 후 나오는 설명을 잘 읽어보고 인증서를 발급 받으면 됩니다.

이 방법을 사용하면 Nginx 설정이 갱신 됩니다.
꼭 Nginx 설정을 다시 확인해 주세요

==

/var/www 폴더에 mkdir 명령으로 /letsencrypt/.well-know/acme-channenge 디렉토리를 만듭니다.

/etc/nginx/sites-enabled/default를 다음으로 수정합니다.

server {
        listen 80;
        server_name yourdomain.com www.yourdomain.com; <- 자신의 도매인 입력
        
        location ^~ /.well-known/acme-challenge/ {
                default_type "text/plain"
                root /var/www/letsencrypt;
        }
}

nginx를 재시작 합니다.

sudo service nginx restart

인증서를 발급 받습니다.

sudo certbot certonly --webroot

 [Standalne처럼, 메일입력, 약관동의를 요구, 생략]
 
Please enter in your domain name(s) (comma and/or space separated)  (Enter 'c'
to cancel): www.vompressor.com <- {1} 여러개 입력 가능
Requesting a certificate for www.vompressor.com
Performing the following challenges:
http-01 challenge for www.vompressor.com
Input the webroot for www.vompressor.com: (Enter 'c' to cancel): /var/www/letsencrypt <- {2} certbot이 접근가능한 경로
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/www.vompressor.com/fullchain.pem <- {3} 인증서 경로
   Your key file has been saved at:
   /etc/letsencrypt/live/www.vompressor.com/privkey.pem <- {3} 인증서 경로
   Your certificate will expire on 2021-05-17. To obtain a new or
   tweaked version of this certificate in the future, simply run
   certbot again. To non-interactively renew *all* of your
   certificates, run "certbot renew"
 - 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

{1} 인증서를 발급받을 도메인을 입력합니다. 여러개를 입력할 수 있습니다.
{2} 입력받은 경로로 certbot이 특정 파일을 작성합니다. Let's encrypt 서버는 입력받은 경로를 웹 서버를 통해 접속하여, 특정 파일이 존재함을 확인후 인증서를 발급 합니다.
{3} 발급된 인증서 경로