#!/usr/bin/env sh

set -eo pipefail

if [ -z "${NGINX_DOMAIN_APPEND}" ]; then
    echo "Environment variable NGINX_DOMAIN_APPEND not defined."
    exit 1
fi

set -u

envsubst '${NGINX_DOMAIN_APPEND}' < nginx.conf.tpl > /etc/nginx/nginx.conf

echo "Starting nginx with NGINX_DOMAIN_APPEND=${NGINX_DOMAIN_APPEND}"
exec nginx -g 'daemon off;'
