-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstart.sh
38 lines (32 loc) · 1.34 KB
/
start.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
#!/bin/sh
# Check if ${URL} was set.
if [ ! "${URL}" ] ; then
echo "ERROR: You need to set the url to mirror using the \"\$URL\" variable!"
exit 1
fi
# Keys can be available by a persistent data in /data or through a mount.
if [ ! -f /data/server.key ] || [ ! -f /data/server.crt ] ; then
# If keys are not available, generate them.
echo "WARNING: Generating SSL Key and Certificate, because none were found."
openssl req -x509 -newkey rsa:4096 -keyout /data/server.key -out /data/server.crt -days 365 -subj "/CN=${DOMAIN:-localhost}" -nodes
fi
# The persisted, mounted or generated keys should be made available in the default directory.
echo "INFO: Linking SSL Key and Certificate to the runtime location."
ln -s /data/server.key "${DIRECTORY}"/conf/server.key
ln -s /data/server.crt "${DIRECTORY}"/conf/server.crt
# Write a configfile.
echo "INFO: Writing the custom Apache HTTPD configuration."
echo "ServerName ${DOMAIN:-localhost}" >> "${DIRECTORY}"/conf/httpd.conf && \
cat << EOF >> "${CONFIGFILE}"
ProxyHTMLURLMap ${URL} /
<Location "/">
ProxyPass ${URL}
# Rewrite "Location" in the header to prevent redirects.
ProxyPassReverse ${URL}
# Uncompress, rewrite HTML and compress when done.
SetOutputFilter INFLATE;proxy-html;DEFLATE
</Location>
EOF
# Start the httpd daemon.
echo "INFO: Staring Apache HTTPD daemon."
exec httpd-foreground