Nginx config

Install dependencies

We recommend you to use NodeJS 15+.
1
# Install nginx
2
sudo apt install -y nginx
Copied!

Sample nginx config

You can just create a new sites within nginx. In /etc/nginx/sites-available/dashboard:
1
server {
2
listen 443 ssl http2;
3
listen [::]:443 ssl http2;
4
server_name dashboard.speculare.cloud;
5
root /root/speculare-dashboard/dist_current;
6
7
# SSL
8
ssl_certificate /etc/letsencrypt/live/dashboard.speculare.cloud/fullchain.pem;
9
ssl_certificate_key /etc/letsencrypt/live/dashboard.speculare.cloud/privkey.pem;
10
ssl_trusted_certificate /etc/letsencrypt/live/dashboard.speculare.cloud/chain.pem;
11
12
# security headers
13
add_header X-Frame-Options "SAMEORIGIN" always;
14
add_header X-XSS-Protection "1; mode=block" always;
15
add_header X-Content-Type-Options "nosniff" always;
16
add_header Referrer-Policy "no-referrer-when-downgrade" always;
17
add_header Content-Security-Policy "connect-src wss://cdc.speculare.cloud https://server.speculare.cloud";
18
19
# . files
20
location ~ /\.(?!well-known) {
21
deny all;
22
}
23
24
# additional config
25
include nginxconfig.io/general.conf;
26
27
location ~* ^.+\.(ico|gif|jpg|jpeg|png)$ {
28
access_log off;
29
expires 30d;
30
}
31
32
location ~* ^.+\.(css|js|txt|xml|swf|wav)$ {
33
access_log off;
34
expires 24h;
35
}
36
37
location ~* ^.+\.(html|htm)$ {
38
expires 1h;
39
}
40
41
location ~* ^.+\.(eot|ttf|otf|woff|svg)$ {
42
access_log off;
43
expires max;
44
}
45
46
location / {
47
try_files $uri /index.html;
48
}
49
}
50
51
# HTTP redirect
52
server {
53
listen 80;
54
listen [::]:80;
55
server_name dashboard.speculare.cloud;
56
57
location / {
58
return 301 https://dashboard.speculare.cloud$request_uri;
59
}
60
}
Copied!
Don't forget to update the domains and SSL paths.
The above config rely on /etc/nginx/nginxconfig.io/general.conffor caching & robots instructions:
1
# favicon.ico
2
location = /favicon.ico {
3
log_not_found off;
4
access_log off;
5
}
6
7
# robots.txt
8
location = /robots.txt {
9
log_not_found off;
10
access_log off;
11
}
12
13
# assets, media
14
location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {
15
expires 7d;
16
access_log off;
17
}
18
19
# svg, fonts
20
location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff2?)$ {
21
add_header Access-Control-Allow-Origin "*";
22
expires 7d;
23
access_log off;
24
}
25
26
# gzip
27
gzip on;
28
gzip_vary on;
29
gzip_proxied any;
30
gzip_comp_level 6;
31
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
Copied!
Last modified 4mo ago
Copy link