Letsencrypt는 모질라재단의 무료SSL 인증서 발급 프로젝트다.
인증서 유효기간이 90일뿐이지만 자동 갱신설정으로 영구히 무료 SSL인증서를 이용할 수 있다.
아래는 CentOS, Nginx이 구축된 서버에 SSL인증서를 발행하기 위한 letsencrypt 패키지 설치와 SSL 자동 갱신 방법이다.
○ 설치환경
* CentOS 7 (Linux 3.10.0-514.26.2.el7.x86_64)
* NginX Version : nginx-1.9.9
* 발급하려는 도메인으로 웹서버 구성이 되어 있어야 한다. (설치 프로그램이 도메인의 80포트 오픈여부를 확인한다)
○ Let’s encrypt 무료 SSL 인증서 발급
필수 라이브러리 설치
$ rpm -ivh https://rhel7.iuscommunity.org/ius-release.rpm $ yum install git python27 python27-devel python27-pip python27-setuptools python27-virtualenv python27-libs $ git clone https://github.com/certbot/certbot
저장소 추가 및 설치
$ yum install epel-release $ yum install python-certbot-nginx
WebRoot방식 도메인 인증을 위한 폴더 준비
$ mkdir /var/www/certbot-webroot $ chown nginx:nginx /var/www/certbot-webroot $ chmod 700 /var/www/certbot-webroot
※ 폴더는 NginX 서버 환경에 맞게 준비한다.
nginx.conf 에 블록 추가
location /.well-known { root /var/www/certbot-webroot/; }
※ 블록 추가후 nginx 재기동
인증서 발급
$ /root/certbot/certbot-auto certonly --server https://acme-v01.api.letsencrypt.org/directory \ --rsa-key-size 4096 --agree-tos --email 이메일주소 \ --webroot -w /var/www/certbot-webroot -d www.도메인.com -d m.도메인.com
※ -d 옵션으로 필요한 서브도메인을 나열한다. (주의: '*.도메인' 은 발행이 안된다)
아래처럼 표시되면 인증서 발급이 성공한것이다
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for www.도메인.co.kr
http-01 challenge for 도메인.co.kr
http-01 challenge for www.도메인.kr
http-01 challenge for 도메인.kr
Using the webroot path /usr/local/도메인/certbot-webroot for all unmatched domains.
Waiting for verification...
Cleaning up challenges
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/www.도메인.co.kr/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/www.도메인.co.kr/privkey.pem
Your cert will expire on 2018-02-24. To obtain a new or tweaked
version of this certificate in the future, simply run certbot-auto
again. To non-interactively renew *all* of your certificates, run
"certbot-auto renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF:
발급 인증서 확인
$ certbot certificates
아래와 같이 표시된다
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Attempting to parse the version 0.19.0 renewal configuration file found at /etc/letsencrypt/renewal/www.도메인.co.kr.conf with version 0.14.1 of Certbot. This might not work.
-------------------------------------------------------------------------------
Found the following certs:
Certificate Name: www.도메인.co.kr
Domains: www.도메인.co.kr 도메인.co.kr 도메인.kr www.도메인.kr
Expiry Date: 2018-02-24 12:47:54+00:00 (VALID: 89 days)
Certificate Path: /etc/letsencrypt/live/www.도메인.co.kr/fullchain.pem
Private Key Path: /etc/letsencrypt/live/www.도메인.co.kr/privkey.pem
-------------------------------------------------------------------------------
○ SSL 인증서 설치
nginx.conf 에 SSL설정
ssl on; ssl_certificate /etc/letsencrypt/live/www.도메인.co.kr/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/www.도메인.co.kr/privkey.pem;
재기동 하면 SSL인증서 발급과 설치가 완료됩니다.
※ 발급(설치)된 SSL 인증서 테스트: https://www.ssllabs.com/ssltest
○ Let’s encrypt 무료 SSL 인증서 자동 갱신 방법
Let’s encrypt 무료 SSL은 만료일 30일 이전부터 갱신이 가능하다. 자동갱신을 통해 편리하게 유지할 수 있어 추천하는 방식으로 자동 갱신 설정 전 아래와 같이 테스트를 하여 자동갱신에 문제 없는지 확인한다.
인증서 갱신 테스트
$ certbot renew --dry-run
crontab에 인증서 갱신 명령 등록하기
0 1 1 * * /usr/bin/certbot renew --quiet --renew-hook "service nginx reload"
※ 매월 1일 1시에 SSL 갱신 명령이 실행된다
끝.
이상으로 "CentOS 무료SSL Let’s encrypt 설치 및 자동 갱신 방법"을 마칩니다.
* * *
[팁]
아래와 같이 에러가 나면,
1. 외부에서 인증서를 발급하고자 하는 도메인의 80포트로 접근이 안되거나.
2. 도메인 아래 .well-known 경로로 접근이 안되거나
3. certbot-auto 명령의 옵션 --webroot에 경로가 NginX의 'location /.well-known' 블록과 일치하지 않을때 발생한다.
Obtaining a new certificate Performing the following challenges: http-01 challenge for 도메인.co.kr http-01 challenge for www.도메인.co.kr http-01 challenge for m.도메인.co.kr Using the webroot path /usr/local/도메인 for all unmatched domains. Waiting for verification... Cleaning up challenges Failed authorization procedure. www.도메인.co.kr (http-01): urn:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from http://www.도메인.co.kr/.well-known/acme-challenge/hORhM9rrWp-bkk8QAxYhIy******: " <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta ", m.도메인.co.kr (http-01): urn:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from http://m.도메인.co.kr/.well-known/acme-challenge/KFOfwIgAH6qVewPCqib*********5faRVCAXPwzHo: " <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta ", 도메인.co.kr (http-01): urn:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from http://도메인.co.kr/.well-known/acme-challenge/wM4uelz2kr5XdT7**********r3-qknU6R4: " <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta " IMPORTANT NOTES: - The following errors were reported by the server: Domain: www.도메인.co.kr Type: unauthorized Detail: Invalid response from http://www.도메인.co.kr/.well-known/acme-challenge/hORh*******W7TDLxuA: " <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta " Domain: m.도메인.co.kr Type: unauthorized Detail: Invalid response from http://m.도메인.co.kr/.well-known/acme-challenge/KFOfwIgAH6q******XPwzHo: " <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta " Domain: 도메인.co.kr Type: unauthorized Detail: Invalid response from http://도메인.co.kr/.well-known/acme-challenge/wM4uelz2kr5*******3-qknU6R4: " <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta " To fix these errors, please make sure that your domain name was entered correctly and the DNS A/AAAA record(s) for that domain contain(s) the right IP address. - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal.
'IT > OS·Server' 카테고리의 다른 글
SimpleDnsCrypt로 DNS 암호화 (DNS-over-TLS) 하기 (0) | 2018.05.06 |
---|---|
구글 클라우드 DNS 설정 (14) | 2017.12.19 |
애플, 맥용 신형 운영체제 '하이 시에라' 설치 (0) | 2017.09.30 |
CentOS 리눅스 서버 시간 설정 및 타임존 변경 (0) | 2017.09.01 |
리눅스 CentOS - nginx 기동 오류 (0) | 2017.08.20 |