【发布时间】:2011-08-31 19:59:22
【问题描述】:
我的目标是在端口 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 通过 node.js 代理 Apache?这将使我能够在端口 80 上运行 node.js 吗? node-http-proxy 是实现这一目标的最佳方式吗?
谢谢。
【问题讨论】:
标签: apache proxy node.js websocket