-
명령어로 Nginx SSL 인증서 발급하기(자동 갱신/Letsencrypt)우아한 테크코스/이것저것 2020. 8. 10. 19:53반응형
Certbot이 자동으로 인증서를 갱신해줘 편리한 방식
Certbot 설치
$ sudo apt-get update $ sudo apt-get install -y software-properties-common $ sudo add-apt-repository universe $ sudo add-apt-repository ppa:certbot/certbot $ sudo apt-get update $ sudo apt-get install certbot python-certbot-nginx # 만약 다음과 같은 에러가 난다면1 E: The repository 'http://ppa.launchpad.net/certbot/certbot/ubuntu focal Release' does not have a Release file. $ sudo apt-add-repository -r ppa:certbot/certbot # 만약 다음과 같은 에러가 난다면2 However the following packages replace it: python3-certbot-nginx E: Package 'python-certbot-nginx' has no installation candidate $ sudo apt-get install certbot python3-certbot-nginx
Certbot 동작 방식 선택
// nginx을 기동중일 경우, https를 지원하도록 conf까지 바꿔줌 - 추천 $ sudo certbot --nginx // 다른 작업은 하지 않고(conf 수정 등) 인증서만 발급 - 수동으로 conf 바꿔줘야함 $ sudo certbot certonly --nginx /* email - 이메일 적기 * 약관 동의 - y * 이메일 발송 동의 - y or n * Which names would you like to activate HTTPS for? - 해당 도메인의 번호 선택 * - 혹은 직접 도메인을 입력하라고 나타나면 직접 입력(예 - domain.com) */
자동 갱신 확인
// 수동 갱신 - Processing /etc/letsencrypt/renewal/도메인.conf 라고 나타남 $ sudo certbot renew --dry-run $ cat /etc/letsencrypt/renewal/도메인.conf # renew_before_expiry = 30 days version = 0.31.0 archive_dir = /etc/letsencrypt/archive/도메인 cert = /etc/letsencrypt/live/도메인/cert.pem privkey = /etc/letsencrypt/live/도메인/privkey.pem chain = /etc/letsencrypt/live/도메인/chain.pem fullchain = /etc/letsencrypt/live/도메인/fullchain.pem # Options used in the renewal process [renewalparams] account = 비밀 authenticator = nginx installer = nginx server = https://acme-v02.api.letsencrypt.org/directory /* 수동으로 nginx 설정을 변경했다면 아래와 같이 ssl 설정을 꼭 해줘야 함 ssl_certificate /etc/letsencrypt/live/도메인/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/도메인/privkey.pem; */ // 자동 갱신의 경우 아래와 같이 확인 가능 $ cat /etc/cron.d/certbot (생략) 0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew
확인
반응형'우아한 테크코스 > 이것저것' 카테고리의 다른 글
Ubuntu에 MySql 설치 & Database 및 계정 생성 (0) 2020.08.11 Site에서 무료 SSL 발급하기 (0) 2020.08.10 Jenkins & Github 연동 (0) 2020.08.02 Docker를 이용한 Jenkins Gradle, JDK 설정 (0) 2020.07.31 Ubuntu - 재부팅시 Docker를 이용한 Jenkins 자동으로 ON (0) 2020.07.31