Commit 1f2852cc authored by Valian's avatar Valian
Browse files

changed BACKEND variable to SITES

parent e0d27d99
......@@ -16,33 +16,33 @@ if [ ! -f "/etc/resty-auto-ssl/dhparam.pem" ]; then
fi
# if $BACKENDS is defined, we should prepare configuration files
# if $SITES is defined, we should prepare configuration files
# example usage:
#
# -e BACKENDS="db.example.com=localhost:5432;app.example.com=http://localhost:8080"
# -e SITES="db.example.com=localhost:5432;app.example.com=http://localhost:8080"
#
# it will create 2 files:
#
# 1. /etc/nginx/conf.d/db.example.com.conf using $SERVER_ENDPOINT=localhost:5432 and $SERVER_NAME=db.example.com
# 2. /etc/nginx/conf.d/app.example.com.conf using $SERVER_ENDPOINT=localhost:8080 and $SERVER_NAME=app.example.com
if [ -n "$BACKENDS" ]; then
if [ -n "$SITES" ]; then
# lets read all backends, separated by ';'
IFS=\; read -a BACKENDS_SEPARATED <<<"$BACKENDS"
IFS=\; read -a SITES_SEPARATED <<<"$SITES"
# for each backend (in form of server_name=endpoint:port) we create proper file
for NAME_EQ_ENDPOINT in "${BACKENDS_SEPARATED[@]}"; do
for NAME_EQ_ENDPOINT in "${SITES_SEPARATED[@]}"; do
RAW_SERVER_ENDPOINT=${NAME_EQ_ENDPOINT#*=}
export SERVER_NAME=${NAME_EQ_ENDPOINT%=*}
export SERVER_ENDPOINT=${RAW_SERVER_ENDPOINT#*//} # it clears url scheme, like http:// or https://
envsubst '$SERVER_NAME $SERVER_ENDPOINT' \
< ${RESTY_CONF_DIR}/server-backend.conf \
< ${RESTY_CONF_DIR}/server-proxy.conf \
> ${NGINX_CONF_DIR}/${SERVER_NAME}.conf
done
unset SERVER_NAME SERVER_ENDPOINT
# if $BACKENDS isn't defined, let's check if $NGINX_CONF_DIR is empty
# if $SITES isn't defined, let's check if $NGINX_CONF_DIR is empty
elif [ ! "$(ls -A ${NGINX_CONF_DIR})" ]; then
# if yes, just copy default server (similar to default from docker-openresty, but using https)
cp ${RESTY_CONF_DIR}/server-default.conf ${NGINX_CONF_DIR}/default.conf
......
# this configuration will be used for each server
# specified using $BACKENDS variable
# specified using $SITES variable
# more in README
server {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment