From 218fc11d4bd250084e4be94623ea3875341f8d0e Mon Sep 17 00:00:00 2001 From: kings9527 <3350474162@qq.com> Date: Tue, 26 May 2026 18:33:27 +0800 Subject: [PATCH] fix: correct multi-domain certificate path handling and update nginx version - Use first domain (domains[0]) as certificate directory name instead of unquoted array expansion, which caused incorrect path resolution when multiple domains were configured - Check specific certbot live directory instead of generic data_path for existing certificate detection - Update nginx image from 1.15-alpine (2018, EOL) to 1.30-alpine (2026 stable) for security patches and HTTP/2 keep-alive improvements Fixes #139 --- docker-compose.yml | 2 +- init-letsencrypt.sh | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9615cc1f..8ad35330 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '3' services: nginx: - image: nginx:1.15-alpine + image: nginx:1.30-alpine restart: unless-stopped volumes: - ./data/nginx:/etc/nginx/conf.d diff --git a/init-letsencrypt.sh b/init-letsencrypt.sh index a3f3cb01..7f538052 100755 --- a/init-letsencrypt.sh +++ b/init-letsencrypt.sh @@ -11,8 +11,11 @@ data_path="./data/certbot" email="" # Adding a valid address is strongly recommended staging=0 # Set to 1 if you're testing your setup to avoid hitting request limits -if [ -d "$data_path" ]; then - read -p "Existing data found for $domains. Continue and replace existing certificate? (y/N) " decision +# Use the first domain as the certificate directory name +cert_dir="${domains[0]}" + +if [ -d "$data_path/conf/live/$cert_dir" ]; then + read -p "Existing data found for $cert_dir (${domains[*]}). Continue and replace existing certificate? (y/N) " decision if [ "$decision" != "Y" ] && [ "$decision" != "y" ]; then exit fi @@ -27,9 +30,9 @@ if [ ! -e "$data_path/conf/options-ssl-nginx.conf" ] || [ ! -e "$data_path/conf/ echo fi -echo "### Creating dummy certificate for $domains ..." -path="/etc/letsencrypt/live/$domains" -mkdir -p "$data_path/conf/live/$domains" +echo "### Creating dummy certificate for $cert_dir (${domains[*]}) ..." +path="/etc/letsencrypt/live/$cert_dir" +mkdir -p "$data_path/conf/live/$cert_dir" docker-compose run --rm --entrypoint "\ openssl req -x509 -nodes -newkey rsa:$rsa_key_size -days 1\ -keyout '$path/privkey.pem' \ @@ -42,15 +45,15 @@ echo "### Starting nginx ..." docker-compose up --force-recreate -d nginx echo -echo "### Deleting dummy certificate for $domains ..." +echo "### Deleting dummy certificate for $cert_dir ..." docker-compose run --rm --entrypoint "\ - rm -Rf /etc/letsencrypt/live/$domains && \ - rm -Rf /etc/letsencrypt/archive/$domains && \ - rm -Rf /etc/letsencrypt/renewal/$domains.conf" certbot + rm -Rf /etc/letsencrypt/live/$cert_dir && \ + rm -Rf /etc/letsencrypt/archive/$cert_dir && \ + rm -Rf /etc/letsencrypt/renewal/${cert_dir}.conf" certbot echo -echo "### Requesting Let's Encrypt certificate for $domains ..." +echo "### Requesting Let's Encrypt certificate for ${domains[*]} ..." #Join $domains to -d args domain_args="" for domain in "${domains[@]}"; do