-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnginx-routing.conf
95 lines (84 loc) · 3.08 KB
/
nginx-routing.conf
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
# This file handles strictly the routing, and caching
# settings of webstudio for such routings.
#
# This file should be loaded within a "server { ... }" config
# block. The server config block is assumed to be a deployment
# config, that devops will setup on the server.
#############################################################
#
# Nginx Server caching settings (aggressive)
#
#############################################################
# Aggressive file metadata caching
#
# Because this is designed for deploy once on
# a server startup, strictly speaking no metadata
# revalidation is actually needed.
open_file_cache max=10000 inactive=30m;
open_file_cache_valid 10m;
open_file_cache_min_uses 1;
open_file_cache_errors on;
# Set everything to utf=8 please
charset utf-8;
# File reading caching at os level if possible
sendfile on;
aio threads;
#############################################################
#
# Location based routing segment of webstudio
#
#############################################################
#
# Quick crash course on location routing
# See: https://nginx.org/en/docs/http/ngx_http_core_module.html#location
#
# It matches for the following
#
# 1) = (exact match wins) : location = /path
# 2) ^~ (forward match, longest match wins) : location ^~ /path
# 3) ~ (regular expression case sensitive, first match wins) : location ~ /path/
# 4) ~* (regular expression case insensitive, first match wins) : location ~* .(jpg|png|bmp)
# 5) / (prefix match, longest match wins) : location /path
#
# General rule of thumb is to favour forward/prefix match first before regex.
# Cause regex takes "more cpu". This should not however compromise config complexity
#
# PS : You can nest location blocks, its priority would be examined at each depth.
#
# PS : The following is a useful tool for testing nginx regex - http://nginx.viraptor.info/
# NOTE DO NOT PUT ANY SENSITIVE INFORMATION THERE, as it is not secure
#
# All other file routing (final fallback)
# Attempts to load the file, else fallbacks to 404
location / {
#
# short term caching of 1 minutes for all
# other assets that was not optimized
# for CDN is applied here
#
# Note that due to the multilayers of caching
# in actual usage, this can easily multiply
# to a 5 minute cache delay
#
location ~* \.(?:jpg|jpeg|gif|png|bmp|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
# 1 minute server caching, 5 minute browser caching
add_header Cache-Control "max-age=300";
add_header Cache-Control "s-maxage=60";
add_header Cache-Control "public";
# Actually load the file if given
try_files $uri =404;
}
#
# For all other files, it is assuming to be the page html
# loading. Micro-caching is applied instead to allow changes
# to update quickly, while gaining (limited) benefits from CDN
#
# See: https://www.nginx.com/blog/benefits-of-microcaching-nginx/
#
# 1 second server caching, 5 second browser caching
add_header Cache-Control "max-age=5";
add_header Cache-Control "s-maxage=1";
add_header Cache-Control "public";
# Actually load the file if given
try_files $uri $uri/index.html $uri.html =404;
}