Is there a solution that lets Node.js act as an HTTP reverse proxy?
Our com开发者_Python百科pany has a project that right now uses nginx as a reverse proxy for serving static content and supporting comet connections. We use long polling connections to get rid of constant refresh requests and let users get updates immediately.
Now, I know there is a lot of code already written for Node.js, but is there a solution that lets Node.js act as a reverse proxy for serving static content as nginx does? Or maybe there is a framework that allows to quickly develop such a layer using Node.js?
dogproxy might be able to help you, if not as a full solution then possibly as the building blocks for one.
However, you might wish to reconsider keeping nginx for serving static content -- it is specifically designed and tuned for this particular task. You would be adding a lot of overhead in using node.js to serve static content - much like using PHP to serve static files.
node-http-proxy sounds like what you want
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>
精彩评论