-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnginx.conf
100 lines (84 loc) · 3.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
96
97
98
99
100
server {
listen 80;
server_name localhost;
# Enhanced 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 "strict-origin-when-cross-origin" always;
# Root directory for static files
root /usr/share/nginx/html;
index index.html;
# Static file serving with optimized caching
location / {
try_files $uri $uri/ /index.html;
# Disable caching for HTML to always check for updates
location ~* \.html$ {
expires -1;
add_header Cache-Control "no-store, no-cache, must-revalidate";
}
# Cache bust other static assets with query strings or file hashes
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
# Optimize static file serving
tcp_nodelay on;
tcp_nopush on;
sendfile on;
# Gzip compression for static files
gzip on;
gzip_types text/plain text/css application/javascript application/json image/svg+xml;
gzip_min_length 1000;
}
# WebSocket proxy with optimized settings
location /ws {
proxy_pass http://app:3001;
proxy_http_version 1.1;
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-Proto $scheme;
# WebSocket timeouts
proxy_read_timeout 300s;
proxy_connect_timeout 75s;
proxy_send_timeout 300s;
# WebSocket specific optimizations
proxy_buffering off;
proxy_cache off;
}
# Drawing endpoint proxy with optimized settings
location /drawing.bmp {
proxy_pass http://app:3001;
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;
# Since this is real-time generated content
proxy_buffering off;
proxy_cache off;
expires -1;
add_header Cache-Control "no-store, no-cache, must-revalidate";
}
# Health check endpoint proxy
location /health {
proxy_pass http://app:3001;
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;
# Optimize for health checks
proxy_buffering off;
proxy_cache off;
expires -1;
add_header Cache-Control "no-store, no-cache, must-revalidate";
}
# Deny access to . files
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
}