본문 바로가기

개발바닥/BackEnd

무료 SSL인증서 발급 with Let's Encrypt

안녕하세요 devport 입니다. https 사이트를 운영하기 위해선 SSL 인증서가 필수적으로 필요합니다. 무료로 SSL을 설치할 수 있는 Let's Encrypt를 사용하여 제 개인 서버에 적용해보고자 합니다.

 

Let's Encrypt는?

  • 인증서는 3개월이 유효하고 주기적으로 갱신 필요
  • 인증서를 발급받기 위해선 root 권한을 사용
  • Public 도메인이 할당된 서버에서만 발급이 가능
  • 도메인 인증자 이메일을 계정당 1개의 인증서만 무료
  • 1일 3회 이상 발급을 시도 할 수 없으므로 실수 하지 않도록 주의가 필요

 

Certbot 설치

Let's Encrypt를 설치하기 위해서는 Certbot을 설치가 필요합니다.

# EPEL repository 활성화
$ yum -y install epel-release
# amazon linux 2 에서 EPEL 활성화
$ sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
$ sudo yum-config-manager --enable epel

# certbot-nginx 설치
$ sudo yum install -y certbot python2-certbot-nginx

# 외부 인터넷을 사용할 수 없는 서버를 위하여 certbot 설치에 필요한 rpm들을 다운로드 받을 수 있습니다.
$ sudo yum install certbot python2-certbot-nginx --downloadonly --downloaddir=/root/certbot

Certbot 명령어 설명

sudo certbot --nginx --standalone -d example.com centonly
  • apache / nginx
  • standalone / webroot: 인증서 발급 방식, 세가지 방식을 직접 선택할 경우 --manual 옵션을 붙일 것, Dns 방식의 경우 --preferred-challenges dns 값을 붙인다.
  • -d [도메인 이름]: 발급할 인증서의 도메인을 입력하는 부분, 여러 도메인을 입력해야할 경우 ,(콤마)로 구분 입력
  • certonly: 웹 서비스 설정 파일에 인증서 관련 내용을 임의로 수정하지 못하도록 한다.

 

Nginx 서버에 반영하기

인증서가 생성이 완료된다면 "/etc/letsencrypt/live/[신청한 인증서의 도메인명].com" 위치에 저장됨

생성되는 파일들은 아래와 같이 생성이 된다.

cert.pem
chain.pem
fullchain.pem
privkey.pem

example.com의 Nginx 서버에 설정한다면 위치를 다음과 같이 설정한다. (위치: /etc/nginx/nginx.conf)

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name exaple.com www.example.com;
    root /usr/share/nginx/html;
    # include /etc/nginx/example.com.conf.d/*.conf;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/privket.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

중지 되었던 웹 서비스를 다시 시작한다.

웹사이트에서 인증서가 제대로 발급된지 확인을 한다. (URL의 자물쇠 모양을 클릭하여 인증서를 확인할 수 있다.)

인증서의 발급자가 Let's Encrypt Authority X3으로 생성되는지 확인한다.

참고 : https://certbot.eff.org