我的目标是在端口 80 上运行 Node.js。这是因为我发现某些网络阻止了 Node.js,这些网络不允许来自任何其他端口的流量。
看来,最好的方法是通过 Node.js 代理 Apache。我尝试过使用节点 http 代理做到这一点,但我没有任何运气。
我正在使用的代码在这里:
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 通过 node.js 代理 Apache?这能让我在端口 80 上运行 node.js 吗? node-http-proxy 是实现这一目标的最佳方法吗?
谢谢。
在高端口 8080 或其他端口上运行您的应用程序
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
如果您没有使用 nginx 或 apache
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)