-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-letsencrypt.sh
More file actions
executable file
·61 lines (50 loc) · 1.96 KB
/
init-letsencrypt.sh
File metadata and controls
executable file
·61 lines (50 loc) · 1.96 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
#!/bin/bash
# Erstes SSL-Zertifikat von Let's Encrypt holen.
# Einmalig auf dem Server ausführen, BEVOR docker-compose up -d.
#
# Voraussetzungen:
# - Domain bereits auf Server-IP gezeigt (DNS propagiert)
# - DOMAIN und EMAIL unten angepasst
# - Docker und docker-compose installiert
set -e
DOMAIN="DEINE-DOMAIN.de"
EMAIL="DEINE-EMAIL@beispiel.de"
STAGING=0 # Zum Testen auf 1 setzen (kein Rate-Limit), für Produktion: 0
# Pfade
CERT_PATH="/etc/letsencrypt/live/$DOMAIN"
DATA_PATH="./certbot_data" # temporär, wird in Docker-Volume geschrieben
echo "### Erstelle temporäres Dummy-Zertifikat für $DOMAIN ..."
docker compose run --rm --entrypoint "\
sh -c 'mkdir -p /etc/letsencrypt/live/$DOMAIN && \
openssl req -x509 -nodes -newkey rsa:4096 -days 1 \
-keyout /etc/letsencrypt/live/$DOMAIN/privkey.pem \
-out /etc/letsencrypt/live/$DOMAIN/fullchain.pem \
-subj /CN=localhost'" certbot
echo "### Lade TLS-Parameter (DH params + options) ..."
docker compose run --rm --entrypoint "\
sh -c 'curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf \
> /etc/letsencrypt/options-ssl-nginx.conf && \
openssl dhparam -out /etc/letsencrypt/ssl-dhparams.pem 2048'" certbot
echo "### Starte nginx mit Dummy-Zertifikat ..."
docker compose up -d nginx
echo "### Warte kurz auf nginx ..."
sleep 3
echo "### Hole echtes Let's Encrypt Zertifikat ..."
STAGING_ARG=""
if [ "$STAGING" = "1" ]; then
STAGING_ARG="--staging"
fi
docker compose run --rm --entrypoint "\
certbot certonly --webroot \
--webroot-path=/var/www/certbot \
$STAGING_ARG \
--email $EMAIL \
--agree-tos \
--no-eff-email \
-d $DOMAIN \
-d www.$DOMAIN" certbot
echo "### Lade nginx mit echtem Zertifikat neu ..."
docker compose exec nginx nginx -s reload
echo ""
echo "Fertig! Die Website läuft jetzt unter https://$DOMAIN"
echo "Alle 12h prüft der certbot-Container automatisch auf Erneuerung."