我有两个在端口3000
和4000
. 我想有以下行为:
https://localhost/dev ==> http://localhost:3000
https://localhost/prod ==> http:// localhost:4000
我有以下代理:
var fs = require('fs'),
httpProxy = require('http-proxy');
var PATH_TO_KEY = "/home/wow/browser.key",
PATH_TO_CERT = "/home/wow/browser.crt",
PATH_TO_CHAIN = "";
var options = {
ssl: {
key: fs.readFileSync(PATH_TO_KEY, 'utf8'),
cert: fs.readFileSync(PATH_TO_CERT, 'utf8'),
//ca : fs.readFileSync(PATH_TO_CHAIN, 'utf8')
},
target: "http://localhost:4000", // this is prod
ws: true,
xfwd: true,
router: {
'https://localhost/dev': 'http://127.0.0.1:3000/',
'https://localhost/prod': 'http://127.0.0.1:4000/',
},
pathRewrite: {
'^/dev' : '/', // remove /dev/ path
'^/prod' : '/' // remove /prod/ path
},
};
var server = httpProxy.createProxyServer(options).listen(443);
但是,当我访问https://localhost/dev
或https://localhost/prod
时,会发生以下情况:
- 它总是重定向到
target
指定的,而不是router
. - pathRewrite 似乎没有发生,因为 I 总是以
target/prod
or结尾target/dev
。/dev 和 /prod 的路径不存在,因此出现页面无法显示错误。
我不确定我哪里出了问题。有人可以帮忙吗?
谢谢。