我创建了一个小代理节点脚本,它查找request.url 并将请求传递给我的apache服务器或使用节点 进程/响应此请求。我已经成功到目前为止, 一切工作正常,但是当我启用mod_deflate为Apache, “奇怪的事情会发生”。Nodejs代理脚本,与mod_deflate无关
它看起来像节点只是“取消”或“停止”早期的响应方式。 我正在监听来自我请求的“数据”事件,并且在某个点 节点刚刚决定响应已结束(这是错误的),并且 触发了“结束”事件。
代码片段:
var apache = http.createClient(82, 'localhost');
function pass_to_apache(req, res){
var request = apache.request(req.method, req.url, req.headers);
req.addListener('end', function() {
request.end();
});
req.addListener('data', function(chunk) {
request.write(chunk);
sys.puts('writting chunk\n');
});
request.addListener('response', function(response) {
res.writeHead(response.statusCode, response.headers);
response.addListener('data', function(chunk) {
sys.puts('writting data..\n');
res.write(chunk);
});
response.addListener('end', function() {
sys.puts('end of request');
res.end();
});
});
}
var MainServer = http.createServer(function(request, response) {
sys.puts('received '+request.method+' '+request.url + "\n"+JSON.stringify(request.headers));
if(/^\/node/.test(request.url)) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end("Hi, it's node =)\n");
}
else if(/^\/exit/.test(request.url)) {
sys.puts('closing..\n');
MainServer.close();
throw new Error('forced');
}
else {
pass_to_apache(request, response);
}
});
MainServer.listen(80, 'typeofnan.com');
可以通过 “看” 这个动作在www.typeofnan.com & & www.typeofnan.com/node/anything
编辑:禁用对的NodeJS现在。
请记住,如果没有gzip/deflate被apache使用,这就像一个魅力。我尝试在我的响应中将编码设置为“二进制”,但也没有成功。
我在这里错过了什么吗?阿莫尼能证实这种行为吗? 我正在使用最新版本(0.2.0)。
是否有另一种(更好的)解决方案使用这样的代理脚本?
当我在我的服务器上禁用'mod_deflate',它工作正常与代理脚本。在其他方式(禁用mod_deflate或使用accept-headers),这不是我想要的。我想要从apache执行gzip,并且我希望节点能够通过它(这仍然不起作用)。目前,我禁用了nodejs,它是100%的apache。我在帖子中已经描述过“奇怪的事情”。节点只是停止发送数据,或早或晚。在中间传输一个JS/CSS/HTML /无论文件,只是停止。 – jAndy 2010-09-13 12:32:56
Gotcha。只是为了澄清我的意思是你可以让节点做gzip并让apache在没有它的情况下做出回应。 – bxjx 2010-09-13 13:32:08
因此,加载特定文件时会崩溃吗? http://www.typeofnan.com/cgi-bin/supply.pl?js=[%22jquery-1.4.2.min.js%22,%22jquery-ui-1.8.4.custom.min的响应。 js%22,%22init.min.js%22,%22box.min.js%22,%22app.min.js%22]似乎不太正确。看起来不像cgi配置正确。也许删除supply.files(..)调用,看看节点是否更喜欢事物。 – bxjx 2010-09-13 13:38:11