forked from MorbZ/docker-web-redirect
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·38 lines (30 loc) · 845 Bytes
/
start.sh
File metadata and controls
executable file
·38 lines (30 loc) · 845 Bytes
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
#!/bin/bash
set -eu
echo "Validating required environment variables"
: ${REDIRECT_TARGET:?"You need to set the REDIRECT_TARGET environment variable."}
# Set defaults
REDIRECT_CODE="${REDIRECT_CODE:=301}"
IGNORE_REQUEST_URI="${IGNORE_REQUEST_URI:=false}"
# Set variables
NGINX_CONFIG_FILE="/etc/nginx/conf.d/default.conf"
# Add http if not set
if ! [[ ${REDIRECT_TARGET} =~ ^https?:// ]]; then
REDIRECT_TARGET="http://${REDIRECT_TARGET}"
fi
echo "Redirecting to ${REDIRECT_TARGET} with status code ${REDIRECT_CODE}"
if [[ ${IGNORE_REQUEST_URI} = "true" ]]; then
cat <<- EOF > ${NGINX_CONFIG_FILE}
server {
listen 8080;
return ${REDIRECT_CODE} ${REDIRECT_TARGET};
}
EOF
else
cat <<- EOF > ${NGINX_CONFIG_FILE}
server {
listen 8080;
return ${REDIRECT_CODE} ${REDIRECT_TARGET}\$request_uri;
}
EOF
fi
exec nginx -g "daemon off;"