nginx配置:
location / {
content_by_lua_file '$APP_PATH/dispatch.lua';
}
location ^~ /proxy1 {
proxy_pass http://10.10.159.249:8282$request_uri;
}
location ^~ /proxy2 {
proxy_pass http://10.10.159.247:8282$request_uri;
}
dispatch.lua内有:
local res = ngx.location.capture(loc, { method = method, always_forward_body = true, copy_all_vars = true }) -- loc是动态取得的/proxy1或者/proxy2
if res.status ~= ngx.HTTP_OK then
content = '{"error": "proxy error", "error_code": 2}'
ngx.header['Connection'] = 'close'
ngx.header['Content-Length'] = #content
ngx.header['Pragma'] = 'no-cache'
ngx.print(content)
ngx.flush(true)
ngx.exit(ngx.HTTP_SERVICE_UNAVAILABLE)
end
for k, v in pairs(res.header) do
ngx.header[k] = v
end
ngx.print(res.body)
问题:
这种处理,ngx.location.capture如果是get一个大文件时必须等所有都收齐了才能ngx.print出去,怎样才能一边收一边回传??