forked from gatsbyjs/gatsby-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx-boot.sh
executable file
·106 lines (80 loc) · 2.4 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
#!/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"
else
REWRITE_RULE="rewrite ^([^.]*[^/])\$ \$1/ permanent"
fi
if [ -f /etc/nginx/server.conf ]; then
CUSTOM_SERVER_CONFIG=$(</etc/nginx/server.conf)
else
CUSTOM_SERVER_CONFIG=${CUSTOM_SERVER_CONFIG:-};
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;
sendfile off;
tcp_nopush on;
tcp_nodelay on;
client_max_body_size 64k;
client_header_buffer_size 16k;
large_client_header_buffers 4 16k;
## Cache open FD
open_file_cache max=10000 inactive=3600s;
open_file_cache_valid 7200s;
open_file_cache_min_uses 2;
## 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;
server {
listen $HTTP_PORT;
root $PUBLIC_PATH;
index index.html;
autoindex off;
charset $CHARSET;
error_page 404 /404.html;
location ~* \.($CACHE_IGNORE)$ {
add_header Cache-Control "no-store";
expires off;
}
location ~* \.($CACHE_PUBLIC)$ {
add_header Cache-Control "public";
expires +$CACHE_PUBLIC_EXPIRATION;
}
$REWRITE_RULE;
try_files \$uri \$uri/ \$uri/index.html =404;
$CUSTOM_SERVER_CONFIG
}
}
EOF
[ "" != "$DEBUG" ] && cat $NGINX_CONF;
mkdir -p /run/nginx/
chown -R root:root /var/lib/nginx
exec nginx -c $NGINX_CONF