From 339c1a4837bbf9f61848b80257e766391f6a84a1 Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Fri, 22 Sep 2023 14:34:07 -0700 Subject: [PATCH] Test the nginx configuration before reloading. This avoids crashing the container if there are configuration errors. --- src/scripts/run_certbot.sh | 6 ++++++ src/scripts/run_local_ca.sh | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/scripts/run_certbot.sh b/src/scripts/run_certbot.sh index bb10b8c..5f6241a 100644 --- a/src/scripts/run_certbot.sh +++ b/src/scripts/run_certbot.sh @@ -169,5 +169,11 @@ done # did indeed get certificates for. auto_enable_configs +# Make sure the Nginx configs are valid. +if ! nginx -t; then + error "Nginx configuration is invalid, skipped reloading. Check the logs for details." + exit 0 +fi + # Finally, tell Nginx to reload the configs. nginx -s reload diff --git a/src/scripts/run_local_ca.sh b/src/scripts/run_local_ca.sh index 55bd0ef..d903454 100644 --- a/src/scripts/run_local_ca.sh +++ b/src/scripts/run_local_ca.sh @@ -247,5 +247,11 @@ done # did indeed succeed with. auto_enable_configs +# Make sure the Nginx configs are valid. +if ! nginx -t; then + error "Nginx configuration is invalid, skipped reloading. Check the logs for details." + exit 0 +fi + # Finally, tell Nginx to reload the configs. nginx -s reload