我正在使用http-proxy模块,并且尝试将请求发送到端口1234并获得其回复。但是在apache日志中,我可以看到该请求仅针对/
。该文档说使用toProxy: true
来传递URL,但是它不起作用。
https://github.com/http-party/node-http-proxy
这里是代码:
var http = require('http');
var httpProxy = require('http-proxy');
var proxy = httpProxy.createProxyServer();
var fs = require('fs');
http.createServer(function(req, res) {
return proxy.web(req, res, { target: {host: 'localhost', port: 1234},
ssl: {
key: fs.readFileSync('/root/test.pem', 'utf8'),
cert: fs.readFileSync('/root/test_cert.pem', 'utf8')
},
toProxy: true
});
}).listen(3000);
我正在使用curl测试并检查正在端口1234上监听的apache日志。
curl -v http://localhost:3000/getsomething.html
想通了。我必须包括协议。
return proxy.web(req, res, { target: { protocol: 'https:', host: 'localhost', port: 1234},