nginx-envsubst/start-nginx.sh
2021-02-05 15:58:46 +01:00

35 lines
871 B
Bash
Executable file

#!/usr/bin/env sh
set -x
enable_server() {
for name in "$@"; do
src_dir="/etc/nginx/sites-available"
dst_dir="/etc/nginx/sites-enabled"
mkdir -p "$dst_dir"
envsubst '${DOMAIN_NAME}' < "$src_dir/$name.conf" > "$dst_dir/$name.conf"
done
}
enable_ssh_server() {
for name in "$@"; do
src_dir="/etc/nginx/ssh-available"
dst_dir="/etc/nginx/ssh-enabled"
mkdir -p "$dst_dir"
envsubst '${DOMAIN_NAME}' < "$src_dir/$name.conf" > "$dst_dir/$name.conf"
done
}
sub_env_vars="$(cat /environment_variables.txt)"
echo "Enabling servers"
(
cd "/etc/nginx/sites-available" || exit $?
mkdir "../sites-enabled" || exit $?
for f in *.conf; do
envsubst "$sub_env_vars" < "$f" > "../sites-enabled/$f"
done
)
echo "Starting nginx"
exec nginx -g 'daemon off;' -c /etc/nginx/nginx.conf