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