fix: nginx config

This commit is contained in:
u00lipp committed 2025-10-30 11:03:09 +01:00
1 parent 13d912738d
commit b7ff7602f6
1 file changed
+20 -11
+20 -11
View File
@@ -1,29 +1,38 @@
#!/bin/sh
set -e
SERVER_NAME="${SERVER_NAME:-$(hostname -f 2>/dev/null || hostname)}"
export SERVER_NAME
# Render vhost ONLY into http.d so it's inside http{} context
if [ -f /etc/nginx/templates/default.conf.template ]; then
envsubst '$SERVER_NAME' < /etc/nginx/templates/default.conf.template > /etc/nginx/http.d/default.conf
# Ensure SERVER_NAME is set
if [ -z "$SERVER_NAME" ]; then
echo "[entrypoint] SERVER_NAME is not set. Using default value: localhost"
SERVER_NAME="localhost"
else
echo "[entrypoint] ERROR: missing /etc/nginx/templates/default.conf.template" >&2
exit 1
echo "[entrypoint] Using SERVER_NAME=$SERVER_NAME"
fi
# Add basic authentication if enabled
# Prepare BASIC_AUTH_DIRECTIVES
if [ "$ENABLE_BASIC_AUTH" = "true" ]; then
echo "[entrypoint] Enabling basic authentication..."
if [ -f /etc/nginx/htpasswd ]; then
# Use sed to append basic auth directives inside the location block
sed -i '/location \/ {/a \\t\tauth_basic "Restricted Content";\n\t\tauth_basic_user_file /etc/nginx/htpasswd;' /etc/nginx/http.d/default.conf
BASIC_AUTH_DIRECTIVES=$(cat <<EOF
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/htpasswd;
EOF
)
else
echo "[entrypoint] ERROR: htpasswd file not found at /etc/nginx/htpasswd" >&2
exit 1
fi
else
echo "[entrypoint] Basic authentication is disabled."
BASIC_AUTH_DIRECTIVES=""
fi
# Render the NGINX configuration
if [ -f /etc/nginx/templates/default.conf.template ]; then
envsubst '$SERVER_NAME,$BASIC_AUTH_DIRECTIVES' < /etc/nginx/templates/default.conf.template > /etc/nginx/http.d/default.conf
else
echo "[entrypoint] ERROR: missing /etc/nginx/templates/default.conf.template" >&2
exit 1
fi
# Test nginx configuration