/
nginx.conf
95 lines (79 loc) · 2.06 KB
/
nginx.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
user nginx;
worker_processes auto;
pid /var/run/nginx.pid;
events {
multi_accept on;
worker_connections 1024;
}
http {
charset utf-8;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
log_not_found off;
types_hash_max_size 2048;
client_max_body_size 20M;
# MIME
include /etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 80;
listen [::]:80;
root /usr/share/nginx/html;
index index.html;
location ~ (index.html|service-worker.js)$ {
expires -1;
}
# Single-Page-App fallback routing
location / {
# First attempt to serve request as file, then
# as directory, then fall back to redirecting to index.html
try_files $uri $uri/ /index.html;
}
# Media: images, icons, video, audio, HTC
location /static {
expires 7d;
access_log off;
add_header Cache-Control "public";
}
# Flags don't change often
location /static/flags {
expires 365d;
access_log off;
add_header Cache-Control "public";
}
# CSS and JS bundles
location /bundles {
try_files $uri =404;
add_header Cache-Control "public, max-age=31536000, immutable";
access_log off;
}
# favicon.ico
location = /favicon.ico {
rewrite . /static/favicon.ico;
expires 14d;
add_header Cache-Control public;
}
# robots.txt
location = /robots.txt {
log_not_found off;
access_log off;
}
# Any route containing a file extension
location ~ ^.+\..+$ {
try_files $uri =404;
}
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
# Gzip
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/xml+rss application/atom+xml image/svg+xml;
}
}