我的目标是在80端口上运行Node.js。这是因为我发现某些网络会阻止Node.js从任何其他端口发送流量。
看起来最好的方法是通过Node.js代理Apache。我已经尝试使用node-http-proxy来实现,但是没有成功。
我正在使用的代码在此处:
var util = require('util'),
http = require('http'),
httpProxy = require('http-proxy');
httpProxy.createServer(9000, 'localhost').listen(80);
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);
但我一直收到“地址正在使用”的错误,端口为80。我一定做错了什么。
我如何通过node-http-proxy代理Apache来运行node.js?这样会使我能够在端口80上运行node.js吗?node-http-proxy是实现此目的的最佳方式吗?
谢谢。