Sub-request using Parent Request Body

Adrian Janeczek loleslav.pl at gmail.com
Fri Jan 7 03:35:07 MSK 2011


spierdalaj chamie

2011/1/7 Roman Vasilyev <roman at anchorfree.com>

> On 01/05/2011 09:02 PM, agentzh wrote:
>
>> 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 '
>>
>>
> Thank you for quick response, and I afraid of my stupid questions about
> embedded lua but :) :
> 1) I'm using current development nginx-0.9.3 (my internals need huge table
> ~350k domain records for 2 different nginx parameters) and doable in current
> version.
> 2) when I'm just including  *rewrite_by_lua* with simple return, I'm
> loosing all headers from parent cite, please help me with best solution for
> that.
> 3) why you prefer NDK to clear nginx environment?
>
>              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
>>
>>
>
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://nginx.org/mailman/listinfo/nginx
>



-- 
Z wyrazami szacunku* Adrian Janeczek

*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20110107/e0862201/attachment.html>


More information about the nginx mailing list