1
+ # Rate limiting zone for DDoS protection (limits to 50 req/s per IP)
2
+ limit_req_zone $binary_remote_addr zone=mylimit:10m rate=50r/s;
3
+
4
+ # Connection limiting zone for DDoS protection
5
+ limit_conn_zone $binary_remote_addr zone=conn_limit:150m;
6
+
7
+ # HTTP to HTTPS redirect
1
8
server {
2
9
listen 80;
3
10
server_name $HOSTNAME;
4
- return 301 https://${DOLLAR} server_name${DOLLAR} request_uri;
11
+ return 301 https://$server_name$request_uri;
5
12
}
6
13
14
+ # Main HTTPS server
7
15
server {
16
+ # SSL setup
8
17
listen 443 ssl;
9
18
ssl_certificate /etc/nginx/certs/$CERTIFICATE_NAME;
10
19
ssl_certificate_key /etc/nginx/certs/$CERTIFICATE_KEY;
11
20
ssl_ciphers EECDH+AESGCM:EDH+AESGCM;
12
21
ssl_ecdh_curve secp384r1;
13
- ssl_session_timeout 10m;
22
+ ssl_session_timeout 10m;
14
23
ssl_session_cache shared:SSL:10m;
15
24
server_name $HOSTNAME;
25
+
26
+ # DDoS protection
27
+ limit_req zone=mylimit burst=20 nodelay; # Limits HTTP floods
28
+ limit_conn conn_limit 50; # Caps connections per IP
29
+ limit_conn_log_level warn; # Logs exceeded limits
30
+ client_body_timeout 10s; # Drops slow body sends
31
+ client_header_timeout 10s; # Drops slow header sends
32
+ keepalive_timeout 5s; # Closes idle connections
33
+ send_timeout 10s; # Limits response time
34
+ client_max_body_size 2m; # Caps request size
35
+
36
+ # Security headers
16
37
add_header Strict-Transport-Security "max-age=86400; includeSubDomains" always;
17
38
add_header X-XSS-Protection "1; mode=block";
18
39
add_header X-Permitted-Cross-Domain-Policies "none";
19
40
add_header X-Frame-Options "deny";
20
41
add_header Access-Control-Allow-Origin "domain";
21
- add_header Access-Control-Allow-Origin https://${DOLLAR} server_name;
42
+ add_header Access-Control-Allow-Origin https://$server_name;
22
43
add_header X-Content-Type-Options "nosniff";
23
44
add_header Content-Security-Policy "script-src 'self'; base-uri 'self'; frame-ancestors 'deny'; form-action 'self'; default-src 'self'; object-src 'none'; worker-src 'self' blob:;";
24
45
add_header Cache-Control "no-store";
25
46
add_header Pragma "no-cache";
47
+
48
+ # Logging
26
49
error_log /var/log/nginx/tombolo-error.log;
27
50
access_log /var/log/nginx/tombolo-access.log;
51
+
52
+ # Static files
28
53
location / {
29
- proxy_set_header X-Real-IP ${DOLLAR}remote_addr;
30
- proxy_set_header X-Forwarded-For ${DOLLAR}proxy_add_x_forwarded_for;
31
- proxy_set_header Host ${DOLLAR}http_host;
54
+ limit_req zone=mylimit burst=20 nodelay; # Rate limit for this location
55
+ proxy_set_header X-Real-IP $remote_addr;
56
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
57
+ proxy_set_header Host $http_host;
32
58
proxy_hide_header X-Powered-By;
33
59
expires -1;
34
- # adding this on top of -1, as part of the requirements for different browsers
35
60
expires 01 Jan 1971 01:01:01 GMT;
36
-
37
- root /usr/share/nginx/html;
38
- index index.html index.htm;
39
- try_files ${DOLLAR}uri ${DOLLAR}uri/ /index.html;
61
+ root /usr/share/nginx/html;
62
+ index index.html index.htm;
63
+ try_files $uri $uri/ /index.html;
40
64
}
41
65
66
+ # API proxy
42
67
location /api {
68
+ limit_req zone=mylimit burst=50 nodelay; # Higher burst for API
43
69
proxy_pass http://node:3000;
44
70
proxy_set_header X-Frame-Options "deny";
45
71
proxy_hide_header X-Powered-By;
46
72
}
47
73
48
- # Location block for SSE at /api/addClusterWithProgress
74
+ # SSE for clustering progress
49
75
location /api/cluster/addClusterWithProgress {
50
- proxy_pass http://node:3000; # Pass to your Node.js server
51
- proxy_set_header Connection keep-alive;
52
- proxy_buffering off; # Disable buffering to support SSE
53
- proxy_cache off; # Disable caching
54
- chunked_transfer_encoding off; # Disable chunked transfer encoding
55
- add_header Cache-Control no-cache; # Ensure no caching is done on client side
76
+ proxy_pass http://node:3000;
77
+ proxy_set_header Connection keep-alive;
78
+ proxy_buffering off;
79
+ proxy_cache off;
80
+ chunked_transfer_encoding off;
81
+ add_header Cache-Control no-cache;
56
82
}
57
83
58
-
59
- location /socket.io {
84
+ # WebSocket for Socket.IO
85
+ location /socket.io {
60
86
proxy_pass http://node:3000;
61
87
proxy_http_version 1.1;
62
- proxy_set_header Upgrade ${DOLLAR} http_upgrade;
88
+ proxy_set_header Upgrade $http_upgrade;
63
89
proxy_set_header Connection 'upgrade';
64
- proxy_set_header Host ${DOLLAR} host;
65
- proxy_cache_bypass ${DOLLAR} http_upgrade;
66
- }
90
+ proxy_set_header Host $host;
91
+ proxy_cache_bypass $http_upgrade;
92
+ }
67
93
94
+ # Error pages
68
95
error_page 500 502 503 504 /50x.html;
69
- location = /50x.html {
70
- root /usr/share/nginx/html;
96
+ location = /50x.html {
97
+ root /usr/share/nginx/html;
71
98
}
72
99
}
0 commit comments