【问题标题】:nodejs http-proxy not passing URLnodejs http-proxy 没有通过 URL
【发布时间】:2020-04-20 09:56:06
【问题描述】:

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

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

  • toProxy:true/false,将绝对 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

【问题讨论】:

  • 向我们展示你的 apache 配置

标签: node.js http-proxy node-http-proxy node-https


【解决方案1】:

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

return proxy.web(req, res, { target: { protocol: 'https:', host: 'localhost', port: 1234},

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-06
    • 2014-11-09
    • 1970-01-01
    • 2018-12-03
    • 2015-02-19
    相关资源
    最近更新 更多