forked from gatsbyjs/gatsby-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnginx-boot.sh
executable file
·132 lines (101 loc) · 3.11 KB
/
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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
# Check for variables
export CHARSET=${CHARSET:-utf-8}
export WORKER_CONNECTIONS=${WORKER_CONNECTIONS:-1024}
export HTTP_PORT=${HTTP_PORT:-80}
export NGINX_CONF=/etc/nginx/mushed.conf
export PUBLIC_PATH=${PUBLIC_PATH:-/pub}
export GZIP_TYPES=${GZIP_TYPES:-application/javascript application/x-javascript application/rss+xml text/javascript text/css image/svg+xml}
export GZIP_LEVEL=${GZIP_LEVEL:-6}
export CACHE_IGNORE=${CACHE_IGNORE:-html}
export CACHE_PUBLIC=${CACHE_PUBLIC:-ico|jpg|jpeg|png|gif|svg|js|jsx|css|less|swf|eot|ttf|otf|woff|woff2}
export CACHE_PUBLIC_EXPIRATION=${CACHE_PUBLIC_EXPIRATION:-1y}
if [ "$TRAILING_SLASH" = false ]; then
REWRITE_RULE="rewrite ^(.+)/+\$ \$1 permanent"
TRY_FILES="try_files \$uri \$uri/index.html =404"
else
REWRITE_RULE="rewrite ^([^.]*[^/])\$ \$1/ permanent"
TRY_FILES="try_files \$uri \$uri/ \$uri/index.html =404"
fi
if [ "$DISABLE_FILE_CACHE" != true ]; then
read -r -d '' FILE_CACHE <<'EOF'
## Cache open FD
open_file_cache max=10000 inactive=3600s;
open_file_cache_valid 7200s;
open_file_cache_min_uses 2;
EOF
fi
if [ -f /etc/nginx/server.conf ]; then
CUSTOM_SERVER_CONFIG=$(</etc/nginx/server.conf)
else
CUSTOM_SERVER_CONFIG=${CUSTOM_SERVER_CONFIG:-};
fi
if [ -f /etc/nginx/location_cache_ignore.conf ]; then
CUSTOM_LOCATION_CACHE_IGNORE=$(</etc/nginx/location_cache_ignore.conf)
else
CUSTOM_LOCATION_CACHE_IGNORE=${CUSTOM_LOCATION_CACHE_IGNORE:-};
fi
if [ -f /etc/nginx/location_cache_public.conf ]; then
CUSTOM_LOCATION_CACHE_PUBLIC=$(</etc/nginx/location_cache_public.conf)
else
CUSTOM_LOCATION_CACHE_PUBLIC=${CUSTOM_LOCATION_CACHE_PUBLIC:-};
fi
# Build config
cat <<EOF > $NGINX_CONF
daemon off;
worker_processes 1;
user root;
events {
worker_connections $WORKER_CONNECTIONS;
}
http {
include mime.types;
default_type application/octet-stream;
keepalive_timeout 15;
autoindex off;
server_tokens off;
port_in_redirect off;
absolute_redirect off;
sendfile off;
tcp_nopush on;
tcp_nodelay on;
client_max_body_size 64k;
client_header_buffer_size 16k;
large_client_header_buffers 4 16k;
$FILE_CACHE
## Gzipping is an easy way to reduce page weight
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_types $GZIP_TYPES;
gzip_buffers 16 8k;
gzip_comp_level $GZIP_LEVEL;
access_log /dev/stdout;
error_log /dev/stderr error;
server {
listen $HTTP_PORT;
root $PUBLIC_PATH;
index index.html;
autoindex off;
charset $CHARSET;
error_page 404 /404.html;
location ~* \.($CACHE_IGNORE)$ {
$CUSTOM_LOCATION_CACHE_IGNORE
add_header Cache-Control "no-store";
expires off;
}
location ~* \.($CACHE_PUBLIC)$ {
$CUSTOM_LOCATION_CACHE_PUBLIC
add_header Cache-Control "public";
expires +$CACHE_PUBLIC_EXPIRATION;
}
$REWRITE_RULE;
$TRY_FILES;
$CUSTOM_SERVER_CONFIG
}
}
EOF
[ "" != "$DEBUG" ] && cat $NGINX_CONF;
mkdir -p /run/nginx/
chown -R root:root /var/lib/nginx
exec nginx -c $NGINX_CONF