-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinit-letsencrypt.sh
More file actions
executable file
·89 lines (77 loc) · 2.76 KB
/
init-letsencrypt.sh
File metadata and controls
executable file
·89 lines (77 loc) · 2.76 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
# 도메인 설정
domains=(globalnomad.site www.globalnomad.site)
rsa_key_size=4096
data_path="./certbot"
email="cksgh5477@gmail.com"
# staging=0 # 실제 인증서 발급 (모든 테스트 완료 후 마지막에만 사용)
staging=1 # 테스트용 인증서 발급 (Rate Limit 회피를 위해 사용)
# 기존 데이터가 있는지 확인
if [ -d "$data_path" ]; then
read -p "기존 인증서 데이터가 있습니다. 삭제하고 계속하시겠습니까? (y/N) " decision
if [ "$decision" != "Y" ] && [ "$decision" != "y" ]; then
exit
fi
fi
# 필요한 디렉토리 생성
if [ ! -d "$data_path/conf" ]; then
mkdir -p "$data_path/conf"
fi
if [ ! -d "$data_path/www" ]; then
mkdir -p "$data_path/www"
fi
# TLS 파라미터 다운로드
if [ ! -e "$data_path/conf/options-ssl-nginx.conf" ] || [ ! -e "$data_path/conf/ssl-dhparams.pem" ]; then
echo "### SSL 파라미터 다운로드 중..."
curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf > "$data_path/conf/options-ssl-nginx.conf"
curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot/certbot/ssl-dhparams.pem > "$data_path/conf/ssl-dhparams.pem"
echo
fi
# 임시 인증서 생성 (nginx 시작을 위해)
echo "### 임시 자체 서명 인증서 생성 중..."
path="/etc/letsencrypt/live/globalnomad.site"
mkdir -p "$data_path/conf/live/globalnomad.site"
docker run --rm -v "$PWD/$data_path/conf:/etc/letsencrypt" \
--entrypoint "/bin/sh" certbot/certbot \
-c "openssl req -x509 -nodes -newkey rsa:1024 -days 1 \
-keyout '$path/privkey.pem' \
-out '$path/fullchain.pem' \
-subj '/CN=localhost'"
echo
# nginx 시작
echo "### nginx 시작 중..."
docker-compose up -d nginx
echo
# 임시 인증서 삭제
echo "### 임시 인증서 삭제 중..."
docker run --rm -v "$PWD/$data_path/conf:/etc/letsencrypt" \
--entrypoint "/bin/sh" certbot/certbot \
-c "rm -rf /etc/letsencrypt/live/globalnomad.site && \
rm -rf /etc/letsencrypt/archive/globalnomad.site && \
rm -rf /etc/letsencrypt/renewal/globalnomad.site.conf"
echo
# Let's Encrypt 인증서 요청
echo "### Let's Encrypt 인증서 요청 중..."
domain_args=""
for domain in "${domains[@]}"; do
domain_args="$domain_args -d $domain"
done
# 스테이징 환경 선택
case "$staging" in
1) staging_arg="--staging" ;;
*) staging_arg="" ;;
esac
docker run --rm \
-v "$PWD/$data_path/conf:/etc/letsencrypt" \
-v "$PWD/$data_path/www:/var/www/certbot" \
certbot/certbot certonly --webroot -w /var/www/certbot \
$staging_arg \
--email $email \
--agree-tos \
--no-eff-email \
--force-renewal \
$domain_args
echo
# nginx 재시작
echo "### nginx 재시작 중..."
docker-compose restart nginx