@abtnode/router-provider 1.7.9 → 1.7.10

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.
@@ -15,3 +15,5 @@ proxy_set_header Upgrade $http_upgrade;
15
15
  proxy_set_header Connection $connection_upgrade;
16
16
 
17
17
  proxy_read_timeout 3600;
18
+
19
+ proxy_pass_header server;
@@ -126,7 +126,7 @@ class NginxProvider extends BaseProvider {
126
126
  this.initialize();
127
127
  }
128
128
 
129
- async update({ routingTable = [], certificates = [], globalHeaders, services = [], nodeInfo = {} } = {}) {
129
+ async update({ routingTable = [], certificates = [], commonHeaders, services = [], nodeInfo = {} } = {}) {
130
130
  if (!Array.isArray(routingTable)) {
131
131
  throw new Error('routingTable must be an array');
132
132
  }
@@ -163,7 +163,7 @@ class NginxProvider extends BaseProvider {
163
163
 
164
164
  this._addCorsMap(conf, siteCorsConfigs);
165
165
  conf.nginx.http._add('server_tokens', 'off');
166
- this._addGlobalHeaders(conf, globalHeaders);
166
+ this._addCommonResHeaders(conf.nginx.http, commonHeaders);
167
167
  this._addExposeServices(conf, services);
168
168
 
169
169
  logger.info('routing sites:', sites);
@@ -191,6 +191,7 @@ class NginxProvider extends BaseProvider {
191
191
  serverName: parsedServerName,
192
192
  corsAllowedOrigins,
193
193
  daemonPort: nodeInfo.port,
194
+ commonHeaders,
194
195
  });
195
196
  } else {
196
197
  this._addHttpServer({
@@ -200,6 +201,7 @@ class NginxProvider extends BaseProvider {
200
201
  corsAllowedOrigins,
201
202
  port,
202
203
  daemonPort: nodeInfo.port,
204
+ commonHeaders,
203
205
  });
204
206
  }
205
207
  }
@@ -380,6 +382,7 @@ class NginxProvider extends BaseProvider {
380
382
  target,
381
383
  ruleId,
382
384
  type,
385
+ commonHeaders,
383
386
  }) {
384
387
  server._add('location', concatPath(prefix, suffix));
385
388
 
@@ -402,6 +405,7 @@ class NginxProvider extends BaseProvider {
402
405
  location._add('include', 'includes/security');
403
406
  }
404
407
 
408
+ this._addCommonResHeaders(location, commonHeaders);
405
409
  this._addTailSlashRedirection(location, prefix); // Note: 末尾 "/" 的重定向要放在 CORS(OPTIONS) 响应之后, 这样不会影响 OPTIONS 的响应
406
410
 
407
411
  if (did) {
@@ -618,13 +622,13 @@ class NginxProvider extends BaseProvider {
618
622
  }
619
623
  }
620
624
 
621
- _addGlobalHeaders(conf, headers) {
625
+ _addCommonResHeaders(block, headers) {
622
626
  if (!headers || Object.prototype.toString.call(headers) !== '[object Object]') {
623
627
  return;
624
628
  }
625
629
 
626
630
  Object.keys(headers).forEach((key) => {
627
- conf.nginx.http._add('add_header', `${key} ${headers[key]}`);
631
+ block._add('add_header', `${key} ${headers[key]}`);
628
632
  });
629
633
  }
630
634
 
@@ -656,14 +660,14 @@ class NginxProvider extends BaseProvider {
656
660
  : conf.nginx.stream.server;
657
661
  }
658
662
 
659
- _addHttpServer({ locations = [], serverName, conf, corsAllowedOrigins, port, daemonPort }) {
663
+ _addHttpServer({ locations = [], serverName, conf, corsAllowedOrigins, port, daemonPort, commonHeaders }) {
660
664
  const httpServerUnit = this._addHttpServerUnit({ conf, serverName, port });
661
665
  this._addDefaultLocations(httpServerUnit, daemonPort);
662
666
  // eslint-disable-next-line max-len
663
- locations.forEach((x) => this._addReverseProxy({ server: httpServerUnit, ...x, serverName, corsAllowedOrigins })); // prettier-ignore
667
+ locations.forEach((x) => this._addReverseProxy({ server: httpServerUnit, ...x, serverName, corsAllowedOrigins, commonHeaders })); // prettier-ignore
664
668
  }
665
669
 
666
- _addHttpsServer({ conf, locations, certificateFileName, serverName, corsAllowedOrigins, daemonPort }) {
670
+ _addHttpsServer({ conf, locations, certificateFileName, serverName, corsAllowedOrigins, daemonPort, commonHeaders }) {
667
671
  const httpsServerUnit = this._addHttpsServerUnit({ conf, serverName, certificateFileName });
668
672
 
669
673
  const httpServerUnit = this._addHttpServerUnit({ conf, serverName });
@@ -671,7 +675,7 @@ class NginxProvider extends BaseProvider {
671
675
 
672
676
  this._addDefaultLocations(httpsServerUnit, daemonPort);
673
677
  // eslint-disable-next-line max-len
674
- locations.forEach((x) => this._addReverseProxy({ server: httpsServerUnit, ...x, serverName, corsAllowedOrigins })); // prettier-ignore
678
+ locations.forEach((x) => this._addReverseProxy({ server: httpsServerUnit, ...x, serverName, corsAllowedOrigins,commonHeaders })); // prettier-ignore
675
679
  }
676
680
 
677
681
  _addHttpServerUnit({ conf, serverName, port }) {
package/lib/nginx/util.js CHANGED
@@ -12,7 +12,7 @@ const { MAX_UPLOAD_FILE_SIZE } = require('@abtnode/constant');
12
12
 
13
13
  const logger = require('@abtnode/logger')('router:nginx:util');
14
14
 
15
- const WORKER_CONNECTIONS = 1000 * 10; // 10K
15
+ const MAX_WORKER_CONNECTIONS = 10240;
16
16
  const CLIENT_MAX_BODY_SIZE = process.env.MAX_UPLOAD_FILE_SIZE || MAX_UPLOAD_FILE_SIZE;
17
17
 
18
18
  const formatError = (errStr) => {
@@ -130,6 +130,17 @@ const getUserGroup = (username) => {
130
130
  return res.stdout.trim();
131
131
  };
132
132
 
133
+ const getWorkerConnectionCount = (maxWorkerConnections, workerProcess) => {
134
+ const { stdout, code } = shelljs.exec('ulimit -n', { silent: true });
135
+ if (code !== 0) {
136
+ return maxWorkerConnections;
137
+ }
138
+
139
+ const ulimit = Number(stdout.trim());
140
+
141
+ return Math.min(maxWorkerConnections, Math.floor(ulimit / workerProcess));
142
+ };
143
+
133
144
  const getMainTemplate = ({
134
145
  logDir,
135
146
  tmpDir,
@@ -145,7 +156,7 @@ user ${os.userInfo().username} ${getUserGroup(os.userInfo().username)};
145
156
  pid nginx.pid;
146
157
 
147
158
  events {
148
- worker_connections ${WORKER_CONNECTIONS};
159
+ worker_connections ${getWorkerConnectionCount(MAX_WORKER_CONNECTIONS, workerProcess)};
149
160
  }
150
161
 
151
162
  http {
@@ -270,4 +281,5 @@ module.exports = {
270
281
  getNginxStatus,
271
282
  rotateNginxLogFile,
272
283
  getUserGroup,
284
+ getWorkerConnectionCount,
273
285
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abtnode/router-provider",
3
- "version": "1.7.9",
3
+ "version": "1.7.10",
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.7.9",
36
- "@abtnode/logger": "1.7.9",
37
- "@abtnode/router-templates": "1.7.9",
38
- "@abtnode/util": "1.7.9",
35
+ "@abtnode/constant": "1.7.10",
36
+ "@abtnode/logger": "1.7.10",
37
+ "@abtnode/router-templates": "1.7.10",
38
+ "@abtnode/util": "1.7.10",
39
39
  "axios": "^0.26.1",
40
40
  "debug": "^4.3.3",
41
41
  "find-process": "^1.4.3",
@@ -62,5 +62,5 @@
62
62
  "fs-extra": "^10.0.1",
63
63
  "needle": "^3.0.0"
64
64
  },
65
- "gitHead": "285f4fedd41fcb8e1814ce5d8250ac10616e67e0"
65
+ "gitHead": "8eab10fd39b6183a2fa4d2706f52e8b2ecaa059a"
66
66
  }