Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69ab1c94b1 | ||
|
|
b550cbda4a |
@@ -4,4 +4,4 @@ DDNINJA_IS_PRODUCTION=false
|
|||||||
DDNINJA_MONGO_DBNAME=fdn2_test
|
DDNINJA_MONGO_DBNAME=fdn2_test
|
||||||
DDNINJA_MONGO_LOCATION=mongo
|
DDNINJA_MONGO_LOCATION=mongo
|
||||||
|
|
||||||
DDNINJA_PUBLIC_URL=http://test.ifattidinapoli.it
|
DDNINJA_PUBLIC_URL=https://test.ifattidinapoli.it
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ DDNINJA_IS_PRODUCTION=false
|
|||||||
DDNINJA_MONGO_DBNAME=fdn2_test
|
DDNINJA_MONGO_DBNAME=fdn2_test
|
||||||
DDNINJA_MONGO_LOCATION=mongo
|
DDNINJA_MONGO_LOCATION=mongo
|
||||||
|
|
||||||
DDNINJA_PUBLIC_URL=http://test.ifattidinapoli.it
|
DDNINJA_PUBLIC_URL=https://test.ifattidinapoli.it
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ Il primo dominio e' il primario e da' il nome alla cartella
|
|||||||
## Primo setup
|
## Primo setup
|
||||||
|
|
||||||
Prerequisiti:
|
Prerequisiti:
|
||||||
|
- Docker con il plugin Compose v2 (comando `docker compose`, non `docker-compose`).
|
||||||
- La rete docker esterna `nginx-network` deve esistere (`docker network create nginx-network`).
|
- La rete docker esterna `nginx-network` deve esistere (`docker network create nginx-network`).
|
||||||
- Le porte 80 e 443 dell'host devono essere pubblicamente raggiungibili per
|
- Le porte 80 e 443 dell'host devono essere pubblicamente raggiungibili per
|
||||||
tutti i domini (la validazione HTTP-01 passa dalla porta 80).
|
tutti i domini (la validazione HTTP-01 passa dalla porta 80).
|
||||||
|
|||||||
@@ -8,11 +8,16 @@
|
|||||||
# cartella /etc/letsencrypt/live/<primario>/ referenziata in nginx.conf.
|
# cartella /etc/letsencrypt/live/<primario>/ referenziata in nginx.conf.
|
||||||
#
|
#
|
||||||
# Lanciarlo una volta sola, al primo setup. Per i rinnovi usare renew.sh.
|
# Lanciarlo una volta sola, al primo setup. Per i rinnovi usare renew.sh.
|
||||||
|
#
|
||||||
|
# NB: usa il plugin "docker compose" (v2). Con questo plugin --entrypoint accetta
|
||||||
|
# solo un eseguibile: i comandi con piu' token o con && vanno wrappati in
|
||||||
|
# `--entrypoint sh <service> -c "..."`, altrimenti gli argomenti oltre il primo
|
||||||
|
# vengono scartati silenziosamente.
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
if ! [ -x "$(command -v docker-compose)" ]; then
|
if ! docker compose version >/dev/null 2>&1; then
|
||||||
echo 'Error: docker-compose is not installed.' >&2
|
echo 'Error: "docker compose" (plugin v2) is not available.' >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -35,9 +40,9 @@ email="riccardo.didato@gmail.com"
|
|||||||
staging=0
|
staging=0
|
||||||
|
|
||||||
# Costruisce la sequenza di argomenti -d per certbot
|
# Costruisce la sequenza di argomenti -d per certbot
|
||||||
domain_args=""
|
domain_args=()
|
||||||
for domain in "${domains[@]}"; do
|
for domain in "${domains[@]}"; do
|
||||||
domain_args="$domain_args -d $domain"
|
domain_args+=(-d "$domain")
|
||||||
done
|
done
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@@ -62,45 +67,48 @@ else
|
|||||||
echo "### Creating dummy certificate for $primary_domain ..."
|
echo "### Creating dummy certificate for $primary_domain ..."
|
||||||
path="/etc/letsencrypt/live/$primary_domain"
|
path="/etc/letsencrypt/live/$primary_domain"
|
||||||
mkdir -p "$data_path/conf/live/$primary_domain"
|
mkdir -p "$data_path/conf/live/$primary_domain"
|
||||||
docker-compose run --rm --entrypoint "\
|
docker compose run --rm --entrypoint sh certbot -c "\
|
||||||
openssl req -x509 -nodes -newkey rsa:$rsa_key_size -days 1 \
|
openssl req -x509 -nodes -newkey rsa:$rsa_key_size -days 1 \
|
||||||
-keyout '$path/privkey.pem' \
|
-keyout '$path/privkey.pem' \
|
||||||
-out '$path/fullchain.pem' \
|
-out '$path/fullchain.pem' \
|
||||||
-subj '/CN=localhost'" certbot
|
-subj '/CN=localhost'"
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "### Starting nginx ..."
|
echo "### Starting nginx ..."
|
||||||
docker-compose up --force-recreate -d nginx
|
docker compose up --force-recreate -d nginx
|
||||||
echo
|
echo
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# FASE 2: richiesta del certificato REALE
|
# FASE 2: richiesta del certificato REALE
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
echo "### Deleting dummy certificate ..."
|
echo "### Deleting dummy certificate ..."
|
||||||
docker-compose run --rm --entrypoint "\
|
docker compose run --rm --entrypoint sh certbot -c "\
|
||||||
rm -Rf /etc/letsencrypt/live/$primary_domain && \
|
rm -Rf /etc/letsencrypt/live/$primary_domain && \
|
||||||
rm -Rf /etc/letsencrypt/archive/$primary_domain && \
|
rm -Rf /etc/letsencrypt/archive/$primary_domain && \
|
||||||
rm -Rf /etc/letsencrypt/renewal/$primary_domain.conf" certbot
|
rm -Rf /etc/letsencrypt/renewal/$primary_domain.conf"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
email_arg=()
|
||||||
case "$email" in
|
case "$email" in
|
||||||
"") email_arg="--register-unsafely-without-email" ;;
|
"") email_arg=(--register-unsafely-without-email) ;;
|
||||||
*) email_arg="--email $email" ;;
|
*) email_arg=(--email "$email") ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ "$staging" != "0" ]; then staging_arg="--staging"; fi
|
staging_arg=()
|
||||||
|
if [ "$staging" != "0" ]; then staging_arg=(--staging); fi
|
||||||
|
|
||||||
echo "### Requesting Let's Encrypt certificate for: ${domains[*]} ..."
|
echo "### Requesting Let's Encrypt certificate for: ${domains[*]} ..."
|
||||||
docker-compose run --rm --entrypoint "\
|
# L'immagine certbot/certbot ha gia' "certbot" come entrypoint: passiamo solo
|
||||||
certbot certonly --webroot -w /var/www/certbot \
|
# gli argomenti come comando (niente --entrypoint da sovrascrivere).
|
||||||
$staging_arg \
|
docker compose run --rm certbot certonly --webroot -w /var/www/certbot \
|
||||||
$email_arg \
|
"${staging_arg[@]}" \
|
||||||
$domain_args \
|
"${email_arg[@]}" \
|
||||||
--rsa-key-size $rsa_key_size \
|
"${domain_args[@]}" \
|
||||||
|
--rsa-key-size "$rsa_key_size" \
|
||||||
--agree-tos \
|
--agree-tos \
|
||||||
--force-renewal" certbot
|
--force-renewal
|
||||||
echo
|
echo
|
||||||
|
|
||||||
echo "### Reloading nginx ..."
|
echo "### Reloading nginx ..."
|
||||||
docker-compose exec nginx nginx -s reload
|
docker compose exec nginx nginx -s reload
|
||||||
|
|||||||
+5
-2
@@ -2,6 +2,9 @@
|
|||||||
# Rinnova il certificato SSL e ricarica nginx.
|
# Rinnova il certificato SSL e ricarica nginx.
|
||||||
# Schedulato via crontab sull'host (vedi README). certbot renew rinnova solo se
|
# Schedulato via crontab sull'host (vedi README). certbot renew rinnova solo se
|
||||||
# il certificato scade entro 30 giorni, quindi e' sicuro lanciarlo ogni giorno.
|
# il certificato scade entro 30 giorni, quindi e' sicuro lanciarlo ogni giorno.
|
||||||
|
#
|
||||||
|
# NB: usa il plugin "docker compose" (v2). L'immagine certbot/certbot ha gia'
|
||||||
|
# "certbot" come entrypoint, quindi passiamo "renew" come comando.
|
||||||
|
|
||||||
/usr/local/bin/docker-compose run --rm --entrypoint "certbot renew" certbot
|
docker compose run --rm certbot renew
|
||||||
/usr/local/bin/docker-compose exec -T nginx nginx -s reload
|
docker compose exec -T nginx nginx -s reload
|
||||||
|
|||||||
Reference in New Issue
Block a user