서버 환경
OS: CentOS7 Apache 2.4.6
#yum install epel-release
# yum install python-certbot-apache
인증서 신규추가
# certbot --apache -d example.co.kr -d www.example.co.kr #서브도메인 있다면 이후에 계속 추가
인증서 갱신
certbot renew
자동 인증서 업데이트
# crontab -e
//30일마다 새벽 4시 0분에 명령어가 실행됩니다.
0 4 */30 * * certbot renew
이미 등록된 도메인에 서브도메인 추가하여 인증서 갱신
certbot --cert-name aaa.com -d aaa.com -d www.aaa.com -d ko.aaa.com
이미 등록된 도메인에서 서브도메인 하나 삭제(ko.aaa.com삭제할 때)
certbot --cert-name aaa.com -d aaa.com -d www.aaa.com
도메인 인증서 삭제(서브도메인 포함)
certbot delete
————————————————————--
서버 환경
OS: Ubuntu 16.04 Nginx 1.11.4
인증서 설치
$ cd /root # /root 디렉토리로 이동해 작업 시작
$ apt-get update # 최신 업데이트가 있는 지 학인
$ apt-get install git # git 설치
$ git clone https://github.com/certbot/certbot # certbot 설치
$ cd certbot # /certbot 디렉토리로 이동해 작업 시작
$ service nginx stop # 80포트를 사용하지 않토록 nginx를 중단시킴
$ ./certbot-auto certonly # 인증 절차 진행, 조금 시간이 걸립니다.
인증 절차 상세- 연락받아볼 메일 적기, standalone 선택, 도메인을 전부 기록. www도 별도로 기록. 컴마로 구분.$ service nginx start # 작업이 끝나면 다시 nginx를 가동시킴
$ cd /etc/nginx/sites-available 에 다음파일생성
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name yourdomain.com;
root /home/ubuntu/yourdomain;
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";
add_header X-Frame-Options DENY;
ssl on;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
#OCSP Stapling(인증서가 유효하다는 증명을 미리 받아두어서 사이트에 처음 방문할 때 접속 속도를 높여주는 방법dla)
ssl_dhparam /etc/nginx/ssl/yourdomain.com.pem;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
resolver 8.8.8.8 8.8.4.4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
ssl_prefer_server_ciphers on;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:10m;
access_log /var/log/nginx/yourdomain.com.access.log;
error_log /var/log/nginx/yourdomain.com.error.log warn;
location / {
try_files $uri $uri/ /index.php?$args;
index index.php index.html index.htm;
}
# Block dot file (.htaccess .htpasswd .svn .git .env and so on.)
location ~ /. {
deny all;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* /(?:uploads|files|data)/.*.php$ {
deny all;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~* ^.+.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off;
log_not_found off;
expires max;
}
location ~ [^/].php(/|$) {
fastcgi_split_path_info ^(.+?.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# pagespeed on;
# pagespeed FileCachePath /var/ngx_pagespeed_cache;
# pagespeed RewriteLevel CoreFilters;
# pagespeed EnableFilters defer_javascript;
# Ensure requests for pagespeed optimized resources go to the pagespeed handler
# and no extraneous headers get set.
# location ~ ".pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+" {
# add_header "" "";
# }
# location ~ "^/pagespeed_static/" { }
# location ~ "^/ngx_pagespeed_beacon$" { }
}
DH Param 생성, 적용 - 암호화 성능을 향상
$ mkdir /etc/nginx/ssl
$ cd /etc/nginx/ssl
$ openssl dhparam -out dhparams.pem 4096 # 시간이 많이 소요.
$ openssl rand 48 > session_ticket.key # 세션 티켓키도 생성. 이는 시간이 거의 걸리지 않는다.
인증서 상태보기
$ certbot certificates
인증서 수동갱신
$ certbot renew
crontab에 인증서 갱신 명령 등록하기
0 4 1 */3 * root /root/certbot/certbot renew >> /var/log/letsencrypt/le-renew.log
※ cron을 3개월에 한번씩 새벽 4시에 갱신을 확인하라는 명령
crontab에 인증서 갱신 명령 등록하기 - sudo일때
0 4 1 */3 * root /root/certbot/certbot renew --pre-hook “sudo service nginx stop” --post-hook “sudo service nginx start”
리뉴얼시에 nginx 껐다켜기
$ vim /etc/letsencrypt/renewal/ example.co.kr.conf
[renewalparams]
pre_hook = service nginx stop
post_hook = service nginx start
추가
인증서에 도메인 추가
# service nginx stop
# certbot certonly
인증 절차 상세 - standalone 선택, 도메인을 기록. www도 별도로 기록. 컴마로 구분
# service nginx start
# certbot certificates
인증서에 서브도메인 추가
# service nginx stop
# certbot certonly
인증 절차 상세 - standalone 선택, 메인도메인을 포함하여 전부 기록. www도 별도로 기록. 컴마로 구분 - 추가로 하는 거기 때문에 Expand 선택
# service nginx start
# certbot certificates
인증서 삭제
certbot delete --cert-name example.co.kr
서버 환경
OS: Rocky8 Apache 2.4.37
1. 패키지 다운로드
# yum -y install epel-release mod_ssl
# yum -y install certbot python3-certbot-apache
2. 발급
# certbot --apache -d 도메인 -d www.도메인
3. 자동 갱신 설정
발급된 인증서 유효기간은 3개월이며, 만료 1개월 전부터 갱신이 가능합니다.
자동으로 발급받아질 수 있게 crontab 에 등록해 줍니다. (1달에 한번씩 새벽 4시에 갱신)
# crontab -e
0 4 */30 * * root /usr/sbin/certbot renew
# service crond restart