Sub-request using Parent Request Body
agentzh
agentzh at gmail.com
Thu Jan 6 08:02:48 MSK 2011
On Wed, Jan 5, 2011 at 8:20 AM, Roman Vasilyev <roman at anchorfree.com> wrote:
>
> Let me show one variant of nginx.conf's:
> location / {
> include proxy.conf;
> eval_subrequest_in_memory off;
> eval_override_content_type text/plain;
> eval $res {
> include spam_fastcgi.conf;
> if ( $request_method = POST) {
> fastcgi_pass unix:/var/run/nginx/cgiwrap-dispatch.sock;
> }
> }
> if ( $res = SPAM) {
> rewrite ^ /terms-of-use.html redirect;
> }
> }
Please try the following:
location = /check-spam {
internal;
include spam_fastcgi.conf;
fastcgi_pass unix:/var/run/nginx/cgiwrap-dispatch.sock;
}
location / {
client_max_body_size 100k;
client_body_buffer_size 100k;
lua_need_request_body on;
rewrite_by_lua '
if ngx.var.request_method ~= "POST" then
return
end
local res = ngx.location.capture(
"/check-spam",
{ method = "POST", body = ngx.var.request_body }
)
if res.body == "SPAM" then
return ngx.redirect("/terms-of-use.html")
end
';
# ... your normal fastcgi_pass/proxy_pass/etc settings
# go here ...
}
Please note that you need the git HEAD of the "master" branch of the
ngx_lua git repos:
https://github.com/chaoslawful/lua-nginx-module
> I have some foreign spam analyzer which I'm running like fastcgi server
> written in perl.
> I tried to use $request_body as fastsgi_param arg, it was empty;
> Wrote module which creates $post_body var in rewrite stage and with echo
> $post_body it works, but on subrequest it gives empty body (I guess because
> it not passing POST into subrequest)
> maybe somebody have any ideas how to realize it other way, or may be how to
> get POST in subrequest?
>
If you have further issues, feel free to report here ;)
Happy nginx.conf hacking!
-agentzh
More information about the nginx
mailing list