forked from 61FINTECH/deploy-strapi-on-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnginx.conf
128 lines (105 loc) · 4.13 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
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
# The original template is generated by https://nginxconfig.io/?0.domain=yourdomain.com&0.path=%2Fhome%2Fubuntu%2Fstrapi-cms&0.document_root=%2Fhome%2Fubuntu%2Fstrapi-cms%2Fpublic&0.redirect=false&[email protected]&0.php=false&0.proxy&0.proxy_pass=http:%2F%2F127.0.0.1:1337&0.root=false&expires_assets=&expires_media=&expires_svg=&expires_fonts=&access_log=off%20%23%20use%20PM2%20logs&error_log=off%20%23%20use%20PM2%20logs&file_structure=unified
user www-data;
pid /run/nginx.pid;
worker_processes auto;
worker_rlimit_nofile 65535;
events {
multi_accept on;
worker_connections 65535;
}
http {
charset utf-8;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
types_hash_max_size 2048;
client_max_body_size 10M;
# MIME
include mime.types;
default_type application/octet-stream;
# disabled logging, use `PM2 logs` instead
access_log off;
error_log off;
# 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;
# SSL
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
# modern configuration
ssl_protocols TLSv1.2;
ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256;
ssl_prefer_server_ciphers on;
# OCSP Stapling
ssl_stapling on;
ssl_stapling_verify on;
resolver 1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4 208.67.222.222 208.67.220.220 valid=60s;
resolver_timeout 2s;
# load configs
include /etc/nginx/conf.d/*.conf;
#####################################################
## the above are stable, the below would be custom ##
#####################################################
map $host $strapi_cms {
cms.yourdomain.com 127.0.0.1:1339;
staging-cms.yourdomain.com 127.0.0.1:1338;
dev-cms.yourdomain.com 127.0.0.1:1337;
}
# single SSL certificate for multiple domains
ssl_certificate /etc/letsencrypt/live/cms.yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/cms.yourdomain.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/cms.yourdomain.com/fullchain.pem;
# https://github.com/strapi/strapi/issues/2424#issuecomment-445964719
map $http_x_forwarded_host $custom_forwarded_host {
default "$host";
strapi "strapi";
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name cms.yourdomain.com staging-cms.yourdomain.com dev-cms.yourdomain.com;
# reverse proxy
location / {
proxy_pass http://$strapi_cms$request_uri;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $custom_forwarded_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
}
# 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;
add_header Content-Security-Policy "default-src * data: 'unsafe-eval' 'unsafe-inline'" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
# . files
location ~ /\.(?!well-known) {
deny all;
}
}
# http => https
server {
listen 80;
listen [::]:80;
server_name cms.yourdomain.com staging-cms.yourdomain.com dev-cms.yourdomain.com;
# ACME-challenge
location ^~ /.well-known/acme-challenge/ {
root /var/www/_letsencrypt;
}
location / {
return 301 https://$server_name$request_uri;
}
}
}