@abtnode/router-provider 1.16.34-beta-20241129-100152-679bd732 → 1.16.34-beta-20241205-145120-3a7aa096
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/nginx/includes/blacklist +0 -0
- package/lib/nginx/includes/params +0 -4
- package/lib/nginx/index.js +19 -7
- package/lib/nginx/util.js +12 -0
- package/package.json +6 -6
|
File without changes
|
package/lib/nginx/index.js
CHANGED
|
@@ -137,7 +137,7 @@ class NginxProvider extends BaseProvider {
|
|
|
137
137
|
return path.relative(this.configDir, dir);
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
getConfTemplate() {
|
|
140
|
+
getConfTemplate(proxyPolicy) {
|
|
141
141
|
return getMainTemplate({
|
|
142
142
|
logDir: this.getRelativeConfigDir(formatBackSlash(this.logDir)),
|
|
143
143
|
tmpDir: this.getRelativeConfigDir(formatBackSlash(this.tmpDir)),
|
|
@@ -145,6 +145,7 @@ class NginxProvider extends BaseProvider {
|
|
|
145
145
|
workerProcess: this.getWorkerProcess(),
|
|
146
146
|
nginxLoadModules: getNginxLoadModuleDirectives(REQUIRED_MODULES, this.readNginxConfigParams()).join(os.EOL),
|
|
147
147
|
capabilities: this.capabilities,
|
|
148
|
+
proxyPolicy,
|
|
148
149
|
});
|
|
149
150
|
}
|
|
150
151
|
|
|
@@ -156,6 +157,8 @@ class NginxProvider extends BaseProvider {
|
|
|
156
157
|
services = [],
|
|
157
158
|
nodeInfo = {},
|
|
158
159
|
requestLimit,
|
|
160
|
+
blockPolicy,
|
|
161
|
+
proxyPolicy,
|
|
159
162
|
cacheEnabled,
|
|
160
163
|
} = {}) {
|
|
161
164
|
if (!Array.isArray(routingTable)) {
|
|
@@ -170,7 +173,7 @@ class NginxProvider extends BaseProvider {
|
|
|
170
173
|
|
|
171
174
|
// eslint-disable-next-line consistent-return
|
|
172
175
|
return new Promise((resolve, reject) => {
|
|
173
|
-
const confTemplate = this.getConfTemplate();
|
|
176
|
+
const confTemplate = this.getConfTemplate(proxyPolicy);
|
|
174
177
|
|
|
175
178
|
NginxConfFile.createFromSource(confTemplate, (err, conf) => {
|
|
176
179
|
if (err) {
|
|
@@ -193,7 +196,10 @@ class NginxProvider extends BaseProvider {
|
|
|
193
196
|
this._addCommonResHeaders(conf.nginx.http, commonHeaders);
|
|
194
197
|
this._addExposeServices(conf, services);
|
|
195
198
|
if (requestLimit && requestLimit.enabled) {
|
|
196
|
-
this.
|
|
199
|
+
this.addRequestLimiting(conf.nginx.http, requestLimit);
|
|
200
|
+
}
|
|
201
|
+
if (blockPolicy && blockPolicy?.enabled) {
|
|
202
|
+
this.updateBlacklist(blockPolicy.blacklist);
|
|
197
203
|
}
|
|
198
204
|
|
|
199
205
|
const allRules = sites.reduce((acc, site) => {
|
|
@@ -661,6 +667,8 @@ class NginxProvider extends BaseProvider {
|
|
|
661
667
|
}
|
|
662
668
|
|
|
663
669
|
server._add('root', this.getRelativeConfigDir(this.wwwDir));
|
|
670
|
+
server._addVerbatimBlock('if ($access_blocked)', 'return 403;');
|
|
671
|
+
|
|
664
672
|
server._add('error_page', '404 =404 /_abtnode_404');
|
|
665
673
|
server._add('error_page', '502 =502 /_abtnode_502');
|
|
666
674
|
server._add('error_page', '500 502 503 504 =500 /_abtnode_5xx');
|
|
@@ -889,13 +897,17 @@ class NginxProvider extends BaseProvider {
|
|
|
889
897
|
});
|
|
890
898
|
}
|
|
891
899
|
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
block._add('
|
|
895
|
-
block._add('limit_req', `zone=ip_limit burst=${limit.maxInstantRate || 30} delay=10`);
|
|
900
|
+
addRequestLimiting(block, limit) {
|
|
901
|
+
block._add('limit_req_zone', `$binary_remote_addr zone=req_limit_per_ip:20m rate=${limit.rate || 5}r/s`);
|
|
902
|
+
block._add('limit_req', `zone=req_limit_per_ip burst=${limit.maxInstantRate || 30} delay=10`);
|
|
896
903
|
block._add('limit_req_status', 429);
|
|
897
904
|
}
|
|
898
905
|
|
|
906
|
+
updateBlacklist(blacklist) {
|
|
907
|
+
const blacklistFile = path.join(this.includesDir, 'blacklist');
|
|
908
|
+
fs.writeFileSync(blacklistFile, blacklist.map((x) => `${x} 1;`).join(os.EOL));
|
|
909
|
+
}
|
|
910
|
+
|
|
899
911
|
getLogFilesForToday() {
|
|
900
912
|
return {
|
|
901
913
|
access: this.accessLog,
|
package/lib/nginx/util.js
CHANGED
|
@@ -182,6 +182,7 @@ const getMainTemplate = ({
|
|
|
182
182
|
workerProcess,
|
|
183
183
|
maxBodySize = CLIENT_MAX_BODY_SIZE,
|
|
184
184
|
capabilities = {},
|
|
185
|
+
proxyPolicy = {},
|
|
185
186
|
}) =>
|
|
186
187
|
`${nginxLoadModules}
|
|
187
188
|
${getDynamicModulesDirective(capabilities)}
|
|
@@ -197,6 +198,17 @@ events {
|
|
|
197
198
|
}
|
|
198
199
|
|
|
199
200
|
http {
|
|
201
|
+
${
|
|
202
|
+
proxyPolicy?.enabled
|
|
203
|
+
? `${(proxyPolicy?.trustedProxies || ['0.0.0.0/0']).map((x) => `set_real_ip_from ${x};`).join(os.EOL)}
|
|
204
|
+
real_ip_header ${proxyPolicy?.realIpHeader || 'X-Forwarded-For'};
|
|
205
|
+
real_ip_recursive ${proxyPolicy?.trustRecursive ? 'on' : 'off'};`
|
|
206
|
+
: ''
|
|
207
|
+
}
|
|
208
|
+
geo $access_blocked {
|
|
209
|
+
default 0;
|
|
210
|
+
include includes/blacklist;
|
|
211
|
+
}
|
|
200
212
|
map $http_upgrade $connection_upgrade {
|
|
201
213
|
default upgrade;
|
|
202
214
|
'' "";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abtnode/router-provider",
|
|
3
|
-
"version": "1.16.34-beta-
|
|
3
|
+
"version": "1.16.34-beta-20241205-145120-3a7aa096",
|
|
4
4
|
"description": "Routing engine implementations for abt node",
|
|
5
5
|
"author": "polunzh <polunzh@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/ArcBlock/blocklet-server#readme",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"url": "https://github.com/ArcBlock/blocklet-server/issues"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@abtnode/constant": "1.16.34-beta-
|
|
36
|
-
"@abtnode/logger": "1.16.34-beta-
|
|
37
|
-
"@abtnode/router-templates": "1.16.34-beta-
|
|
38
|
-
"@abtnode/util": "1.16.34-beta-
|
|
35
|
+
"@abtnode/constant": "1.16.34-beta-20241205-145120-3a7aa096",
|
|
36
|
+
"@abtnode/logger": "1.16.34-beta-20241205-145120-3a7aa096",
|
|
37
|
+
"@abtnode/router-templates": "1.16.34-beta-20241205-145120-3a7aa096",
|
|
38
|
+
"@abtnode/util": "1.16.34-beta-20241205-145120-3a7aa096",
|
|
39
39
|
"@arcblock/http-proxy": "^1.19.1",
|
|
40
40
|
"@arcblock/is-valid-domain": "^1.0.5",
|
|
41
41
|
"axios": "^1.7.5",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"bluebird": "^3.7.2",
|
|
60
60
|
"fs-extra": "^11.2.0"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "1162a42e8d2c5ed0330a51724685b2d554c50160"
|
|
63
63
|
}
|