nodejs http-proxy不通过URL

问题描述 投票:0回答:1

我正在使用http-proxy模块,并且尝试将请求发送到端口1234并获得其回复。但是在apache日志中,我可以看到该请求仅针对/。该文档说使用toProxy: true来传递URL,但是它不起作用。

https://github.com/http-party/node-http-proxy

  • toProxy:是/否,将绝对URL作为路径传递(用于代理到代理)

这里是代码:

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
node.js http-proxy node-http-proxy node-https
1个回答
0
投票

想通了。我必须包括协议。

return proxy.web(req, res, { target: { protocol: 'https:', host: 'localhost', port: 1234},
© www.soinside.com 2019 - 2024. All rights reserved.