-
-
Save valmayaki/be6bea9b0e9658fecf999a2042c1648a to your computer and use it in GitHub Desktop.
An "envsubst" alternative for replacing env variables in NGinX site configurations (for using it with Docker)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# NOTE: Brackets are not supported and '$' in values will break the script. | |
mkdir /etc/nginx/sites-enabled 2> /dev/null | |
for file in /etc/nginx/sites-available/*.conf | |
do | |
TPL=$(cat $file) | |
for row in $(env) | |
do | |
IFS="=" | |
read key val <<< "$row" | |
if [[ $val == tcp://* ]] | |
then | |
valhttp=$(echo -n $val | sed 's#^tcp://#http://#') | |
TPL=$(echo -n $TPL | sed "s\$\\\$$key\_HTTP\$$valhttp\$") | |
fi | |
TPL=$(echo -n $TPL | sed "s\$\\\$$key\$$val\$") | |
done | |
echo -n $TPL > "/etc/nginx/sites-enabled/$(basename $file)" | |
done | |
nginx -g "daemon off;" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment