-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-letsencrypt.sh
More file actions
executable file
·64 lines (48 loc) · 1.79 KB
/
Copy pathinit-letsencrypt.sh
File metadata and controls
executable file
·64 lines (48 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# Let's Encrypt 초기 인증서 발급 스크립트
# 최초 1회만 실행하면 됩니다.
# 사용법: sudo ./init-letsencrypt.sh
DOMAIN="taja.myvnc.com"
if [ -f .env ]; then
EMAIL=$(grep -s '^CERTBOT_EMAIL=' .env | cut -d'=' -f2)
fi
# 기존 컨테이너 정리
echo ">>> 기존 nginx 컨테이너 정리..."
docker compose down nginx 2>/dev/null || true
# 1. certbot 인증용 디렉토리 생성
echo ">>> 디렉토리 생성..."
mkdir -p ./certbot/www
mkdir -p ./certbot/conf/live/$DOMAIN
# 2. 임시 자체서명 인증서 생성 (nginx가 시작할 수 있도록)
echo ">>> 임시 인증서 생성..."
openssl req -x509 -nodes -newkey rsa:2048 -days 1 \
-keyout ./certbot/conf/live/$DOMAIN/privkey.pem \
-out ./certbot/conf/live/$DOMAIN/fullchain.pem \
-subj "/CN=$DOMAIN" 2>/dev/null
echo ">>> 임시 인증서 생성 완료"
# 3. nginx 시작
echo ">>> nginx 시작..."
docker compose up -d nginx
echo ">>> 10초 대기..."
sleep 10
# 4. 임시 인증서 삭제
echo ">>> 임시 인증서 삭제..."
rm -rf ./certbot/conf/live/$DOMAIN
rm -rf ./certbot/conf/archive/$DOMAIN
rm -rf ./certbot/conf/renewal/$DOMAIN.conf
# 5. Let's Encrypt 인증서 발급
echo ">>> Let's Encrypt 인증서 발급 중..."
if [ -z "$EMAIL" ]; then
EMAIL_ARG="--register-unsafely-without-email"
else
EMAIL_ARG="--email $EMAIL"
fi
docker compose run --rm --entrypoint "certbot" certbot certonly --webroot --webroot-path=/var/www/certbot $EMAIL_ARG --agree-tos --no-eff-email --force-renewal -d $DOMAIN
if [ $? -ne 0 ]; then
echo ">>> 인증서 발급 실패! 80 포트 접근 및 DNS 설정을 확인하세요."
exit 1
fi
# 6. nginx 재시작 (실제 인증서 적용)
echo ">>> nginx 재시작..."
docker compose restart nginx
echo ">>> HTTPS 설정 완료! https://$DOMAIN 으로 접속해보세요."