简体   繁体   中英

node proxy error Error: connect ECONNREFUSED

I use reverse proxy from the following module 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 ECONNREFUSED what does it mean this error and what can be possible solution to it?

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

ECONNREFUSED means there is no server process listening at the specified port. What hostname and port are you using? Can you connect directly (without the proxy)?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM