-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.bash
More file actions
executable file
·85 lines (64 loc) · 2.07 KB
/
run.bash
File metadata and controls
executable file
·85 lines (64 loc) · 2.07 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
if [ -z "${SKIP_CONF_GEN}" ]; then
if [ -z "${SERVICE_HOST}" ]; then
echo "Missing SERVICE_HOST"
exit 0
fi
if [ -z "${SERVICE_PORT}" ]; then
SERVICE_PORT=80
fi
if [ -z "${NGINX_CLIENT_MAX_BODY_SIZE}" ]; then
NGINX_CLIENT_MAX_BODY_SIZE="100M"
fi
if [ -z "${NGINX_CLIENT_BODY_TIMEOUT}" ]; then
NGINX_CLIENT_BODY_TIMEOUT="60s"
fi
if [ -z "${PROXY_AUTH_DISABLE}" ]; then
NGINX_PASSWORD_FILE=/etc/nginx/service.pwd
if [ -z "${NGINX_PASSWORD_FILE}" ]; then
exit 0
fi
if [ -z "${PROXY_AUTH_USERNAME}" ]; then
echo "Missing PROXY_AUTH_USERNAME"
exit 0
fi
if [ -z "${PROXY_AUTH_PASSWORD}" ]; then
echo "Missing PROXY_AUTH_PASSWORD"
exit 0
fi
if [ -z "${PROXY_AUTH_TITLE}" ]; then
PROXY_AUTH_TITLE="Protected Service"
fi
htpasswd -b -c ${NGINX_PASSWORD_FILE} ${PROXY_AUTH_USERNAME} ${PROXY_AUTH_PASSWORD}
AUTH1="auth_basic \"${PROXY_AUTH_TITLE}\";"
AUTH2="auth_basic_user_file ${NGINX_PASSWORD_FILE};"
else
AUTH1="# auth disabled"
AUTH2=""
fi
cat > /etc/nginx/conf.d/default.conf <<EOL
server {
listen 80 default_server;
server_name localhost;
${AUTH1}
${AUTH2}
client_max_body_size ${NGINX_CLIENT_MAX_BODY_SIZE};
client_body_timeout ${NGINX_CLIENT_BODY_TIMEOUT};
resolver 127.0.0.1 valid=5s;
set \$dn "${SERVICE_HOST}";
location / {
proxy_pass http://\$dn:${SERVICE_PORT};
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Host \$host;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_redirect off;
}
}
EOL
fi
service dnsmasq restart && echo "Starting nginx..." && exec nginx -g "daemon off;"