-
Notifications
You must be signed in to change notification settings - Fork 15
/
nginx-boot.sh
executable file
·40 lines (32 loc) · 947 Bytes
/
nginx-boot.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
#!/bin/bash
# Check for variables
export WORKER_CONNECTIONS=${WORKER_CONNECTIONS:-1024}
export HTTP_PORT=${HTTP_PORT:-80}
export REDIRECT=${REDIRECT:-https\:\/\/\$host}
export REDIRECT_TYPE=${REDIRECT_TYPE:-permanent}
export NGINX_CONF=/etc/nginx/mushed.conf
export HSTS=${HSTS:-0}
export HSTS_MAX_AGE=${HSTS_MAX_AGE:-31536000}
export HSTS_INCLUDE_SUBDOMAINS=${HSTS_INCLUDE_SUBDOMAINS:-0}
# Build config
cat <<EOF > $NGINX_CONF
user root;
daemon off;
events {
worker_connections $WORKER_CONNECTIONS;
}
http {
server {
listen $HTTP_PORT;
server_tokens off;
$([ "${HSTS}" != "0" ] && echo "
add_header Strict-Transport-Security \"max-age=${HSTS_MAX_AGE};$([ "${HSTS_INCLUDE_SUBDOMAINS}" != "0" ] && echo "includeSubDomains")\";
")
rewrite ^(.*) $REDIRECT\$1 $REDIRECT_TYPE;
}
}
EOF
cat $NGINX_CONF;
chown -R root:root /var/lib/nginx;
mkdir -p /run/nginx;
exec nginx -c $NGINX_CONF