-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserve.sh
executable file
·66 lines (54 loc) · 1.25 KB
/
serve.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
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
domain=$1
root=$2
ssl_dir='/etc/letsencrypt/live'
auth=''
fallback=''
while [ $# -gt 0 ]; do
case "$1" in
-a|--auth)
auth="
AuthType Basic
AuthName 'Authentication required'
AuthUserFile /etc/apache2/.htpasswd
Require valid-user"
;;
-h|--help)
echo "
Generate a static webserver configuration file
Usage: serve.sh <domain> <documentRoot>
Flags:
-a, --auth: Add basic authentication
--fallback: Add a global fallback for single page applications using HTML5 history mode routing"
exit 0
;;
--fallback)
index='/index.html'
if [ ! -z $2 ]; then
index="$2"
fi
fallback="
FallbackResource $index
"
esac
shift
done
template="<VirtualHost *:80>
ServerName $domain
Redirect permanent / https://$domain
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName $domain
DocumentRoot $root
$fallback
<Directory $root>
Require all granted$auth
</Directory>
<IfModule mod_http2.c>
Protocols h2 http/1.1
</IfModule>
SSLCertificateFile $ssl_dir/$domain/fullchain.pem
SSLCertificateKeyFile $ssl_dir/$domain/privkey.pem
</VirtualHost>
</IfModule>"
echo "$template"