본문 바로가기

CentOS

SSL 무료 인증서 발급하기

https://letsencrypt.org/

 

Let's Encrypt - Free SSL/TLS Certificates

 

letsencrypt.org

 

무료로 SSL 인증서를 발급받을 수 있다. 단지 1년마다 갱신해줘야 한다는 단점이 있는데 이제 소개할 Certbot ACME client를 사용하면 자동 갱신까지 된다.

 

https://certbot.eff.org/

 

Certbot

Different Internet services are distinguished by using different TCP port numbers. Unencrypted HTTP normally uses TCP port 80, while encrypted HTTPS normally uses TCP port 443. To use certbot –webroot, certbot –apache, or certbot –nginx, you should have an

certbot.eff.org

위 사이트에 접속하자.

붉은 네모로 강조한 Software와 System을 SSL 인증서를 적용할 시스템에 맞게 선택하자. 두 항목을 선택하면 너무나 감사하게도 화면 아래쪽에 설치방법이 소개 된다.

 

설치 방법이 두개로 나눠져 설명되어있다. DEFAULT 와 WILDCARD인데, DEFAULT는 특정 도메인에 대해서만, WILDCARD는 특정 도메인에 속하는 모든 서브도메인에 대해서 사용할 수 있는 SSL 인증서이다.

예를들어 내 도메인이 asusual.dev 일 때

asusual.dev에 대해서만 SSL 인증서가 필요하다면 DEFAULT를,

asusual.dev와 blog.asusual.dev, www.asusual.dev, 등과 같이 asusual.dev 하위의 모든 서브 도메인에서 사용가능한 SSL 인증서를 발급하려면 WILDCARD 인증서를 발급하면 된다.(wildcard 도메인은 root 도메인, 즉 asusual.dev에 대해 보장해주지 않는다.)

 

WILDCARD를 이용하려면 docker를 설치하거나, certbot의 manual 모드를 사용해야 한다. 우선 DEFAULT 방식으로 진행한다. 

nginx를 미리 설치해두어야 한다. 혹시 진행과정 중 nginx 모듈을 찾지 못했다는 에러가 난다면 /usr/local/sbin 경로에 nginx 실행파일을 심볼릭 링크로 걸자.

# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx

 

처음 할 일은 certbot 스크립트를 다운로드하고, 실행권한을 준 뒤, sbin 경로에 옮겨야 한다.

# cd /home/build
# curl https://dl.eff.org/certbot-auto > certbot-auto
# chmod +x certbot-auto
# mv certbot-auto /usr/local/sbin/certbot-auto

 

이제 certbot을 실행하자

# certbot-auto --nginx

필요한 패키지 중 누락된 패키지가 있다면 설치 화면이 뜬다. 그 뒤로 한참 기다리면 본격적인 발급 절차에 들어선다.

이메일을 묻고, 어딘가 가입할건지 묻는 화면이 있는데 캡쳐를 못했다. 취향껏 설정하자.

 

No names were found in your configuration files. Please enter in your domain name(s) (comma and/or space separated) (Enter 'c' to cancel):

도메인을 묻는다. DNS 검증을 거치므로 반드시 자기가 갖고있는 도메인을 입력해야한다. 참고로 입력한 도메인을 쿼리해봤을 때 그 장비의 IP가 나와야 한다. 혹시 공유기 아래에 놓인 장비라면 미리 80포트를 포트포워딩 해주는걸 잊지말자.

 

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS. You can undo this change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):

http 트래픽을 https로 리다이렉트 할 것인지 묻는다. 크롬은 http에 대해 보안 경고를 띄우므로 리다이렉트 해버리자.

 

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
...
Your cert will expire on 2020-06-03.
...

 

정상적으로 발급되었다. 한번 https로 접속해보고, http로도 접속해보자.

정상적으로 SSL 인증서가 적용되었다.

혹시라도 404가 뜬다면 너무 걱정하지 말고 두가지를 체크해보자.

서버의 firewall 설정

# firewall-cmd --permanent --add-service https

그리고 공유기의 포트포워딩(https 또는 443포트)

 

1년마다 이런 짓을 반복해야하느냐, 하면 그건 아니다. certbot-auto의 renew기능을 이용하면 되는데 별다른 입력을 요구하진 않으므로 crontab으로 설정해버려도 된다. 아래의 명령어는 certbot에서 권유하는 crontab이다.

# echo "0 0,12 * * * root python3 -c 'import random; import time; time.sleep(random.random() * 3600)' && /usr/local/bin/certbot-auto renew -q" | sudo tee -a /etc/crontab > /dev/null

 

'CentOS' 카테고리의 다른 글

Docker 설치  (0) 2020.03.13
Ruby 설치하기  (0) 2020.03.08
Nginx 설치하기  (0) 2020.03.06
RRDtool 설치하기  (0) 2020.03.01
MariaDB 튜닝하기  (0) 2020.03.01