【发布时间】:2018-10-03 12:59:18
【问题描述】:
我正在尝试为多个节点应用程序编写反向代理。什么时候做这样的事情:
app.use('/', proxy('http://localhost:5010/'));
app.listen(8000, (err) => {
if (err) {
return console.error('Application failed to start:', err);
}
console.log('Application listening on port', 8000);
});
它按预期工作。但是当我做类似的事情时
app.use('/', proxy('http://localhost:5010/'));
app.use('/config', proxy('http://localhost:5020/config'));
app.listen(8000, (err) => {
if (err) {
return console.error('Application failed to start:', err);
}
console.log('Application listening on port', 8000);
});
我对 http://localhost:8000/config 的请求被路由到 localhost:5010
如果我只做/config 的代理,它将正确路由。它是关于我何时做多个代理的。
我为此使用 express 和 express-http-proxy。
关于如何做到这一点的任何想法?
【问题讨论】:
标签: node.js express proxy reverse-proxy