-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnginx-site.conf
More file actions
91 lines (83 loc) · 3.05 KB
/
nginx-site.conf
File metadata and controls
91 lines (83 loc) · 3.05 KB
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
# Microcache for expensive matplotlib endpoints (30s)
proxy_cache_path /var/cache/nginx/dip levels=1:2 keys_zone=dip_cache:10m
max_size=200m inactive=5m use_temp_path=off;
upstream gunicorn {
server 127.0.0.1:8000;
keepalive 16;
}
server {
listen 80;
server_name dip.dmj.one _;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 104.16.0.0/13;
set_real_ip_from 104.24.0.0/14;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 131.0.72.0/22;
real_ip_header CF-Connecting-IP;
client_max_body_size 10M;
# Static files — served directly by Nginx, bypass Gunicorn
location /static/ {
alias /opt/dip-practical/app/static/;
expires 7d;
add_header Cache-Control "public, immutable";
gzip_static on;
}
# Matplotlib demo and reference — cache 60s (same output for everyone)
location ~ ^/api/(matplotlib-demos|matplotlib-reference)$ {
proxy_pass http://gunicorn;
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-Proto $scheme;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_read_timeout 120s;
proxy_buffering on;
proxy_cache dip_cache;
proxy_cache_valid 200 60s;
proxy_cache_use_stale error timeout updating;
proxy_cache_lock on;
add_header X-Cache-Status $upstream_cache_status;
}
# Image list — cache 5 min (static dataset)
location = /api/images {
proxy_pass http://gunicorn;
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-Proto $scheme;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_read_timeout 120s;
proxy_buffering on;
proxy_cache dip_cache;
proxy_cache_valid 200 300s;
proxy_cache_use_stale error timeout updating;
proxy_cache_lock on;
add_header X-Cache-Status $upstream_cache_status;
}
# All other API endpoints — buffered but not cached (user-specific params)
location / {
proxy_pass http://gunicorn;
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-Proto $scheme;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_read_timeout 120s;
proxy_buffering on;
proxy_buffer_size 16k;
proxy_buffers 8 32k;
}
}