javascript 节点代理错误错误:连接ECONNREFUSED

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32979418/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 15:58:35  来源:igfitidea点击:

node proxy error Error: connect ECONNREFUSED

javascriptnode.jsproxynode-http-proxy

提问by 07_05_GuyT

I use reverse proxy from the following module https://github.com/nodejitsu/node-http-proxy

我使用以下模块中的反向代理 https://github.com/nodejitsu/node-http-proxy

and I got in err for the following code

我犯了以下代码的错误

proxy.on('error', function (err, req, res) {
    res.end('Error occurr'+ err);
});

connect ECONNREFUSEDwhat does it mean this error and what can be possible solution to it?

connect ECONNREFUSED这个错误是什么意思,有什么可能的解决方案?

I use the

我用

proxy = httpProxy.createProxyServer({});

    proxy.web(req, res, {
        target: 'http://' + hostname + ':' + port
    });

    proxy.on('error', function (err, req, res) {
        res.end('Error occurr'+ err);
    });

and I need just to proxy calls to new port

我只需要代理对新端口的调用

回答by keithmo

ECONNREFUSEDmeans there is no server process listening at the specified port. What hostnameand portare you using? Can you connect directly (without the proxy)?

ECONNREFUSED表示没有服务器进程在指定端口侦听。什么hostnameport您使用的?您可以直接连接(没有代理)吗?

P.S. Unrelated to ECONNREFUSED, but you should also set changeOrigin in the options passed to proxy.web:

PS 与 ECONNREFUSED 无关,但您还应该在传递给 proxy.web 的选项中设置 changeOrigin:

proxy.web(req, res, {
    target: 'http://' + hostname + ':' + port,
    changeOrigin: true
});