docker 서비스시 nginx certbot https 설정

By | 2021년 7월 19일

.well-known 작업

# my.domain.com
server {
  listen 80;
  server_name my.domain.com;

  location ~ /.well-known/acme-challenge {
      allow all;
      root /var/www/certbot;
  }
}

현재 작업폴더 기준

pwd 
/home/ubuntu/webhome

certbot 이미지를 이용해 등록

sudo docker run -it --rm --name certbot \
-v '/home/ubuntu/webhome/certbot/conf:/etc/letsencrypt' \
-v '/home/ubuntu/webhome/certbot/logs:/var/log/letsencrypt' \
-v '/home/ubuntu/webhome/certbot/data:/var/www/certbot' \
certbot/certbot certonly --webroot --webroot-path=/var/www/certbot --email 이메일 --agree-tos --no-eff-email -d my.domain.com

ssl 반영

# my.domain.com
server {
  listen 80;
  server_name my.domain.com;
  return 301 https://$server_name$request_uri;
}
server {
  listen 443 ssl;
  client_max_body_size 10M;
  server_name my.domain.com;

  #ssl_certificate /etc/nginx/ssl/archive/my.domain.com/fullchain1.pem;
  #ssl_certificate_key /etc/nginx/ssl/archive/my.domain.com/privkey1.pem;
  ssl_certificate /etc/nginx/ssl/live/my.domain.com/fullchain.pem;
  ssl_certificate_key /etc/nginx/ssl/live/my.domain.com/privkey.pem;
}

명령어 목록

# 등록
sudo docker run --rm --name certbot \
-v '/home/ubuntu/webhome/certbot/conf:/etc/letsencrypt' \
-v '/home/ubuntu/webhome/certbot/logs:/var/log/letsencrypt' \
-v '/home/ubuntu/webhome/certbot/data:/var/www/certbot' \
certbot/certbot certonly --webroot --webroot-path=/var/www/certbot --email 이메일 --agree-tos --no-eff-email -d my.domain.com

# 갱신
sudo docker run --rm --name certbot \
-v '/home/ubuntu/webhome/certbot/conf:/etc/letsencrypt' \
-v '/home/ubuntu/webhome/certbot/logs:/var/log/letsencrypt' \
-v '/home/ubuntu/webhome/certbot/data:/var/www/certbot' \
certbot/certbot renew \
--cert-name my.domain.com

# 만료일 확인
sudo docker run -it --rm --name certbot \
-v '/home/ubuntu/webhome/certbot/conf:/etc/letsencrypt' \
-v '/home/ubuntu/webhome/certbot/logs:/var/log/letsencrypt' \
-v '/home/ubuntu/webhome/certbot/data:/var/www/certbot' \
certbot/certbot certificates

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다