Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ECONNREFUSEDwhat 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

like image 905
07_05_GuyT Avatar asked Oct 06 '15 20:10

07_05_GuyT


1 Answers

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)?

P.S. 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
});
like image 156
keithmo Avatar answered Oct 12 '22 23:10

keithmo