Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 1ff8a62

Browse files
authored
Merge branch 'main' into simplify-dnslink-nginx-logic
2 parents 8381dfd + 872550d commit 1ff8a62

File tree

5 files changed

+22
-27
lines changed

5 files changed

+22
-27
lines changed

nginx.conf

+10-13
Original file line numberDiff line numberDiff line change
@@ -110,27 +110,24 @@ http {
110110
ngx.header["Skynet-Server-Api"] = ngx.var.scheme .. "://" .. ngx.var.skynet_server_domain
111111
}
112112

113-
# ratelimit specified IPs
113+
# do not rate limit local traffic (ie. health checks)
114114
geo $limit {
115-
default 0;
116-
include /etc/nginx/conf.d/include/ratelimited;
115+
default 1;
116+
127.0.0.0/8 0; # host network
117+
10.0.0.0/8 0; # private network
118+
172.16.0.0/12 0; # private network
119+
192.168.0.0/16 0; # private network
117120
}
118121

119122
map $limit $limit_key {
120123
0 "";
121124
1 $binary_remote_addr;
122125
}
123126

124-
limit_req_zone $binary_remote_addr zone=uploads_by_ip:10m rate=10r/s;
125-
limit_req_zone $limit_key zone=uploads_by_ip_throttled:10m rate=10r/m;
126-
127-
limit_req_zone $binary_remote_addr zone=registry_access_by_ip:10m rate=60r/m;
128-
limit_req_zone $limit_key zone=registry_access_by_ip_throttled:10m rate=20r/m;
129-
130-
limit_conn_zone $binary_remote_addr zone=upload_conn:10m;
131-
limit_conn_zone $limit_key zone=upload_conn_rl:10m;
132-
133-
limit_conn_zone $binary_remote_addr zone=downloads_by_ip:10m;
127+
limit_req_zone $limit_key zone=uploads_by_ip:10m rate=10r/s;
128+
limit_req_zone $limit_key zone=registry_access_by_ip:10m rate=60r/m;
129+
limit_conn_zone $limit_key zone=upload_conn_limit:10m;
130+
limit_conn_zone $limit_key zone=download_conn_limit:10m;
134131

135132
limit_req_status 429;
136133
limit_conn_status 429;

nginx/conf.d/gzip.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ gzip_min_length 256;
1515
gzip_proxied expired no-cache no-store private auth;
1616

1717
# enables the types of files that can be compressed
18-
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;
18+
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;

nginx/conf.d/include/location-skylink

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include /etc/nginx/conf.d/include/cors;
22

3-
limit_conn downloads_by_ip 100; # ddos protection: max 100 downloads at a time
3+
limit_conn download_conn_limit 100; # ddos protection: max 100 downloads at a time
44

55
# ensure that skylink that we pass around is base64 encoded (transform base32 encoded ones)
66
# this is important because we want only one format in cache keys and logs

nginx/conf.d/include/location-skynet-registry

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ include /etc/nginx/conf.d/include/cors;
22
include /etc/nginx/conf.d/include/sia-auth;
33

44
limit_req zone=registry_access_by_ip burst=600 nodelay;
5-
limit_req zone=registry_access_by_ip_throttled burst=200 nodelay;
65

76
proxy_set_header User-Agent: Sia-Agent;
87
proxy_read_timeout 600; # siad should timeout with 404 after 5 minutes

nginx/conf.d/server/server.api

+10-11
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,7 @@ location /skynet/skyfile {
211211
include /etc/nginx/conf.d/include/portal-access-check;
212212

213213
limit_req zone=uploads_by_ip burst=10 nodelay;
214-
limit_req zone=uploads_by_ip_throttled;
215-
216-
limit_conn upload_conn 5;
217-
limit_conn upload_conn_rl 1;
214+
limit_conn upload_conn_limit 5;
218215

219216
client_max_body_size 5000M; # make sure to limit the size of upload to a sane value
220217

@@ -262,10 +259,8 @@ location /skynet/tus {
262259
include /etc/nginx/conf.d/include/cors-headers; # include cors headers but do not overwrite OPTIONS response
263260

264261
limit_req zone=uploads_by_ip burst=10 nodelay;
265-
limit_req zone=uploads_by_ip_throttled;
266262

267-
limit_conn upload_conn 5;
268-
limit_conn upload_conn_rl 1;
263+
limit_conn upload_conn_limit 5;
269264

270265
# Do not limit body size in nginx, skyd will reject early on too large upload
271266
client_max_body_size 0;
@@ -362,10 +357,8 @@ location /skynet/pin {
362357
include /etc/nginx/conf.d/include/portal-access-check;
363358

364359
limit_req zone=uploads_by_ip burst=10 nodelay;
365-
limit_req zone=uploads_by_ip_throttled;
366360

367-
limit_conn upload_conn 5;
368-
limit_conn upload_conn_rl 1;
361+
limit_conn upload_conn_limit 5;
369362

370363
proxy_set_header User-Agent: Sia-Agent;
371364
proxy_pass http://sia:9980$uri?siapath=$dir1/$dir2/$dir3&$args;
@@ -443,7 +436,13 @@ location ~ "^/file/(([a-zA-Z0-9-_]{46}|[a-z0-9]{55})(/.*)?)$" {
443436
location /skynet/trustless/basesector {
444437
include /etc/nginx/conf.d/include/cors;
445438

446-
limit_conn downloads_by_ip 100; # ddos protection: max 100 downloads at a time
439+
# enable gzip for all content types but keep it on default level for minimal cpu strain
440+
# because this endpoint does not set content type based on the actual content so we cannot
441+
# limit it only to text files so files like videos and images will still be processed
442+
gzip_types *;
443+
gzip_comp_level 1;
444+
445+
limit_conn download_conn_limit 100; # ddos protection: max 100 downloads at a time
447446

448447
# default download rate to unlimited
449448
set $limit_rate 0;

0 commit comments

Comments
 (0)