forked from frappe/press
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx.conf
396 lines (310 loc) · 9.67 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
upstream frappe-bench-frappe {
server 127.0.0.1:8000 fail_timeout=0;
}
upstream frappe-bench-socketio-server {
server 127.0.0.1:9000 fail_timeout=0;
}
server {
listen 80 default_server;
server_name "";
return 444;
}
server {
listen 443 ssl http2 default_server;
server_name "";
ssl on;
ssl_certificate /etc/letsencrypt/live/frappe.cloud/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/frappe.cloud/privkey.pem; # managed by Certbot
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers EECDH+AESGCM:EDH+AESGCM;
ssl_ecdh_curve secp384r1;
ssl_prefer_server_ciphers on;
return 444;
}
# setup maps
map $host $site_name_sxjfjnv {
frappecloud.com frappe.cloud;
default $host;
}
# server blocks
server {
listen 443 ssl http2;
server_name
frappe.cloud
;
root /home/frappe/frappe-bench/sites;
ssl on;
ssl_certificate /etc/letsencrypt/live/frappe.cloud/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/frappe.cloud/privkey.pem; # managed by Certbot
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers EECDH+AESGCM:EDH+AESGCM;
ssl_ecdh_curve secp384r1;
ssl_prefer_server_ciphers on;
add_header X-Frame-Options "SAMEORIGIN";
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
return 301 https://frappecloud.com$request_uri;
}
# http to https redirect
server {
listen 80;
server_name
frappe.cloud
;
return 301 https://$host$request_uri;
}
proxy_cache_path /var/cache/nginx/jscache levels=1:2 keys_zone=jscache:100m inactive=30d use_temp_path=off max_size=100m;
proxy_cache_path /var/cache/nginx/assets keys_zone=assets_cache:10m loader_threshold=300 loader_files=200 max_size=200m;
server {
listen 443 ssl http2;
server_name
frappecloud.com
;
root /home/frappe/frappe-bench/sites;
ssl on;
ssl_certificate /etc/letsencrypt/live/frappecloud.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/frappecloud.com/privkey.pem; # managed by Certbot
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers EECDH+AESGCM:EDH+AESGCM;
ssl_ecdh_curve secp384r1;
ssl_prefer_server_ciphers on;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
add_header X-Frame-Options "SAMEORIGIN";
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
location /status {
auth_basic "NGINX VTS";
auth_basic_user_file /home/frappe/frappe-bench/monitoring.htpasswd;
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
location /metrics {
auth_basic "Prometheus";
auth_basic_user_file /home/frappe/frappe-bench/monitoring.htpasswd;
location /metrics/node {
proxy_pass http://127.0.0.1:9100/metrics;
}
location /metrics/docker {
proxy_pass http://127.0.0.1:9323/metrics;
}
location /metrics/cadvisor {
proxy_pass http://127.0.0.1:9338/metrics;
}
location /metrics/nginx {
vhost_traffic_status_display;
vhost_traffic_status_display_format prometheus;
}
location /metrics/mariadb {
proxy_pass http://127.0.0.1:9104/metrics;
}
location /metrics/gunicorn {
proxy_pass http://127.0.0.1:9102/metrics;
}
}
location /assets {
proxy_cache assets_cache;
proxy_cache_key $scheme$host$request_uri;
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
proxy_cache_bypass $http_secret_cache_purge;
add_header X-Cache-Status $upstream_cache_status;
add_header Cache-Control "max-age=31536000";
try_files $uri =404;
}
location ~ ^/protected/(.*) {
internal;
try_files /$site_name_sxjfjnv/$1 =404;
}
location = /js/script.js {
proxy_pass https://analytics.frappe.cloud/js/plausible.js;
proxy_buffering on;
proxy_cache jscache;
proxy_cache_valid 200 6h;
proxy_cache_use_stale updating error timeout invalid_header http_500;
proxy_set_header Host analytics.frappe.cloud;
proxy_ssl_name analytics.frappe.cloud;
proxy_ssl_server_name on;
proxy_ssl_session_reuse off;
proxy_ssl_protocols TLSv1.3;
proxy_hide_header Cache-Control;
proxy_ignore_headers Cache-Control;
add_header Cache-Control "max-age=31536000";
add_header X-Cache-Status $upstream_cache_status;
}
location = /api/event {
proxy_pass https://analytics.frappe.cloud/api/event;
proxy_buffering on;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $REMOTE_ADDR;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header Host analytics.frappe.cloud;
proxy_ssl_name analytics.frappe.cloud;
proxy_ssl_server_name on;
proxy_ssl_session_reuse off;
proxy_ssl_protocols TLSv1.3;
add_header Cache-Control "max-age=31536000";
}
location /socket.io {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Frappe-Site-Name $site_name_sxjfjnv;
proxy_set_header Origin $scheme://$http_host;
proxy_set_header Host $host;
proxy_pass http://frappe-bench-socketio-server;
}
location = /website_script.js {
proxy_cache assets_cache;
proxy_cache_key $scheme$host$request_uri;
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
proxy_cache_bypass $http_secret_cache_purge;
proxy_set_header X-Forwarded-For $REMOTE_ADDR;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Frappe-Site-Name $site_name_sxjfjnv;
proxy_set_header Host $host;
proxy_read_timeout 120;
proxy_redirect off;
proxy_hide_header Set-Cookie;
proxy_ignore_headers Set-Cookie;
proxy_set_header Cookie "";
add_header Cache-Control "max-age=31536000";
proxy_pass http://frappe-bench-frappe;
}
location ~ ^/saas/billing.* {
proxy_cache assets_cache;
proxy_cache_key $scheme$host$request_uri;
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
proxy_ignore_headers "Set-Cookie";
proxy_hide_header "Set-Cookie";
proxy_set_header Cookie "";
add_header Content-Security-Policy "frame-ancestors 'self' https://*.erpnext.com https://*.frappe.cloud;";
add_header X-Cache-Status $upstream_cache_status;
proxy_set_header X-Forwarded-For $REMOTE_ADDR;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Frappe-Site-Name $site_name_sxjfjnv;
proxy_set_header Host $host;
proxy_set_header X-Use-X-Accel-Redirect True;
proxy_read_timeout 120;
proxy_redirect off;
proxy_pass http://frappe-bench-frappe;
http2_push_preload on;
}
location ~ ^/dashboard/checkout* {
proxy_cache assets_cache;
proxy_cache_key $scheme$host$request_uri;
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
proxy_ignore_headers "Set-Cookie";
proxy_hide_header "Set-Cookie";
proxy_set_header Cookie "";
add_header Content-Security-Policy "frame-ancestors 'self' https://*.erpnext.com https://*.frappe.cloud;";
add_header X-Cache-Status $upstream_cache_status;
proxy_set_header X-Forwarded-For $REMOTE_ADDR;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Frappe-Site-Name $site_name_sxjfjnv;
proxy_set_header Host $host;
proxy_set_header X-Use-X-Accel-Redirect True;
proxy_read_timeout 120;
proxy_redirect off;
proxy_pass http://frappe-bench-frappe;
http2_push_preload on;
}
location / {
rewrite ^(.+)/$ $1 permanent;
rewrite ^(.+)/index\.html$ $1 permanent;
rewrite ^(.+)\.html$ $1 permanent;
location ~ ^/files/.*.(png|jpeg|jpg|gif|css|js) {
add_header Cache-Control "max-age=31536000";
try_files /$site_name_sxjfjnv/public/$uri @webserver;
}
location ~* ^/files/.*.(htm|html|svg|xml) {
add_header Cache-Control "max-age=31536000";
add_header Content-disposition "attachment";
try_files /$site_name_sxjfjnv/public/$uri @webserver;
}
try_files /$site_name_sxjfjnv/public/$uri @webserver;
}
location @webserver {
proxy_set_header X-Forwarded-For $REMOTE_ADDR;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Frappe-Site-Name $site_name_sxjfjnv;
proxy_set_header Host $host;
proxy_set_header X-Use-X-Accel-Redirect True;
proxy_read_timeout 120;
proxy_redirect off;
proxy_pass http://frappe-bench-frappe;
http2_push_preload on;
}
# error pages
error_page 502 /502.html;
location /502.html {
root /home/frappe/.bench/bench/config/templates;
internal;
}
# optimizations
sendfile on;
keepalive_timeout 15;
client_max_body_size 50m;
client_body_buffer_size 16K;
client_header_buffer_size 1k;
# enable gzip compresion
# based on https://mattstauffer.co/blog/enabling-gzip-on-nginx-servers-including-laravel-forge
gzip on;
gzip_http_version 1.1;
gzip_comp_level 5;
gzip_min_length 256;
gzip_proxied any;
gzip_vary on;
gzip_types
application/atom+xml
application/javascript
application/json
application/rss+xml
application/vnd.ms-fontobject
application/x-font-ttf
application/font-woff
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/svg+xml
image/x-icon
text/css
text/plain
text/x-component
;
# text/html is always compressed by HttpGzipModule
}
# http to https redirect
server {
if ($host = frappecloud.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name
frappecloud.com
;
return 301 https://$host$request_uri;
}