我们公司有一个项目,现在使用nginx作为反向代理,用于服务静态内容和支持comet连接。我们使用长轮询连接来摆脱不断的刷新请求,让用户立即获得更新。
现在,我知道已经有很多代码是为Node.js编写的,但是有没有一个解决方案可以让Node.js像nginx那样充当反向代理来提供静态内容呢?或者,也许有一个框架可以使用Node.js快速开发这样一个层?
发布于 2010-07-30 09:50:57
node-http-proxy听起来就是您想要的
var sys = require('sys'),
http = require('http'),
httpProxy = require('http-proxy').httpProxy;
http.createServer(function (req, res){
var proxy = new httpProxy;
proxy.init(req, res);
proxy.proxyRequest('localhost', '9000', req, res);
}).listen(8000);
http.createServer(function (req, res){
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);</code></pre>发布于 2010-02-08 17:25:47
dogproxy也许能够帮助你,如果不是作为一个完整的解决方案,那么可能作为一个构建块。
但是,您可能希望重新考虑将nginx保留为提供静态内容--它是专门为此特定任务设计和调优的。使用node.js提供静态内容会增加很多开销--就像使用PHP提供静态文件一样。
https://stackoverflow.com/questions/2214289
复制相似问题