-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.sh
41 lines (34 loc) · 1.36 KB
/
init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
## Init vars
CONF_TMPL=/etc/nginx/nginx.conf.txt
PROXY_CONF_FILE=/etc/nginx/conf.d/site.conf
EMAIL_ARG="--register-unsafely-without-email"
ADD_SERVER_NAME=""
ADD_PROXY_API=""
# do not forget to escape proxy vars (else envsubst removes them)
read -r -d '' ADD_PROXY_API_CONF << EOM
location ^~ /api {
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_pass ${PROXY_API_ENDPOINT};
proxy_read_timeout 300;
proxy_send_timeout 300;
client_max_body_size 200M;
}
EOM
## Create Nginx configuration ##
if [ -f "$PROXY_CONF_FILE" ]; then
echo "Nginx configuration already exists: $PROXY_CONF_FILE "
else
echo "Creating Nginx configuration: $PROXY_CONF_FILE"
[ ! -z ${SERVER_NAME+x} ] && export ADD_SERVER_NAME="server_name ${SERVER_NAME}";
[ ! -z ${PROXY_API_ENDPOINT+x} ] && export ADD_PROXY_API=$(echo "$ADD_PROXY_API_CONF");
envsubst '${ADD_SERVER_NAME} ${ADD_PROXY_API}' < $CONF_TMPL > $PROXY_CONF_FILE
rm /etc/nginx/conf.d/default.conf || echo "File '/etc/nginx/conf.d/default.conf' already deleted. OK"
nginx -t
cat $PROXY_CONF_FILE
nginx -s reload
fi
nginx -g "daemon off;"