Skip to content

Commit 7df8926

Browse files
ImTotemclaude
andcommitted
fix(infra): init-ssl installs HTTP-only config before requesting certs
Solves chicken-and-egg: HTTPS config needs certs, but certs need ACME challenge served on HTTP. Now installs temporary HTTP-only config first, gets certs, then installs full HTTPS config. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6d97975 commit 7df8926

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

infra/scripts/init-ssl.sh

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,38 @@ if [ -f .env ]; then
55
set -a; source .env; set +a
66
fi
77

8+
NGINX_AVAILABLE="/etc/nginx/sites-available/bcsd-api.conf"
9+
NGINX_ENABLED="/etc/nginx/sites-enabled/bcsd-api.conf"
810
DOMAIN="${DOMAIN:?Set DOMAIN in .env}"
911
N8N_DOMAIN="${N8N_DOMAIN}"
1012
FRONTEND_DOMAIN="${FRONTEND_DOMAIN}"
1113

14+
DOMAINS="$DOMAIN"
15+
[ -n "$N8N_DOMAIN" ] && DOMAINS="$DOMAINS $N8N_DOMAIN"
16+
[ -n "$FRONTEND_DOMAIN" ] && DOMAINS="$DOMAINS $FRONTEND_DOMAIN internal.bcsdlab.com"
17+
1218
echo "=== Initial SSL Certificate Setup ==="
1319

14-
echo "1. Requesting certificate for $DOMAIN..."
20+
echo "1. Installing HTTP-only nginx config for ACME challenge..."
21+
sudo mkdir -p /var/www/certbot
22+
cat <<EOF | sudo tee "$NGINX_AVAILABLE" > /dev/null
23+
server {
24+
listen 80;
25+
server_name $DOMAINS;
26+
27+
location /.well-known/acme-challenge/ {
28+
root /var/www/certbot;
29+
}
30+
31+
location / {
32+
return 444;
33+
}
34+
}
35+
EOF
36+
sudo ln -sf "$NGINX_AVAILABLE" "$NGINX_ENABLED"
37+
sudo nginx -t && sudo nginx -s reload
38+
39+
echo "2. Requesting certificate for $DOMAIN..."
1540
sudo certbot certonly \
1641
--webroot \
1742
-w /var/www/certbot \
@@ -20,7 +45,7 @@ sudo certbot certonly \
2045
--agree-tos
2146

2247
if [ -n "$N8N_DOMAIN" ]; then
23-
echo "2. Requesting certificate for $N8N_DOMAIN..."
48+
echo "3. Requesting certificate for $N8N_DOMAIN..."
2449
sudo certbot certonly \
2550
--webroot \
2651
-w /var/www/certbot \
@@ -30,7 +55,7 @@ if [ -n "$N8N_DOMAIN" ]; then
3055
fi
3156

3257
if [ -n "$FRONTEND_DOMAIN" ]; then
33-
echo "3. Requesting certificate for $FRONTEND_DOMAIN (+ internal.bcsdlab.com)..."
58+
echo "4. Requesting certificate for $FRONTEND_DOMAIN (+ internal.bcsdlab.com)..."
3459
sudo certbot certonly \
3560
--webroot \
3661
-w /var/www/certbot \
@@ -40,7 +65,8 @@ if [ -n "$FRONTEND_DOMAIN" ]; then
4065
--agree-tos
4166
fi
4267

43-
echo "4. Reloading nginx..."
68+
echo "5. Installing full nginx config with HTTPS..."
69+
sudo cp infra/nginx/bcsd-api.conf "$NGINX_AVAILABLE"
4470
sudo nginx -t && sudo nginx -s reload
4571

4672
echo "=== SSL setup complete ==="

0 commit comments

Comments
 (0)