hi mark,
we used this setup in an authentication proxy, nginx + tornado as upstream. all non-public requests went to tornado first, this one did an ``x-accel-redirect`` response with information put in the responseheaders. nginx took the responsecode to distiguish between authorized and unauthorized. additional headers where used to apply information about a user to the real backend service.
two things to note:
- in our case this tornado was a simple http upstream pool, no uwsgi as in your case. i think that should be managable with a uwsgi location somehow too.
- we had no need to pass any responsebody to the second request. and the more i think about it, it makes no sense to have a body passed on a redirect in general. so sorry for the confusion, if this hint was wrong (still i didn't try yet).
you can do something more advanced - not to say crazy ;) - and use the nginx lua module. with that i'm sure it works. i built some request splitter for a friend which works well. looks somehow like that (you could do ``two sequences ``capture`` instead of the ``capture_multi``)::
location /multi {
default_type 'text/html';
# echo does not work at all if ``content_by_lua`` is used
# echo "start lua";
content_by_lua '
local res_one, res_two = ngx.location.capture_multi {
{ "/one" },
{ "/two" }
}
if res_one.status == 200
and res_two.status == 200 then
-- ``ngx.header`` must be set before print
ngx.header["X-Status"] = "Lua"
ngx.print(res_one.body.." ... "..res_two.body)
-- ngx.exit(ngx.OK)
-- return ngx.redirect("/cache");
return
end
-- this one does not work: ``ngx.exit(ngx.ERROR)`
-- whereas setting the status does...
ngx.status = ngx.HTTP_INTERNAL_SERVER_ERROR
ngx.print("error "..ngx.time())
';
}
location /one {
default_type 'text/plain';
echo "one";
}
location /two {
default_type 'text/plain';
echo "two";
}
here is also the relevant part from the buildout, i remember this was a bit bitchy to get it working. atm under lion it failed to compile, but its a start::
[lua]
recipe = hexagonit.recipe.cmmi
strip-top-level-dir=true
configure-command = /usr/bin/true
make-options = INSTALL_TOP=${buildout:directory}/parts/lua ${os:make_opt}
[lua_jit]
recipe = hexagonit.recipe.cmmi
strip-top-level-dir=true
configure-command = /usr/bin/true
make-options = PREFIX=${lua:location}
[nginx_lua_module]
recipe = hexagonit.recipe.download
strip-top-level-dir=true
[nginx]
recipe = hexagonit.recipe.cmmi
strip-top-level-dir=true
configure-options = --with-debug
--add-module=${upstream_fair:destination}
--add-module=${headers_more_module:destination}
--add-module=${echo_module:destination}
--add-module=${eval_module:destination}
--add-module=${nginx_devel_kit:destination}
--add-module=${nginx_lua_module:destination}
--with-cc-opt="-D NGX_HAVE_CASELESS_FILESYSTEM=0"
--with-http_ssl_module
--with-http_stub_status_module
--http-proxy-temp-path=${buildout:directory}/var/nginx/cache/client_body_temp
cache_size = 64
dep-lua_jit = ${lua_jit:location}
dep-lua-nginx = ${nginx_lua_module:url}
environment =
LUA_LIB=${lua:location}/lib
LUA_INC=${lua:location}/include/luajit-2.0
cheers, andi