使用本教程构建了一个负载均衡器 - Building Your Own Load Balancer with ExpressJS
const express = require('express');
const fs = require('fs');
const https = require('https');
const request = require('request');
const servers = ['server2', 'server1','server2'];
let cur = 0;
const profilerMiddleware = (req, res, next) => {
const start = Date.now();
// The 'finish' event comes from core Node.js, it means Node is done handing
// off the response headers and body to the underlying OS.
res.on('finish', () => {
console.log('Completed', req.method, req.url, Date.now() - start);
});
next();
};
const handler = (req, res) => {
// Add an error handler for the proxied request
const _req = request({ url: servers[cur] + req.url }).on('error', error => {
res.status(500).send(error.message);
});
req.pipe(_req).pipe(res);
cur = (cur + 1) % servers.length;
};
const server = express().get('*', handler).post('*', handler);
server.listen(8080);
const app = express().
// Use `express-sslify` to make sure _all_ requests use HTTPS
use(require('express-sslify').HTTPS()).
use(profilerMiddleware).
get('*', handler).
post('*', handler);
app.listen(80);

执行后,我可以从本地服务器访问https。也与服务器建立了连接,但内容未加载。 每个服务器在默认端口上都有一个角度前端,在各自的IP上有一个3000端口上的节点后端。 问题是所有这些都是http服务器,我想通过我的localhost加载它们作为https并且页面不加载。 我为bundle.js vendor.js等文件收到404错误。 任何人都可以帮我解决这个问题吗?